Skip to content

Commit

Permalink
fix(itinerary-details): wrong date time locale
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Helms authored and Andreas Helms committed Dec 10, 2024
1 parent 29a5e7e commit 89db05d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/component/Duration.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ function Duration(props) {
hour12: false,
};
const duration = durationToString(props.duration * 1000);
const startTime = new Intl.DateTimeFormat('en-US', timeOptions).format(
const startTime = new Intl.DateTimeFormat('de-DE', timeOptions).format(
new Date(props.startTime),
);
const endTime = new Intl.DateTimeFormat('en-US', timeOptions).format(
const endTime = new Intl.DateTimeFormat('de-DE', timeOptions).format(
new Date(props.endTime),
);
const futureText = props.futureText
Expand Down
42 changes: 41 additions & 1 deletion app/util/timeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,47 @@ export function isToday(startTime, refTime) {
* Returns formatted date / time
*/
export function getFormattedTimeDate(startTime, pattern) {
return moment(startTime).format(pattern);
return moment(startTime).locale('de').format(pattern);
}

/**
* Epoch ms to 'hh:mm'
*/
export function epochToTime(ms, config) {
const time = new Date(ms).toLocaleTimeString('de-DE', {
timeZone: config.timeZone,
});
const parts = time.split(':');
return `${parts[0]}:${parts[1]}`;
}

/**
* Unix time (from epoch milliseconds if given)
*/
export function unixTime(ms) {
const t = ms || Date.now();
return Math.floor(t / 1000);
}

/**
* Unix to 'YYYYMMDD'
*/
export function unixToYYYYMMDD(s, config) {
const date = new Date(s * 1000).toLocaleDateString('de-DE', {
timeZone: config.timeZone,
});
const parts = date.split('/');
return `${parts[2]}${parts[1]}${parts[0]}`;
}

/**
* ISO-8601/RFC3339 datetime str to 'hh:mm'
*/
export function timeStr(dateTime) {
// e.g. "2024-06-13T14:30+03:00"
const parts = dateTime.split('T');
const time = parts[1].split(':');
return `${time[0]}:${time[1]}`;
}

/**
Expand Down

0 comments on commit 89db05d

Please sign in to comment.