From 0f44d03c6406d31dc65ab7d2a7726bc25e905a6c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 6 Feb 2020 20:16:20 +0000 Subject: [PATCH] --- ayanova/src/api/locale.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index f30e7d5a..deca7bef 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -217,6 +217,45 @@ export default { getTimeZoneName() { return Intl.DateTimeFormat().resolvedOptions().timeZone; }, + /////////////////////////////////////////// + // Turn a utc date into a displayable + // short date and time + // + utcDateToShortDateAndTimeLocalized( + value, + timeZoneName, + languageName, + hour12 + ) { + if (!value) { + return ""; + } + if (!timeZoneName) { + timeZoneName = this.getTimeZoneName(); + } + if (!languageName) { + languageName = this.getBrowserLanguages(); + } + + if (!hour12) { + hour12 = window.$gz.store.state.locale.hour12; + } + + //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z") + var parsedDate = new Date(value); + + //is it a valid date? + if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { + return "not valid"; + } + + return parsedDate.toLocaleString(languageName, { + timeZone: timeZoneName, + dateStyle: "short", + timeStyle: "short", + hour12: locale.format().hour12 + }); + }, //////////////////////////////////////////////////////// // dynamically set the vuetify language elements from // users localized text (am/pm etc)