-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.go
123 lines (109 loc) · 2.67 KB
/
default.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package atimeago
import (
"fmt"
"time"
)
const (
defaultParse = time.RFC1123Z
defaultPrint = time.RFC1123Z
defaultInstantMsg = "Just now"
// past
defaultSecondsPastMsg = "%v second%s ago"
defaultMinutesPastMsg = "%v minute%s ago"
defaultHoursPastMsg = "%v hour%s ago"
defaultDaysPastMsg = "%v day%s ago"
// future
defaultDayFutureMsg = "Tomorrow"
defaultSecondsFutureMsg = "In %d second%s"
defaultMinutesFutureMsg = "In %d minute%s"
defaultHoursFutureMsg = "In %d hour%s"
defaultDaysFutureMsg = "In %d day%s"
)
// NewDefault returns the standard Formatter.
func newDefault(opts ...Option) Formatter {
return NewFormatter(
newDefaultPast(),
newDefaultFuture(),
truncatingCategorizer,
defaultParse,
opts...,
)
}
func newDefaultPast() *Translator {
formatTime := timePrinter(defaultPrint)
return &Translator{
defaultSecondsPast,
defaultMinutesPast,
defaultHoursPast,
defaultDaysPast,
formatTime,
formatTime,
formatTime,
}
}
func newDefaultFuture() *Translator {
formatTime := timePrinter(defaultPrint)
return &Translator{
defaultSecondsFuture,
defaultMinutesFuture,
defaultHoursFuture,
defaultDaysFuture,
formatTime,
formatTime,
formatTime,
}
}
func defaultSecondsPast(c int, _ time.Time) string {
switch c {
case 0:
return fmt.Sprint(defaultInstantMsg)
case 1:
return fmt.Sprintf(defaultSecondsPastMsg, "A", "")
}
return fmt.Sprintf(defaultSecondsPastMsg, c, "s")
}
func defaultMinutesPast(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultMinutesPastMsg, "A", "")
}
return fmt.Sprintf(defaultMinutesPastMsg, c, "s")
}
func defaultHoursPast(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultHoursPastMsg, "An", "")
}
return fmt.Sprintf(defaultHoursPastMsg, c, "s")
}
func defaultDaysPast(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultDaysPastMsg, "A", "")
}
return fmt.Sprintf(defaultDaysPastMsg, c, "s")
}
func defaultSecondsFuture(c int, _ time.Time) string {
switch c {
case 0:
return fmt.Sprint(defaultInstantMsg)
case 1:
return fmt.Sprintf(defaultSecondsFutureMsg, c, "")
}
return fmt.Sprintf(defaultSecondsFutureMsg, c, "s")
}
func defaultMinutesFuture(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultMinutesFutureMsg, c, "")
}
return fmt.Sprintf(defaultMinutesFutureMsg, c, "s")
}
func defaultHoursFuture(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultHoursFutureMsg, c, "")
}
return fmt.Sprintf(defaultHoursFutureMsg, c, "s")
}
func defaultDaysFuture(c int, _ time.Time) string {
if c == 1 {
return fmt.Sprintf(defaultDaysFutureMsg, c, "")
}
return fmt.Sprintf(defaultDaysFutureMsg, c, "s")
}