This commit is contained in:
@@ -79,82 +79,27 @@ export default {
|
||||
///////////////////////////////////////////
|
||||
// Turn a utc date into a vueitfy calendar
|
||||
// schedule control compatible format
|
||||
// localized:
|
||||
//
|
||||
// localized.
|
||||
// For ease of use in schedule the epoch (milliseconds) is the best format
|
||||
// "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.""
|
||||
//
|
||||
//
|
||||
utcDateToScheduleCompatibleFormatLocalized(
|
||||
value,
|
||||
timeZoneName,
|
||||
languageName,
|
||||
hour12
|
||||
) {
|
||||
utcDateToScheduleCompatibleFormatLocalized(value, timeZoneName) {
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
if (!timeZoneName) {
|
||||
timeZoneName = this.getResolvedTimeZoneName();
|
||||
}
|
||||
if (!languageName) {
|
||||
languageName = this.getResolvedLanguage();
|
||||
}
|
||||
|
||||
if (!hour12) {
|
||||
hour12 = this.getHour12();
|
||||
}
|
||||
|
||||
//parse the date which is identified as utc ("2020-02-06T18:18:49.148011Z")
|
||||
let parsedDate = new Date(value);
|
||||
|
||||
//is it a valid date?
|
||||
if (!(parsedDate instanceof Date && !isNaN(parsedDate))) {
|
||||
if (window.$gz.dev) {
|
||||
throw new Error(
|
||||
`locale::utcDateToScheduleCompatibleFormatLocalized - Value '${value}' is not parseable`
|
||||
`locale::utcDateToScheduleCompatibleFormatLocalized - Value is empty`
|
||||
);
|
||||
}
|
||||
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);
|
||||
|
||||
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}`;
|
||||
return new Date(
|
||||
//sv-SE is iso-8601 format so cleanest to parse accurately
|
||||
new Date(value).toLocaleString("sv-SE", {
|
||||
timeZone: timeZoneName
|
||||
})
|
||||
).getTime();
|
||||
},
|
||||
///////////////////////////////////////////
|
||||
// Turn a utc date into a displayable
|
||||
|
||||
Reference in New Issue
Block a user