Skip to content

Commit

Permalink
Use Go timezone format that allows for both zulu and -07:00 style for…
Browse files Browse the repository at this point in the history
…matting.

PiperOrigin-RevId: 643129627
  • Loading branch information
suyashkumar authored and copybara-github committed Jun 13, 2024
1 parent 9adf7d4 commit fa7f34d
Showing 1 changed file with 2 additions and 15 deletions.
17 changes: 2 additions & 15 deletions internal/datehelpers/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@ func DateTimeString(d time.Time, precision model.DateTimePrecision) (string, err
default:
return "", fmt.Errorf("unsupported precision in Date with value %v %w", precision, ErrUnsupportedPrecision)
}
timeZone, err := locationToTimeZoneString(d.Location())
if err != nil {
return "", err
}
return "@" + d.Format(dtFormat+timeZone), nil
tzFormat := "Z07:00" // uses "Z" for UTC timezones, -07:00 style for others.
return "@" + d.Format(dtFormat+tzFormat), nil
}

// TimeString returns a CQL Time string representation of a Time.
Expand All @@ -82,13 +79,3 @@ func TimeString(d time.Time, precision model.DateTimePrecision) (string, error)
}
return d.Format(tFormat), nil
}

func locationToTimeZoneString(loc *time.Location) (string, error) {
if loc == nil {
return "", fmt.Errorf("internal error - loc must be set when calling locationToTimeZoneString")
}
if loc == time.UTC {
return zuluTZ, nil
}
return tz, nil
}

0 comments on commit fa7f34d

Please sign in to comment.