parseISOTimestamp parses an ISO 8601 timestamp string into a time.Time object. Returns the parsed time or an error if parsing fails. Example formats supported: "2023-01-15T14:30:00Z", "2023-01-15"
(timestamp string)
| 2806 | // Returns the parsed time or an error if parsing fails. |
| 2807 | // Example formats supported: "2023-01-15T14:30:00Z", "2023-01-15" |
| 2808 | func parseISOTimestamp(timestamp string) (time.Time, error) { |
| 2809 | if timestamp == "" { |
| 2810 | return time.Time{}, fmt.Errorf("empty timestamp") |
| 2811 | } |
| 2812 | |
| 2813 | // Try RFC3339 format (standard ISO 8601 with time) |
| 2814 | t, err := time.Parse(time.RFC3339, timestamp) |
| 2815 | if err == nil { |
| 2816 | return t, nil |
| 2817 | } |
| 2818 | |
| 2819 | // Try simple date format (YYYY-MM-DD) |
| 2820 | t, err = time.Parse("2006-01-02", timestamp) |
| 2821 | if err == nil { |
| 2822 | return t, nil |
| 2823 | } |
| 2824 | |
| 2825 | // Return error with supported formats |
| 2826 | return time.Time{}, fmt.Errorf("invalid ISO 8601 timestamp: %s (supported formats: YYYY-MM-DDThh:mm:ssZ or YYYY-MM-DD)", timestamp) |
| 2827 | } |
no outgoing calls