fix(timezones): move from utc offsets to timezones

This fixed various issues related to calculating streaks, etc. Now we
appropriately handle time as it was, vs as it is relative to an offset.
This commit is contained in:
2024-03-11 13:13:26 -04:00
parent 8e81acd381
commit f1414e3e4e
12 changed files with 495 additions and 433 deletions

View File

@@ -228,7 +228,7 @@ func (api *API) generateTemplates() *multitemplate.Renderer {
"dict": dict,
"fields": fields,
"getSVGGraphData": getSVGGraphData,
"getUTCOffsets": getUTCOffsets,
"getTimeZones": getTimeZones,
"hasPrefix": strings.HasPrefix,
"niceNumbers": niceNumbers,
"niceSeconds": niceSeconds,

View File

@@ -69,7 +69,7 @@ type requestDocumentIdentify struct {
type requestSettingsEdit struct {
Password *string `form:"password"`
NewPassword *string `form:"new_password"`
TimeOffset *string `form:"time_offset"`
Timezone *string `form:"timezone"`
}
type requestDocumentAdd struct {
@@ -299,8 +299,8 @@ func (api *API) appGetSettings(c *gin.Context) {
}
templateVars["Data"] = gin.H{
"TimeOffset": *user.TimeOffset,
"Devices": devices,
"Timezone": *user.Timezone,
"Devices": devices,
}
c.HTML(http.StatusOK, "page/settings", templateVars)
@@ -869,7 +869,7 @@ func (api *API) appEditSettings(c *gin.Context) {
}
// Validate Something Exists
if rUserSettings.Password == nil && rUserSettings.NewPassword == nil && rUserSettings.TimeOffset == nil {
if rUserSettings.Password == nil && rUserSettings.NewPassword == nil && rUserSettings.Timezone == nil {
log.Error("Missing Form Values")
appErrorPage(c, http.StatusBadRequest, "Invalid or missing form values")
return
@@ -901,9 +901,9 @@ func (api *API) appEditSettings(c *gin.Context) {
}
// Set Time Offset
if rUserSettings.TimeOffset != nil {
if rUserSettings.Timezone != nil {
templateVars["TimeOffsetMessage"] = "Time Offset Updated"
newUserSettings.TimeOffset = rUserSettings.TimeOffset
newUserSettings.Timezone = rUserSettings.Timezone
}
// Update User
@@ -931,8 +931,8 @@ func (api *API) appEditSettings(c *gin.Context) {
}
templateVars["Data"] = gin.H{
"TimeOffset": *user.TimeOffset,
"Devices": devices,
"Timezone": *user.Timezone,
"Devices": devices,
}
c.HTML(http.StatusOK, "page/settings", templateVars)

View File

@@ -13,54 +13,43 @@ import (
"reichard.io/antholume/metadata"
)
type UTCOffset struct {
Name string
Value string
}
var UTC_OFFSETS = []UTCOffset{
{Value: "-12 hours", Name: "UTC12:00"},
{Value: "-11 hours", Name: "UTC11:00"},
{Value: "-10 hours", Name: "UTC10:00"},
{Value: "-9.5 hours", Name: "UTC09:30"},
{Value: "-9 hours", Name: "UTC09:00"},
{Value: "-8 hours", Name: "UTC08:00"},
{Value: "-7 hours", Name: "UTC07:00"},
{Value: "-6 hours", Name: "UTC06:00"},
{Value: "-5 hours", Name: "UTC05:00"},
{Value: "-4 hours", Name: "UTC04:00"},
{Value: "-3.5 hours", Name: "UTC03:30"},
{Value: "-3 hours", Name: "UTC03:00"},
{Value: "-2 hours", Name: "UTC02:00"},
{Value: "-1 hours", Name: "UTC01:00"},
{Value: "0 hours", Name: "UTC±00:00"},
{Value: "+1 hours", Name: "UTC+01:00"},
{Value: "+2 hours", Name: "UTC+02:00"},
{Value: "+3 hours", Name: "UTC+03:00"},
{Value: "+3.5 hours", Name: "UTC+03:30"},
{Value: "+4 hours", Name: "UTC+04:00"},
{Value: "+4.5 hours", Name: "UTC+04:30"},
{Value: "+5 hours", Name: "UTC+05:00"},
{Value: "+5.5 hours", Name: "UTC+05:30"},
{Value: "+5.75 hours", Name: "UTC+05:45"},
{Value: "+6 hours", Name: "UTC+06:00"},
{Value: "+6.5 hours", Name: "UTC+06:30"},
{Value: "+7 hours", Name: "UTC+07:00"},
{Value: "+8 hours", Name: "UTC+08:00"},
{Value: "+8.75 hours", Name: "UTC+08:45"},
{Value: "+9 hours", Name: "UTC+09:00"},
{Value: "+9.5 hours", Name: "UTC+09:30"},
{Value: "+10 hours", Name: "UTC+10:00"},
{Value: "+10.5 hours", Name: "UTC+10:30"},
{Value: "+11 hours", Name: "UTC+11:00"},
{Value: "+12 hours", Name: "UTC+12:00"},
{Value: "+12.75 hours", Name: "UTC+12:45"},
{Value: "+13 hours", Name: "UTC+13:00"},
{Value: "+14 hours", Name: "UTC+14:00"},
}
func getUTCOffsets() []UTCOffset {
return UTC_OFFSETS
func getTimeZones() []string {
return []string{
"Africa/Cairo",
"Africa/Johannesburg",
"Africa/Lagos",
"Africa/Nairobi",
"America/Adak",
"America/Anchorage",
"America/Buenos_Aires",
"America/Chicago",
"America/Denver",
"America/Los_Angeles",
"America/Mexico_City",
"America/New_York",
"America/Nuuk",
"America/Phoenix",
"America/Puerto_Rico",
"America/Sao_Paulo",
"America/St_Johns",
"America/Toronto",
"Asia/Dubai",
"Asia/Hong_Kong",
"Asia/Kolkata",
"Asia/Seoul",
"Asia/Shanghai",
"Asia/Singapore",
"Asia/Tokyo",
"Atlantic/Azores",
"Australia/Melbourne",
"Australia/Sydney",
"Europe/Berlin",
"Europe/London",
"Europe/Moscow",
"Europe/Paris",
"Pacific/Auckland",
"Pacific/Honolulu",
}
}
func niceSeconds(input int64) (result string) {