Skip to content

Commit

Permalink
Dates: use default locale to display dates
Browse files Browse the repository at this point in the history
Shovel uses `Intl.DateTimeFormat` to format times.
This commmit removes the hardcoded `en-US` locale to use the locale defined by
the user.

This fixes dates using 12-hours time (AM/PM) instead of 24-hours time on user
agents that are configured to use 24-hours times.

It also affects the dates format (MM/DD/YYYY).

Before:
```
From 7/20/2024, 11:17:59.638 PM to 7/20/2024, 11:17:59.936 PM, tick 557
```

After (locale `en-GB`):
```
From 20/07/2024, 23:17:59.638 to 20/07/2024, 23:17:59.936, tick 557
```
  • Loading branch information
XeR committed Jul 21, 2024
1 parent dc04829 commit e5733a4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions webapp/static/js/flowdisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ class FlowDisplay {
fractionalSecondDigits: 3
}
const dateStart = new Date(flow.flow.ts_start)
const formatedDateStart = new Intl.DateTimeFormat('en-US', dateParams).format(dateStart)
const formatedDateStart = new Intl.DateTimeFormat(undefined, dateParams).format(dateStart)
const dateEnd = new Date(flow.flow.ts_end)
const formatedDateEnd = new Intl.DateTimeFormat('en-US', dateParams).format(dateEnd)
const formatedDateEnd = new Intl.DateTimeFormat(undefined, dateParams).format(dateEnd)

// Change document title
document.title = `${flow.flow.dest_ipport} - Shovel`
Expand Down
2 changes: 1 addition & 1 deletion webapp/static/js/flowlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ class FlowList {
flows.forEach((flow) => {
const date = new Date(flow.ts_start)
const startDate = new Intl.DateTimeFormat(
'en-US',
undefined,
{ hour: 'numeric', minute: 'numeric', second: 'numeric', fractionalSecondDigits: 1 }
).format(date)

Expand Down

0 comments on commit e5733a4

Please sign in to comment.