Skip to content

Commit

Permalink
Fixed: the 12-hour format issue when using specific formatting option…
Browse files Browse the repository at this point in the history
…s in luxon(#188)
  • Loading branch information
ymaheshwari1 committed Apr 18, 2024
1 parent a355935 commit 95f3bdb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ const sortSequence = (sequence: Array<Group | Route | Rule>, sortOnField = "sequ
}

const getTime = (time: any) => {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.TIME_SIMPLE) : "-";
// Directly using TIME_SIMPLE for formatting the time does not work, as the Intl is set in that way. So, using hourCycle to always get the time in 12-hour format
// https://github.com/moment/luxon/issues/998
return time ? DateTime.fromMillis(time).toLocaleString({ ...DateTime.TIME_SIMPLE, hourCycle: "h12" }) : "-";
}

function getDate(runTime: any) {
return DateTime.fromMillis(runTime).toLocaleString(DateTime.DATE_MED);
return DateTime.fromMillis(runTime).toLocaleString({ ...DateTime.DATE_MED, hourCycle: "h12" });
}

function getDateAndTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : "-";
return time ? DateTime.fromMillis(time).toLocaleString({ ...DateTime.DATETIME_MED, hourCycle: "h12" }) : "-";
}

function getDateAndTimeShort(time: any) {
Expand Down
4 changes: 4 additions & 0 deletions src/views/BrokeringRuns.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ onIonViewWillEnter(async () => {
})
function timeTillRun(time: any) {
if(!time) {
return;
}
const timeDiff = DateTime.fromMillis(time).diff(DateTime.local());
return DateTime.local().plus(timeDiff).toRelative();
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function logout() {
}
function getDateTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : "";
return time ? DateTime.fromMillis(time).toLocaleString({ ...DateTime.DATETIME_MED, hourCycle: "h12" }) : "";
}
function goToOms() {
Expand Down

0 comments on commit 95f3bdb

Please sign in to comment.