diff --git a/ayanova/src/api/locale.js b/ayanova/src/api/locale.js index 36a377b5..12796379 100644 --- a/ayanova/src/api/locale.js +++ b/ayanova/src/api/locale.js @@ -322,7 +322,7 @@ export default { // and return time portion only in iso 8601 // format (used by time and date picker components) // - utcDateStringTo8601TimeOnlyString(value, timeZoneName) { + utcDateStringToLocal8601TimeOnlyString(value, timeZoneName) { if (!value) { //if no value, return the current time as expected by the time picker } else { @@ -355,6 +355,27 @@ export default { .setZone("utc") //convert to UTC .toISO(); //output as ISO 8601 }, + /////////////////////////////////////////////// + // Convert a utc date to local time zone + // and return date only portion only in iso 8601 + // format (used by time and date picker components) + // + utcDateStringToLocal8601DateOnlyString(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).toLocaleDateString("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 3b0f4aeb..c19d9a3b 100644 --- a/ayanova/src/components/date-time-control.vue +++ b/ayanova/src/components/date-time-control.vue @@ -181,33 +181,52 @@ export default { // : ""; }, dateOnly: { - get() { - //TODO: this will likely need an improvement for forms where there should be an automatic pre-set time chosen like workorder labor; - var defaultDateString = window.$gz - .dayjs() - .utc() - .add(window.$gz.locale.format().timeZoneOffset, "hour") - .format("YYYY-MM-DD"); + //---------------------------- + // get() { + // //TODO: this will likely need an improvement for forms where there should be an automatic pre-set time chosen like workorder labor; + // var defaultDateString = window.$gz + // .dayjs() + // .utc() + // .add(window.$gz.locale.format().timeZoneOffset, "hour") + // .format("YYYY-MM-DD"); - return this.value - ? window.$gz.dayjs - .utc(this.value) - .add(window.$gz.locale.format().timeZoneOffset, "hour") - .format("YYYY-MM-DD") - : defaultDateString; + // return this.value + // ? window.$gz.dayjs + // .utc(this.value) + // .add(window.$gz.locale.format().timeZoneOffset, "hour") + // .format("YYYY-MM-DD") + // : defaultDateString; + // }, + // set(value) { + // this.date = window.$gz.dayjs + // .utc(value + " " + this.timeOnly) + // .subtract(window.$gz.locale.format().timeZoneOffset, "hour") + // .toISOString(); + // } + //--------------------------- + get() { + //TODO: return date only portion converted to local working time zone: YYYY-MM-DD + + var v = window.$gz.locale.utcDateStringToLocal8601DateOnlyString( + this.value, + this.timeZoneName + ); + console.log(this.value); + console.log(v); + return v; }, set(value) { - this.date = window.$gz.dayjs - .utc(value + " " + this.timeOnly) - .subtract(window.$gz.locale.format().timeZoneOffset, "hour") - .toISOString(); + this.date = window.$gz.locale.localTimeDateStringToUTC8601String( + value + "T" + this.timeOnly, + this.timeZoneName + ); } }, timeOnly: { //expects just the hours minutes seconds portion: 18:18:49 //Needs to convert into and out of the desired time zone or the control will show the UTC time instead get() { - return window.$gz.locale.utcDateStringTo8601TimeOnlyString( + return window.$gz.locale.utcDateStringToLocal8601TimeOnlyString( this.value, this.timeZoneName );