From 7c8308f149efcaea034b036163ebd55a4f99a600 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 6 Feb 2020 20:27:20 +0000 Subject: [PATCH] --- ayanova/src/api/locale.js | 32 +++++++++++++++++++ ayanova/src/components/gz-data-table.vue | 27 +++++++++------- ayanova/src/main.js | 40 ------------------------ 3 files changed, 48 insertions(+), 51 deletions(-) diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index 5ec4d75f..43bc6746 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -282,6 +282,38 @@ export default { timeZone: timeZoneName, dateStyle: "short" }); + }, /////////////////////////////////////////// + // Turn a utc date into a displayable + // short time + // + utcDateToShortTimeLocalized(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.toLocaleTimeString(languageName, { + timeZone: timeZoneName, + timeStyle: "short", + hour12: hour12 + }); }, //////////////////////////////////////////////////////// // dynamically set the vuetify language elements from diff --git a/ayanova/src/components/gz-data-table.vue b/ayanova/src/components/gz-data-table.vue index 133b4f68..eccdb160 100644 --- a/ayanova/src/components/gz-data-table.vue +++ b/ayanova/src/components/gz-data-table.vue @@ -450,23 +450,28 @@ function buildRecords(listData, columndefinitions, filters) { var display = column.v; switch (dataType) { case 1: //datetime format to shortdatetime - display = window.$gz.locale.utcDateToShortDateAndTimeLocalized( + // display = window.$gz.locale.utcDateToShortDateAndTimeLocalized( + // display, + // timeZoneName, + // languageName, + // hour12 + // ); + // break; + // case 2: //date only + // display = window.$gz.locale.utcDateToShortDateLocalized( + // display, + // timeZoneName, + // languageName + // ); + // break; + case 3: //time only + display = display = window.$gz.locale.utcDateToShortTimeLocalized( display, timeZoneName, languageName, hour12 ); break; - case 2: //date only - display = window.$gz.locale.utcDateToShortDateLocalized( - display, - timeZoneName, - languageName - ); - break; - case 3: //time only - display = filters.shorttimeonlylocalized(display); - break; // case 6: //bool // display = filters.boolastext(display); // break; diff --git a/ayanova/src/main.js b/ayanova/src/main.js index 9108a6fd..b3e645b1 100644 --- a/ayanova/src/main.js +++ b/ayanova/src/main.js @@ -149,46 +149,6 @@ Vue.filter("capitalize", function vueFilterCapitalize(value) { -//Convert date to localized value and return as short date format chosen -Vue.filter("shortdateonlylocalized", function vueFilterShortDateOnlyLocalized( - value -) { - //TODO NOT DONE - if (!value) return ""; - var localizedDate = dayjs - .utc(value) - .add(locale.format().timeZoneOffset, "hour") - .toDate(); - - return localizedDate.toLocaleDateString( - window.$gz.locale.getBrowserLanguages(), - { - dateStyle: "short" - } - ); -}); - -//Convert date to localized value and return as short date format chosen -Vue.filter("shorttimeonlylocalized", function vueFilterShortTimeOnlyLocalized( - value -) { - //TODO NOT DONE - if (!value) return ""; - //new Date().toLocaleString(undefined,{dateStyle:"short",timeStyle:"short",hour12:false}) - //also toLocaleDateString and toLocaleTimeString well supported use similar options - var localizedDate = dayjs - .utc(value) - .add(locale.format().timeZoneOffset, "hour") - .toDate(); - - return localizedDate.toLocaleTimeString( - window.$gz.locale.getBrowserLanguages(), - { - timeStyle: "short", - hour12: locale.format().hour12 - } - ); -}); //https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toLocaleString#Browser_compatibility //https://www.currency-iso.org/en/home.html