Skip to content

Commit

Permalink
Merge pull request #88 from armada-ths/hampus/fix/timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
hampfh authored Sep 10, 2024
2 parents f6c56a5 + bcc9694 commit 180b78f
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.setZone("Europe/Stockholm").isInDST) return date.setZone("UTC-2")
return date.setZone("UTC-1")
}

0 comments on commit 180b78f

Please sign in to comment.