mirror of https://github.com/muety/wakapi.git
fix: wrongly displayed timezone offset
This commit is contained in:
parent
f69dce39d8
commit
8b8c5675af
|
@ -90,6 +90,8 @@ func (u *User) TZ() *time.Location {
|
|||
return tz
|
||||
}
|
||||
|
||||
// TZOffset returns the time difference between the user's current time zone and UTC
|
||||
// TODO: is this actually working??
|
||||
func (u *User) TZOffset() time.Duration {
|
||||
_, offset := time.Now().In(u.TZ()).Zone()
|
||||
return time.Duration(offset * int(time.Second))
|
||||
|
|
|
@ -35,6 +35,7 @@ func DefaultTemplateFuncs() template.FuncMap {
|
|||
"add": utils.Add,
|
||||
"capitalize": utils.Capitalize,
|
||||
"toRunes": utils.ToRunes,
|
||||
"localTZOffset": utils.LocalTZOffset,
|
||||
"entityTypes": models.SummaryTypes,
|
||||
"typeName": typeName,
|
||||
"isDev": func() bool {
|
||||
|
|
|
@ -107,6 +107,12 @@ func FmtWakatimeDuration(d time.Duration) string {
|
|||
return fmt.Sprintf("%d hrs %d mins", h, m)
|
||||
}
|
||||
|
||||
// LocalTZOffset returns the time difference between server local time and UTC
|
||||
func LocalTZOffset() time.Duration {
|
||||
_, offset := time.Now().Zone()
|
||||
return time.Duration(offset * int(time.Second))
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/18632496
|
||||
func firstDayOfISOWeek(year int, week int, timezone *time.Location) time.Time {
|
||||
date := time.Date(year, 0, 0, 0, 0, 0, 0, timezone)
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
// Constants
|
||||
const defaultTab = 'account'
|
||||
const userTimeZone = {{ .User.Location }}
|
||||
const userTzOffset = {{ .User.TZOffset.Hours }} // TODO: fix this!
|
||||
const defaultTzOption = { value: 'Local', text: `Local server time (UTC+${userTzOffset})` }
|
||||
const userTzOffset = {{ localTZOffset.Hours }}
|
||||
const signPrefix = userTzOffset >= 0 ? '+' : ''
|
||||
const defaultTzOption = { value: 'Local', text: `Local server time (UTC${signPrefix}${userTzOffset})` }
|
||||
</script>
|
||||
<script type="module" src="assets/js/components/settings.js"></script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue