Skip to content

Commit

Permalink
utc timezone (#4954)
Browse files Browse the repository at this point in the history
  • Loading branch information
k-anshul committed May 27, 2024
1 parent 13991c3 commit 99b2fc3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions runtime/pkg/pbutil/pbutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ func ToValue(v any, t *runtimev1.Type) (*structpb.Value, error) {
return structpb.NewNumberValue(float64(v)), nil
case time.Time:
if t != nil && t.Code == runtimev1.Type_CODE_DATE {
s := v.Format(time.DateOnly)
s := v.In(time.UTC).Format(time.DateOnly)
return structpb.NewStringValue(s), nil
}
s := v.Format(time.RFC3339Nano)
s := v.In(time.UTC).Format(time.RFC3339Nano)
return structpb.NewStringValue(s), nil
case float32:
// Turning NaNs and Infs into nulls until frontend can deal with them as strings
Expand Down Expand Up @@ -147,10 +147,10 @@ func ToValue(v any, t *runtimev1.Type) (*structpb.Value, error) {
return structpb.NewNumberValue(float64(*v)), nil
case *time.Time:
if t != nil && t.Code == runtimev1.Type_CODE_DATE {
s := v.Format(time.DateOnly)
s := v.In(time.UTC).Format(time.DateOnly)
return structpb.NewStringValue(s), nil
}
s := v.Format(time.RFC3339Nano)
s := v.In(time.UTC).Format(time.RFC3339Nano)
return structpb.NewStringValue(s), nil
case *float32:
// Turning NaNs and Infs into nulls until frontend can deal with them as strings
Expand Down
3 changes: 2 additions & 1 deletion runtime/queries/metricsview_aggregation.go
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,8 @@ func (q *MetricsViewAggregation) buildTimestampExpr(mv *runtimev1.MetricsViewSpe
if dim.TimeZone == "" || dim.TimeZone == "UTC" || dim.TimeZone == "Etc/UTC" {
return fmt.Sprintf("date_trunc('%s', %s)", dialect.ConvertToDateTruncSpecifier(dim.TimeGrain), col), nil, nil
}
return fmt.Sprintf("toTimezone(date_trunc('%s', toTimezone(%s::TIMESTAMP, ?)), ?)", dialect.ConvertToDateTruncSpecifier(dim.TimeGrain), col), []any{dim.TimeZone, dim.TimeZone}, nil
// The return type of date_trunc('month', ...) is Date so need another TIMESTAMP cast
return fmt.Sprintf("toTimezone(date_trunc('%s', toTimezone(%s::TIMESTAMP, ?))::TIMESTAMP, ?)", dialect.ConvertToDateTruncSpecifier(dim.TimeGrain), col), []any{dim.TimeZone, dim.TimeZone}, nil
case drivers.DialectPinot:
// ToDateTime format truncates millis to secs because we don't support that, for example timeseries api does timestamppb.New(ts) which truncates to seconds
return fmt.Sprintf("ToDateTime(date_trunc('%s', %s, 'MILLISECONDS', ?), 'yyyy-MM-dd''T''HH:mm:ss''Z''')", dialect.ConvertToDateTruncSpecifier(dim.TimeGrain), col), []any{dim.TimeZone}, nil
Expand Down

1 comment on commit 99b2fc3

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://ui.rilldata.com as production
🚀 Deployed on https://665420ea165fa13cb0e850fe--rill-ui.netlify.app

Please sign in to comment.