chairemobilite / transition

Transition is a modern new approach to transit planning. It's a web application to model, simulate and plan public transit and alternative transportation.
http://transition.city
MIT License
20 stars 13 forks source link

Add international formatter to chaire-lib DateTimeUtils #995

Open kaligrafy opened 5 days ago

kaligrafy commented 5 days ago
const intlDateFormatOptions: Intl.DateTimeFormatOptions = {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    timeZone: 'America/Toronto',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: false
};
const timeFormatLocale = 'en-ca'; 

en-ca is one of the only locales that follows ISO format, so keep it hardcoded for the whole world. We can add the timeZone as a param though. Then, use this function to get date and time in ISO format:

const toDateStringAndHHmmss = function (date: Date | undefined): [string, string] {
            if (!date) {
                return ['',''];
            }
            return new Intl.DateTimeFormat(timeFormatLocale, intlDateFormatOptions).format(date).split(' ') as [string, string];
        };