mirror of
https://github.com/samsonjs/retrogit.git
synced 2026-04-27 15:07:43 +00:00
Do not panic if we have a timezone that we can't load.
This commit is contained in:
parent
846a4240b2
commit
a667873958
1 changed files with 8 additions and 7 deletions
|
|
@ -29,27 +29,28 @@ func initTimezones() Timezones {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("Could not parse timezones config %s: %s", configBytes, err.Error())
|
log.Panicf("Could not parse timezones config %s: %s", configBytes, err.Error())
|
||||||
}
|
}
|
||||||
timezones = make(Timezones, len(config.LocationNames))
|
timezones = make(Timezones, 0, len(config.LocationNames))
|
||||||
// Use a January date so that UTC offsets are not affected by DST in the northern hemisphere
|
// Use a January date so that UTC offsets are not affected by DST in the northern hemisphere
|
||||||
now := time.Unix(380937600, 0)
|
now := time.Unix(380937600, 0)
|
||||||
for i, locationName := range config.LocationNames {
|
for _, locationName := range config.LocationNames {
|
||||||
if locationName == "" {
|
if locationName == "" {
|
||||||
timezones[i] = Timezone{
|
timezones = append(timezones, Timezone{
|
||||||
LocationName: locationName,
|
LocationName: locationName,
|
||||||
}
|
})
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
location, err := time.LoadLocation(locationName)
|
location, err := time.LoadLocation(locationName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panicf("Location %s could not be loaded: %s", locationName, err.Error())
|
log.Printf("Location %s could not be loaded: %s", locationName, err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
utcDelta := now.Sub(time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), now.Nanosecond(), location))
|
utcDelta := now.Sub(time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second(), now.Nanosecond(), location))
|
||||||
utcDeltaHours := int(utcDelta.Hours())
|
utcDeltaHours := int(utcDelta.Hours())
|
||||||
utcDeltaMinutes := int(utcDelta.Minutes()) - 60*utcDeltaHours
|
utcDeltaMinutes := int(utcDelta.Minutes()) - 60*utcDeltaHours
|
||||||
timezones[i] = Timezone{
|
timezones = append(timezones, Timezone{
|
||||||
LocationName: locationName,
|
LocationName: locationName,
|
||||||
DisplayUTCOffset: fmt.Sprintf("%d:%02d", utcDeltaHours, utcDeltaMinutes),
|
DisplayUTCOffset: fmt.Sprintf("%d:%02d", utcDeltaHours, utcDeltaMinutes),
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
return timezones
|
return timezones
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue