MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / isDateValue

Function isDateValue

buffer.go:563–615  ·  view source on GitHub ↗

isDateValue checks if a string represents a valid date with fast pre-checks

(s string)

Source from the content-addressed store, hash-verified

561
562// isDateValue checks if a string represents a valid date with fast pre-checks
563func isDateValue(s string) bool {
564 if len(s) == 0 {
565 return false
566 }
567
568 // Fast rejection: dates are typically 8-30 characters
569 if len(s) < 8 || len(s) > 30 {
570 return false
571 }
572
573 // Quick heuristic checks before trying to parse
574 // Dates typically contain: -, /, :, T, or spaces with commas (for month names)
575 hasDateSep := strings.ContainsAny(s, "-/.:T") || (strings.Contains(s, " ") && strings.Contains(s, ","))
576 if !hasDateSep {
577 return false
578 }
579
580 // Must contain at least one digit
581 hasDigit := false
582 for _, c := range s {
583 if c >= '0' && c <= '9' {
584 hasDigit = true
585 break
586 }
587 }
588 if !hasDigit {
589 return false
590 }
591
592 // Common date formats (most common first for performance)
593 formats := []string{
594 "2006-01-02", // ISO date: 2024-10-17
595 "2006-01-02 15:04:05", // ISO datetime: 2024-10-17 15:30:00
596 "01/02/2006", // US date: 10/17/2024
597 "02/01/2006", // EU date: 17/10/2024
598 "2006/01/02", // Alt ISO: 2024/10/17
599 time.RFC3339, // RFC3339: 2024-10-17T15:30:00Z
600 "2006-01-02T15:04:05", // ISO8601 without timezone
601 "Jan 02, 2006", // Mon DD, YYYY
602 "January 02, 2006", // Month DD, YYYY
603 "02-Jan-2006", // DD-Mon-YYYY
604 "02 Jan 2006", // DD Mon YYYY
605 "2006.01.02", // Dotted date
606 }
607
608 for _, format := range formats {
609 if _, err := time.Parse(format, s); err == nil {
610 return true
611 }
612 }
613
614 return false
615}
616
617// isNumericValue checks if a string represents a valid number
618// Handles: integers, floats, scientific notation, negative numbers

Callers 2

TestIsDateValueFunction · 0.85
autoDetectColumnTypeMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestIsDateValueFunction · 0.68