Skip to content

Commit

Permalink
enh: Add GetLocalTimezone and ConvertUTCToLocal functions
Browse files Browse the repository at this point in the history
  • Loading branch information
tphakala committed Aug 15, 2024
1 parent 4c297f1 commit 5a137d7
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/conf/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,17 @@ func ParseWeekday(day string) (time.Weekday, error) {
func (lc *LogConfig) GetRotationDay() (time.Weekday, error) {
return ParseWeekday(lc.RotationDay)
}

// GetLocalTimezone returns the local time zone of the system.
func GetLocalTimezone() (*time.Location, error) {
return time.Local, nil
}

// ConvertUTCToLocal converts a UTC time to the local time zone.
func ConvertUTCToLocal(utcTime time.Time) (time.Time, error) {
localLoc, err := GetLocalTimezone()
if err != nil {
return time.Time{}, fmt.Errorf("failed to get local timezone: %w", err)
}
return utcTime.In(localLoc), nil
}

0 comments on commit 5a137d7

Please sign in to comment.