From 8763aea57637adef5c871ac1052064ba92da05b4 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Thu, 6 Feb 2020 20:03:08 +0000 Subject: [PATCH] --- ayanova/devdocs/todo.txt | 3 ++- ayanova/src/api/locale.js | 8 +++++++- ayanova/src/main.js | 31 ++++++++++++------------------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ayanova/devdocs/todo.txt b/ayanova/devdocs/todo.txt index c17e875b..a26c8df3 100644 --- a/ayanova/devdocs/todo.txt +++ b/ayanova/devdocs/todo.txt @@ -58,6 +58,7 @@ TODO: LOCALIZATION - TODO: get time zone from browser with user override option - use browser default unless overridden + - Intl.DateTimeFormat().resolvedOptions().timeZone - How to handle dates and times - All dates stored in UTC format at server and transmitted that way @@ -66,7 +67,7 @@ TODO: LOCALIZATION - Client uses the built in browser tolocale* methods to display dates to user both in their desired format and desired time zone, i.e. NO HOUR ADJUSTMENTS USED -- Proper way to definitevely display a date in desired time zone: DATE.toLocaleString('en-GB', { timeZone: 'UTC', dateStyle: "short",timeStyle: "short", hour12: false }) - + - SB able to ditch the dayjs library entirely once done! - CURRENCY code, need to be able to set currency as a user option, no way to deduce it except maybe a default through deduction of locale - AM PM or 24 hour time sb a setting in locale diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index c930eab0..f30e7d5a 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -204,13 +204,19 @@ export default { // only how the user expects to see the page itself // // also for sake of future proofing and edge cases need to have it be manually settable as well - // ############### TODO: modify both of these to put the user's manual override first in line (if there is one) + // ############### TODO: modify all of these to put the user's manual override first in line (if there is one) getBrowserLanguages() { return window.navigator.languages; }, getBrowserFirstLanguage() { return window.navigator.languages[0]; }, + /////////////////////////////////////////// + // Get users default time zone + // + getTimeZoneName() { + return Intl.DateTimeFormat().resolvedOptions().timeZone; + }, //////////////////////////////////////////////////////// // dynamically set the vuetify language elements from // users localized text (am/pm etc) diff --git a/ayanova/src/main.js b/ayanova/src/main.js index 84253e51..4ed46e15 100644 --- a/ayanova/src/main.js +++ b/ayanova/src/main.js @@ -157,35 +157,28 @@ Vue.filter( var parsedDate = new Date(value); //parsedDate now contains the correct value //but any attempt to get it back out that isn't a UTC function will automatically convert to local perceived time zone - - var tzAdjustedDate = new Date(); - tzAdjustedDate.setTime( - parsedDate.getTime() + locale.format().timeZoneOffset * 60 * 60 * 1000 - ); - // var localizedDate = dayjs - // .utc(value) - // .add(locale.format().timeZoneOffset, "hour") - // .toDate(); + // DATE.toLocaleString('en-GB', { timeZone: 'UTC', dateStyle: "short",timeStyle: "short", hour12: false }) - var ret = tzAdjustedDate.toLocaleString( + var ret = parsedDate.toLocaleString( window.$gz.locale.getBrowserLanguages(), { + timeZone: locale.getTimeZoneName(), dateStyle: "short", timeStyle: "short", hour12: locale.format().hour12 } ); - console.log("value"); - console.log(value); - console.log("parsedDate"); - console.log(parsedDate); - console.log("tzAdjustedDate"); - console.log(tzAdjustedDate); - console.log("presented as:"); - console.log(ret); - console.log("-------"); + // console.log("value"); + // console.log(value); + // console.log("parsedDate"); + // console.log(parsedDate); + // console.log("tzAdjustedDate"); + // console.log(tzAdjustedDate); + // console.log("presented as:"); + // console.log(ret); + // console.log("-------"); //debugger; return ret;