MCPcopy Create free account
hub / github.com/github/gh-aw / parseAbsoluteDateTime

Function parseAbsoluteDateTime

pkg/workflow/time_delta.go:196–296  ·  view source on GitHub ↗

parseAbsoluteDateTime parses various date-time formats and returns a standardized timestamp

(dateTimeStr string)

Source from the content-addressed store, hash-verified

194
195// parseAbsoluteDateTime parses various date-time formats and returns a standardized timestamp
196func parseAbsoluteDateTime(dateTimeStr string) (string, error) {
197 timeDeltaLog.Printf("Parsing absolute date-time: %s", dateTimeStr)
198
199 // Try multiple date-time formats in order of preference
200 formats := []string{
201 // Standard formats
202 "2006-01-02 15:04:05", // YYYY-MM-DD HH:MM:SS
203 "2006-01-02T15:04:05", // ISO 8601 without timezone
204 "2006-01-02T15:04:05Z", // ISO 8601 UTC
205 "2006-01-02 15:04", // YYYY-MM-DD HH:MM
206 "2006-01-02", // YYYY-MM-DD (defaults to start of day)
207
208 // Alternative formats
209 "01/02/2006 15:04:05", // MM/DD/YYYY HH:MM:SS
210 "01/02/2006 15:04", // MM/DD/YYYY HH:MM
211 "01/02/2006", // MM/DD/YYYY
212 "02/01/2006 15:04:05", // DD/MM/YYYY HH:MM:SS
213 "02/01/2006 15:04", // DD/MM/YYYY HH:MM
214 "02/01/2006", // DD/MM/YYYY
215
216 // Readable formats
217 "January 2, 2006 15:04:05", // January 2, 2006 15:04:05
218 "January 2, 2006 15:04", // January 2, 2006 15:04
219 "January 2, 2006", // January 2, 2006
220 "Jan 2, 2006 15:04:05", // Jan 2, 2006 15:04:05
221 "Jan 2, 2006 15:04", // Jan 2, 2006 15:04
222 "Jan 2, 2006", // Jan 2, 2006
223 "2 January 2006 15:04:05", // 2 January 2006 15:04:05
224 "2 January 2006 15:04", // 2 January 2006 15:04
225 "2 January 2006", // 2 January 2006
226 "2 Jan 2006 15:04:05", // 2 Jan 2006 15:04:05
227 "2 Jan 2006 15:04", // 2 Jan 2006 15:04
228 "2 Jan 2006", // 2 Jan 2006
229 "January 2 2006 15:04:05", // January 2 2006 15:04:05 (no comma)
230 "January 2 2006 15:04", // January 2 2006 15:04 (no comma)
231 "January 2 2006", // January 2 2006 (no comma)
232 "Jan 2 2006 15:04:05", // Jan 2 2006 15:04:05 (no comma)
233 "Jan 2 2006 15:04", // Jan 2 2006 15:04 (no comma)
234 "Jan 2 2006", // Jan 2 2006 (no comma)
235
236 // RFC formats
237 time.RFC3339, // 2006-01-02T15:04:05Z07:00
238 time.RFC822, // 02 Jan 06 15:04 MST
239 time.RFC850, // Monday, 02-Jan-06 15:04:05 MST
240 time.RFC1123, // Mon, 02 Jan 2006 15:04:05 MST
241 }
242
243 // Clean up the input string
244 dateTimeStr = strings.TrimSpace(dateTimeStr)
245
246 // Handle ordinal numbers (1st, 2nd, 3rd, 4th, etc.)
247 dateTimeStr = ordinalPattern.ReplaceAllString(dateTimeStr, "$1")
248
249 // Try to parse with each format
250 for _, format := range formats {
251 if parsed, err := time.Parse(format, dateTimeStr); err == nil {
252 // Successfully parsed, convert to UTC and return in standard format
253 result := parsed.UTC().Format("2006-01-02 15:04:05")

Callers 2

resolveStopTimeFunction · 0.85

Calls 2

PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 1