isDateFormat checks if a PG format string is a date/time format (vs number format).
(format string)
| 535 | |
| 536 | // isDateFormat checks if a PG format string is a date/time format (vs number format). |
| 537 | func isDateFormat(format string) bool { |
| 538 | upper := strings.ToUpper(format) |
| 539 | dateSpecifiers := []string{ |
| 540 | "YYYY", "YY", "DD", "HH", "SS", "MON", "MONTH", "DAY", "DY", |
| 541 | "TZ", "AM", "PM", "A.M.", "P.M.", "DDD", "IW", "WW", "IYYY", |
| 542 | } |
| 543 | for _, s := range dateSpecifiers { |
| 544 | if strings.Contains(upper, s) { |
| 545 | return true |
| 546 | } |
| 547 | } |
| 548 | // MI is ambiguous (minute in date, minus-sign-after in number). |
| 549 | // If there are other date specifiers, it's already detected above. |
| 550 | // If MI appears alone with no digit placeholders (9, 0), treat as date. |
| 551 | if strings.Contains(upper, "MI") && !strings.ContainsAny(upper, "90") { |
| 552 | return true |
| 553 | } |
| 554 | return false |
| 555 | } |
| 556 | |
| 557 | // pgDateFormatToStrftime converts PostgreSQL date/time format specifiers to strftime/strptime format. |
| 558 | // Processes left-to-right with longest-match-first to avoid ambiguity. |