From 742fad61253828c8203c3f70cd9d3764009778b5 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 6 Feb 2020 23:01:29 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 2 ++ ayanova/src/api/locale.js | 22 ++++++++++++++++++++ ayanova/src/components/date-time-control.vue | 10 ++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index a26c8df3..76e2f144 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -75,6 +75,8 @@ TODO: LOCALIZATION - Make functional user settings form so can test shit out - Need override for locale, currency setting, 12hr clock etc etc + - Need a browser check on opening the login page that will check to ensure the browser can do the date conversions properly etc and tell user browser is unsuitable if it isn't + - TRY AN ALTERNATE LANGUAGE IN VUETIFY USING THEIR METHOD, SEE WHATS INVOLVED - Find out how to override the default locale for vuetify to set specific items to our localized text version - this saves having to use a whole locale for just the calendar etc diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index 065713d0..37249cf2 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -214,6 +214,7 @@ export default { /////////////////////////////////////////// // Get users default time zone //https://www.iana.org/time-zones + //https://en.wikipedia.org/wiki/List_of_tz_database_time_zones getTimeZoneName() { return Intl.DateTimeFormat().resolvedOptions().timeZone; }, @@ -316,6 +317,27 @@ export default { hour12: hour12 }); }, + /////////////////////////////////////////////// + // Convert a utc date to local time zone + // and return time portion only in iso 8601 + // format (used by time and date picker components) + // + utcDateStringTo8601TimeOnlyString(value, timeZoneName) { + if (!value) { + //if no value, return the current time as expected by the time picker + } else { + //ok, the reason for sv-SE is that it's a locale that returns the time already in ISO format and 24hr by default + //that can change over time so if this breaks that's why + //also fr-CA does as well as possibly en-CA + //https://stackoverflow.com/a/58633686/8939 + if (!timeZoneName) { + timeZoneName = this.getTimeZoneName(); + } + return new Date(value).toLocaleTimeString("sv-SE", { + timeZone: timeZoneName + }); + } + }, //////////////////////////////////////////////////////// // dynamically set the vuetify language elements from // users localized text (am/pm etc) diff --git a/ayanova/src/components/date-time-control.vue b/ayanova/src/components/date-time-control.vue index 599b88f7..3206adcc 100644 --- a/ayanova/src/components/date-time-control.vue +++ b/ayanova/src/components/date-time-control.vue @@ -229,16 +229,20 @@ export default { //----------------- //expects just the hours minutes seconds portion: 18:18:49 //TODO: Need to convert to desired time zone first or the control will show the UTC time instead + //console.log(new Date().toLocaleTimeString('sv-SE',{timeZone:"America/Vancouver"})); + //console.log(new Date().toLocaleTimeString('sv-SE',{timeZone:"UTC"})); get() { if (this.value) { - console.log(this.value.substr(11, 8)); - return this.value.substr(11, 8); + //Ok, this looks weird but sv-SE is the same format as iso8601 format required so if this breaks that's why + return new Date(this.value).toLocaleTimeString("sv-SE", { + timeZone: this.timeZoneName + }); } else { return ""; } }, set(value) { - this.value = value; + //this.value = value; } } }