| 7 | ) |
| 8 | |
| 9 | func 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 | |
| 36 | func getDatePrecisionFromString(dateStr string) string { |
| 37 | if strings.Contains(dateStr, ".") { |