This commit is contained in:
2021-09-16 19:39:14 +00:00
parent 5b1e115d46
commit 04c83e19f4
2 changed files with 97 additions and 22 deletions

View File

@@ -76,30 +76,82 @@ export default {
return window.$gz.store.state.userOptions.hour12; return window.$gz.store.state.userOptions.hour12;
}, },
// /////////////////////////////////////////// ///////////////////////////////////////////
// // Convert timestamp utc epoch value // Turn a utc date into a vueitfy calendar
// // to local timestamp epoch value // schedule control compatible format
// // // localized:
// utcEpochToLocalEpoch(value, timeZoneName) { //
// if (!value) { // "It must be a Date, number of seconds since Epoch, or a string in the format of YYYY-MM-DD or YYYY-MM-DD hh:mm. Zero-padding is optional and seconds are ignored.""
// return null; //
// } //
// if (!timeZoneName) { utcDateToScheduleCompatibleFormatLocalized(
// timeZoneName = this.getResolvedTimeZoneName(); value,
// } timeZoneName,
languageName,
hour12
) {
if (!value) {
return "";
}
if (!timeZoneName) {
timeZoneName = this.getResolvedTimeZoneName();
}
if (!languageName) {
languageName = this.getResolvedLanguage();
}
// let parsedDate = new Date(value); if (!hour12) {
hour12 = this.getHour12();
}
// //is it a valid date? //parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z")
// if (!(parsedDate instanceof Date && !isNaN(parsedDate))) { let parsedDate = new Date(value);
// return null;
// }
// return parsedDate.toLocaleDateString(languageName, { //is it a valid date?
// timeZone: timeZoneName, if (!(parsedDate instanceof Date && !isNaN(parsedDate))) {
// dateStyle: "short" return null;
// }); }
// },
//return this:
//YYYY-MM-DD hh:mm
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/formatToParts
let formatter = new Intl.DateTimeFormat(languageName, {
year: "numeric",
month: "numeric",
day: "numeric",
hour: "numeric",
minute: "numeric",
hour12: false,
timeZone: timeZoneName
});
const parts = formatter.formatToParts(parsedDate);
//console.log(parts);
let p = { year: null, month: null, day: null, hour: null, minute: null };
parts.forEach(x => {
switch (x.type) {
case "year":
case "relatedYear":
p.year = x.value;
break;
case "month":
p.month = x.value;
break;
case "day":
p.day = x.value;
break;
case "hour":
p.hour = x.value;
break;
case "minute":
p.minute = x.value;
break;
}
});
return `${p.year}-${p.month}-${p.day} ${p.hour}:${p.minute}`;
},
/////////////////////////////////////////// ///////////////////////////////////////////
// Turn a utc date into a displayable // Turn a utc date into a displayable
// short date and time // short date and time

View File

@@ -390,7 +390,30 @@ export default {
this.formState.serverError = res.error; this.formState.serverError = res.error;
window.$gz.form.setErrorBoxErrors(this); window.$gz.form.setErrorBoxErrors(this);
} else { } else {
this.events = res.data; console.log("fetch raw data:", JSON.stringify(res.data));
this.events = res.data.map(x => {
return {
...x,
start: window.$gz.locale.utcDateToScheduleCompatibleFormatLocalized(
x.start,
this.timeZoneName,
this.languageName,
this.hour12
),
end: window.$gz.locale.utcDateToScheduleCompatibleFormatLocalized(
x.end,
this.timeZoneName,
this.languageName,
this.hour12
)
};
});
console.log(
"fetch events data after processing:",
JSON.stringify(this.events)
);
} }
} catch (error) { } catch (error) {
window.$gz.errorHandler.handleFormError(error, this); window.$gz.errorHandler.handleFormError(error, this);