This commit is contained in:
2020-02-06 23:50:06 +00:00
parent fe206f5c87
commit 6ac4bf58fe
2 changed files with 33 additions and 34 deletions

View File

@@ -338,6 +338,23 @@ export default {
});
}
},
///////////////////////////////////////////////
// Convert a local time only string with date string
// to UTC and output as ISO 8601
// (used by time and date picker components)
//
localTimeDateStringToUTC8601String(value, timeZoneName) {
//https://moment.github.io/luxon/docs/manual/zones.html#creating-datetimes-in-a-zone
if (!timeZoneName) {
timeZoneName = this.getTimeZoneName();
}
//parse in the time in the currently used timezone
return window.$gz.DateTime.fromISO(value, {
zone: this.timeZoneName
})
.setZone("utc") //convert to UTC
.toISO(); //output as ISO 8601
},
////////////////////////////////////////////////////////
// dynamically set the vuetify language elements from
// users localized text (am/pm etc)

View File

@@ -204,45 +204,27 @@ export default {
}
},
timeOnly: {
//The control needs this value in ISO 8601 format but adjusted to user time zone
//------------originally
// get() {
// var defaultTimeString = window.$gz.dayjs
// .utc()
// .add(window.$gz.locale.format().timeZoneOffset, "hour")
// .format("HH:mm:ss");
// return this.value
// ? window.$gz.dayjs
// .utc(this.value)
// .add(window.$gz.locale.format().timeZoneOffset, "hour")
// .format("HH:mm:ss")
// : defaultTimeString;
// },
// set(value) {
// this.date = window.$gz.dayjs
// .utc(this.dateOnly + " " + value)
// .subtract(window.$gz.locale.format().timeZoneOffset, "hour")
// .toISOString();
// }
//-----------------
//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"}));
//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(this.value);
return window.$gz.locale.utcDateStringTo8601TimeOnlyString(
this.value,
this.timeZoneName
);
},
set(value) {
//https://moment.github.io/luxon/docs/manual/zones.html#creating-datetimes-in-a-zone
this.date = window.$gz.locale.localTimeDateStringToUTC8601String(
this.dateOnly + "T" + value,
this.timeZoneName
);
// //https://moment.github.io/luxon/docs/manual/zones.html#creating-datetimes-in-a-zone
//parse in the time in the currently used timezone
this.date = window.$gz.DateTime.fromISO(this.dateOnly + "T" + value, {
zone: this.timeZoneName
})
.setZone("utc") //convert to UTC
.toISO(); //output as ISO 8601
// //parse in the time in the currently used timezone
// this.date = window.$gz.DateTime.fromISO(this.dateOnly + "T" + value, {
// zone: this.timeZoneName
// })
// .setZone("utc") //convert to UTC
// .toISO(); //output as ISO 8601
}
}
}