FIX: infers time from tz creator to ensure day shown is the one expected
This commit is contained in:
parent
f3b17b92b7
commit
c580a39d49
|
@ -11,7 +11,10 @@
|
|||
clearTimeout(this.timeout);
|
||||
}
|
||||
|
||||
var relativeTime = moment.utc(options.date + " " + options.time, "YYYY-MM-DD HH:mm");
|
||||
var relativeTime = moment.utc(
|
||||
options.date + " " + options.time,
|
||||
"YYYY-MM-DD HH:mm"
|
||||
);
|
||||
|
||||
if (options.recurring && relativeTime < moment().utc()) {
|
||||
var parts = options.recurring.split(".");
|
||||
|
@ -24,7 +27,7 @@
|
|||
}
|
||||
|
||||
var previews = options.timezones.split("|").map(function(timezone) {
|
||||
var dateTime = relativeTime.tz(timezone).format(options.format);
|
||||
var dateTime = relativeTime.tz(timezone).format("LLL");
|
||||
var timezoneParts = _formatTimezone(timezone);
|
||||
|
||||
if (dateTime.match(/TZ/)) {
|
||||
|
@ -43,10 +46,13 @@
|
|||
|
||||
var html = "<span>";
|
||||
html += "<i class='fa fa-globe d-icon d-icon-globe'></i>";
|
||||
html += relativeTime.replace("TZ", _formatTimezone(moment.tz.guess()).join(": "));
|
||||
html += relativeTime.replace(
|
||||
"TZ",
|
||||
_formatTimezone(moment.tz.guess()).join(": ")
|
||||
);
|
||||
html += "</span>";
|
||||
|
||||
var joinedPreviews = previews.join("\n");
|
||||
var joinedPreviews = previews.join(" – ");
|
||||
|
||||
$element
|
||||
.html(html)
|
||||
|
|
|
@ -28,7 +28,9 @@ export default Ember.Component.extend({
|
|||
);
|
||||
this.set(
|
||||
"formats",
|
||||
(this.siteSettings.discourse_local_dates_default_formats || "").split("|")
|
||||
(this.siteSettings.discourse_local_dates_default_formats || "")
|
||||
.split("|")
|
||||
.filter(f => f)
|
||||
);
|
||||
},
|
||||
|
||||
|
@ -94,20 +96,28 @@ export default Ember.Component.extend({
|
|||
const recurring = this.get("recurring");
|
||||
const format = this.get("format");
|
||||
const timezones = this.get("timezones");
|
||||
const timeInferred = time ? false : true;
|
||||
const toTimeInferred = toTime ? false : true;
|
||||
|
||||
let dateTime;
|
||||
|
||||
if (time) {
|
||||
dateTime = moment(`${date} ${time}`, this.dateTimeFormat).utc();
|
||||
if (!timeInferred) {
|
||||
dateTime = moment
|
||||
.tz(`${date} ${time}`, this.get("currentUserTimezone"))
|
||||
.utc();
|
||||
} else {
|
||||
dateTime = moment(date, this.dateFormat).startOf("day");
|
||||
dateTime = moment.tz(date, this.get("currentUserTimezone")).utc();
|
||||
}
|
||||
|
||||
let toDateTime;
|
||||
if (toTime) {
|
||||
toDateTime = moment(`${toDate} ${toTime}`, this.dateTimeFormat).utc();
|
||||
if (!toTimeInferred) {
|
||||
toDateTime = moment
|
||||
.tz(`${toDate} ${toTime}`, this.get("currentUserTimezone"))
|
||||
.utc();
|
||||
} else {
|
||||
toDateTime = moment(toDate, this.dateFormat).endOf("day");
|
||||
toDateTime = moment
|
||||
.tz(toDate, this.get("currentUserTimezone"))
|
||||
.endOf("day")
|
||||
.utc();
|
||||
}
|
||||
|
||||
let config = {
|
||||
|
@ -118,19 +128,18 @@ export default Ember.Component.extend({
|
|||
timezones
|
||||
};
|
||||
|
||||
if (time) {
|
||||
config.time = dateTime.format(this.timeFormat);
|
||||
}
|
||||
config.time = dateTime.format(this.timeFormat);
|
||||
config.toTime = toDateTime.format(this.timeFormat);
|
||||
|
||||
if (toDate) {
|
||||
config.toDate = toDateTime.format(this.dateFormat);
|
||||
}
|
||||
|
||||
if (toTime) {
|
||||
config.toTime = toDateTime.format(this.timeFormat);
|
||||
}
|
||||
|
||||
if (!time && !toTime && this.get("formats").includes(format)) {
|
||||
if (
|
||||
timeInferred &&
|
||||
toTimeInferred &&
|
||||
this.get("formats").includes(format)
|
||||
) {
|
||||
config.format = "LL";
|
||||
}
|
||||
|
||||
|
@ -139,8 +148,8 @@ export default Ember.Component.extend({
|
|||
}
|
||||
|
||||
if (
|
||||
time &&
|
||||
toTime &&
|
||||
!timeInferred &&
|
||||
!toTimeInferred &&
|
||||
date === moment().format(this.dateFormat) &&
|
||||
date === toDate &&
|
||||
this.get("formats").includes(format)
|
||||
|
|
Loading…
Reference in New Issue