MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / ParseDateTime

Function ParseDateTime

internal/filter/datetime.go:9–34  ·  view source on GitHub ↗
(value string)

Source from the content-addressed store, hash-verified

7)
8
9func ParseDateTime(value string) (time.Time, error) {
10 formats := []string{
11 time.RFC3339Nano, // 2006-01-02T15:04:05.999999999Z07:00
12 time.RFC3339, // 2006-01-02T15:04:05Z07:00
13 "2006-01-02T15:04:05.999999999", // Nanoseconds without timezone
14 "2006-01-02T15:04:05.999999", // Microseconds without timezone
15 "2006-01-02T15:04:05.999", // Milliseconds without timezone
16 "2006-01-02T15:04:05", // Seconds without timezone
17 "2006-01-02T15:04", // Minutes without timezone
18 "2006-01-02 15:04:05.999999999", // Nanoseconds with space
19 "2006-01-02 15:04:05.999999", // Microseconds with space
20 "2006-01-02 15:04:05.999", // Milliseconds with space
21 "2006-01-02 15:04:05", // Seconds with space
22 "2006-01-02 15:04", // Minutes with space
23 "2006-01-02", // Date only
24 "2006/01/02", // Date only, slash separated
25 }
26
27 for _, format := range formats {
28 if t, err := time.Parse(format, value); err == nil {
29 return t, nil
30 }
31 }
32
33 return time.Time{}, fmt.Errorf("unable to parse date: %s", value)
34}
35
36func getDatePrecisionFromString(dateStr string) string {
37 if strings.Contains(dateStr, ".") {

Callers 1

parseValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected