Skip to content

Commit

Permalink
fix: timezone diff
Browse files Browse the repository at this point in the history
  • Loading branch information
hampfh committed Sep 10, 2024
1 parent f6c56a5 commit 10d96f1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,29 @@ export function formatDate(isoString: string) {
}

export function formatTimestampAsDate(epochSeconds: number) {
const date = DateTime.fromMillis(epochSeconds * 1000)
const date = adjustTimezone(
DateTime.fromMillis(epochSeconds * 1000, {
zone: "Europe/London"
})
)
return date.toFormat(getDateFormatString(date))
}

export function formatTimestampAsTime(epochSeconds: number) {
const date = DateTime.fromMillis(epochSeconds * 1000)
const date = adjustTimezone(
DateTime.fromMillis(epochSeconds * 1000, {
zone: "Europe/London"
})
)
return date.toFormat("HH:mm")
}

/**
* There is something weird going on with the ais timestamp,
* making luxon think we're in the wrong timezone, this way
* we force it to be sweden specific.
*/
function adjustTimezone(date: DateTime) {
if (date.isInDST) return date.setZone("UTC-2")
return date.setZone("UTC-1")
}

0 comments on commit 10d96f1

Please sign in to comment.