Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Curtis Robert <[email protected]>
  • Loading branch information
TylerHelmuth and crobert-1 committed Jun 8, 2023
1 parent 305bb44 commit 7b45c76
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions internal/coreinternal/timeutils/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func StrptimeToGo(layout string) (string, error) {

func GetLocation(location *string, layout *string) (*time.Location, error) {
if location != nil && *location != "" {
// If "location" is specified, it must be in the local timezone database
// If location is specified, it must be in the local timezone database
loc, err := time.LoadLocation(*location)
if err != nil {
return nil, fmt.Errorf("failed to load location %s: %w", *location, err)
Expand All @@ -26,7 +26,7 @@ func GetLocation(location *string, layout *string) (*time.Location, error) {
}

if layout != nil && strings.HasSuffix(*layout, "Z") {
// If a timestamp ends with 'Z', it should be interpretted at Zulu (UTC) time
// If a timestamp ends with 'Z', it should be interpreted at Zulu (UTC) time
return time.UTC, nil
}

Expand Down Expand Up @@ -86,8 +86,10 @@ func SetTimestampYear(t time.Time) time.Time {
}
n := Now()
d := time.Date(n.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), t.Nanosecond(), t.Location())
// If the timestamp would be more than 7 days in the future using this year,
// assume it's from last year.
// Assume the timestamp is from last year if its month and day are
// more than 7 days past the current date.
// i.e. If today is January 1, but the timestamp is February 1, it's safe
// to assume the timestamp is from last year.
if d.After(n.AddDate(0, 0, 7)) {
d = d.AddDate(-1, 0, 0)
}
Expand Down

0 comments on commit 7b45c76

Please sign in to comment.