aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLisandro Pin <lisandro.pin@proton.ch>2025-11-06 21:07:29 +0100
committerGitHub <noreply@github.com>2025-11-06 12:07:29 -0800
commit5fef4145a4cdd003ff8a7156413a28f923e8175d (patch)
tree817ab5f20ee79a95df42e2c3ee551db5674e058d
parent084b377f8786e3a4d98e0763c3e83be104a9b65e (diff)
downloadseaweedfs-5fef4145a4cdd003ff8a7156413a28f923e8175d.tar.xz
seaweedfs-5fef4145a4cdd003ff8a7156413a28f923e8175d.zip
Fix date string parsing bug for the SQL Engine. (#7446)
`SQLEngine.valueToTime()` is parsing dates always as UTC (via `time.Parse()`), regardless of TZ assumptions for different date formats.
-rw-r--r--weed/query/engine/function_helpers.go20
1 files changed, 8 insertions, 12 deletions
diff --git a/weed/query/engine/function_helpers.go b/weed/query/engine/function_helpers.go
index 60eccdd37..50f71dc08 100644
--- a/weed/query/engine/function_helpers.go
+++ b/weed/query/engine/function_helpers.go
@@ -102,22 +102,18 @@ func (e *SQLEngine) valueToTime(value *schema_pb.Value) (time.Time, error) {
case *schema_pb.Value_StringValue:
// Try to parse various date/time string formats
dateFormats := []struct {
- format string
- useLocal bool
+ format string
+ tz *time.Location
}{
- {"2006-01-02 15:04:05", true}, // Local time assumed for non-timezone formats
- {"2006-01-02T15:04:05Z", false}, // UTC format
- {"2006-01-02T15:04:05", true}, // Local time assumed
- {"2006-01-02", true}, // Local time assumed for date only
- {"15:04:05", true}, // Local time assumed for time only
+ {"2006-01-02 15:04:05", time.Local}, // Local time assumed for non-timezone formats
+ {"2006-01-02T15:04:05Z", time.UTC}, // UTC format
+ {"2006-01-02T15:04:05", time.Local}, // Local time assumed
+ {"2006-01-02", time.Local}, // Local time assumed for date only
+ {"15:04:05", time.Local}, // Local time assumed for time only
}
for _, formatSpec := range dateFormats {
- if t, err := time.Parse(formatSpec.format, v.StringValue); err == nil {
- if formatSpec.useLocal {
- // Convert to UTC for consistency if no timezone was specified
- return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), time.UTC), nil
- }
+ if t, err := time.ParseInLocation(formatSpec.format, v.StringValue, formatSpec.tz); err == nil {
return t, nil
}
}