Skip to content

Commit

Permalink
Allow empty location as no location info (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
nasermirzaei89 authored Apr 11, 2024
1 parent 8a73abf commit 24b70d2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ func FromString(s string) (Date, error) {
// FromTime validates that a `time.Time{}` contains a date and converts it to a
// `Date{}`.
func FromTime(t time.Time) (Date, error) {
zone, offset := t.Zone()

hasLocationInfo := !(t.Location() == time.UTC || (zone == "" && offset == 0))

if t.Hour() != 0 ||
t.Minute() != 0 ||
t.Second() != 0 ||
t.Nanosecond() != 0 ||
t.Location() != time.UTC {
hasLocationInfo {
return Date{}, fmt.Errorf("timestamp contains more than just date information; %s", t.Format(time.RFC3339Nano))
}

Expand Down

0 comments on commit 24b70d2

Please sign in to comment.