/
format.go
45 lines (32 loc) · 1.38 KB
/
format.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
package timestamp
import "time"
// Key is a default key and format of event timestamp
const Key = "_timestamp"
// Layout is an ISO date time format. Note: for parsing use time.RFC3339Nano.
const Layout = "2006-01-02T15:04:05.000000Z"
// Layout is an ISO date time format. Note: for parsing use time.RFC3339Nano.
const JsonISO = "2006-01-02T15:04:05.000Z"
// DayLayout is a Day format of time.Time
const DayLayout = "20060102"
// MonthLayout is a Month format of time.Time
const MonthLayout = "200601"
// DashDayLayout is a Day format with dash delimiter of time.Time
const DashDayLayout = "2006-01-02"
// LogsLayout is a date time representation for log records prefixes
const LogsLayout = "2006-01-02 15:04:05"
// GolangLayout is a default golang layout that is returned on String() without formatting
const GolangLayout = "2006-01-02T15:04:05-0700"
// DBLayout is a time layout that usually comes from Airbyte database sources
const DBLayout = "2006-01-02T15:04:05.999999999"
// NowUTC returns ISO string representation of current UTC time
func NowUTC() string {
return Now().UTC().Format(Layout)
}
// ToISOFormat returns ISO string representation of input time.Time
func ToISOFormat(t time.Time) string {
return t.Format(Layout)
}
// ParseISOFormat returns time.Time from ISO time string representation
func ParseISOFormat(t string) (time.Time, error) {
return time.Parse(time.RFC3339Nano, t)
}