-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
49 lines (41 loc) · 850 Bytes
/
utils.go
File metadata and controls
49 lines (41 loc) · 850 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"log"
"strconv"
"strings"
"time"
)
const (
TimeFmt = "2006-01-02"
)
func mustParseFloat32(s string) float32 {
v, err := strconv.ParseFloat(s, 32)
if err != nil {
log.Fatalf("error parsing float %q: %v", s, err)
}
return float32(v)
}
func mustParseTime(s string) time.Time {
t, err := time.Parse(TimeFmt, s)
if err != nil {
log.Fatalf("error parsing time %q: %v", s, err)
}
return t
}
func formatTime(t time.Time) string {
return t.Format(TimeFmt)
}
func formatCurrency(v float32) string {
return fmt.Sprintf("%.02f €", v)
}
func removeLeadingSpaces(s string) string {
parts := strings.Split(s, "\n")
for i, part := range parts {
parts[i] = strings.TrimSpace(part)
}
return strings.Join(parts, "\n")
}
func linesWithBR(s string) string {
return strings.Replace(s, "\n", "<br>\n", -1)
}