Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -594,36 +594,41 @@
"gnGlobalSettings",
function (gnGlobalSettings) {
return function (date, format, contextAllowToUseFromNow) {
function isDateGmlFormat(date) {
return date.match("[Zz]$") !== null;
}
var settingAllowToUseFromNow = gnGlobalSettings.gnCfg.mods.global.humanizeDates,
timezone = gnGlobalSettings.gnCfg.mods.global.timezone;
const isDateGmlFormat = /[Zz]$/.test(date);
Comment thread
PascalLike marked this conversation as resolved.
Outdated
const isDateTimeFormat = date.includes("T");
var settingAllowToUseFromNow = gnGlobalSettings.gnCfg.mods.global.humanizeDates;
var timezone = gnGlobalSettings.gnCfg.mods.global.timezone;
var parsedDate = null;
if (isDateGmlFormat(date)) {

if (isDateGmlFormat) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this if statement is required.

YYYY-MM-DDtHH-mm-SSSZ is not valid anyways. I think moment(date) should work fine in both cases?

parsedDate = moment(date, "YYYY-MM-DDtHH-mm-SSSZ");
} else {
} else if (isDateTimeFormat) {
parsedDate = moment(date);
} else {
parsedDate = moment.utc(date); // Date only
}

if (parsedDate.isValid()) {
if (!!timezone) {
parsedDate = parsedDate.tz(
timezone === "Browser" ? moment.tz.guess() : timezone
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The revision date with the recommended/browser timezone should not display as the previous day:

It seems that daylight savings is causing issues here. The editor guesses the timezone is -4 (EDT) correctly but then gnHumanizeTimeService guesses the timezone is -5 (EST) shifting to the previous day. Maybe this should be consistent with how the date input in the editor guesses the timezone?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

by default gnHumanizeTimeService uses JVM timezone, but time zones definitions can change frequently and need to be updated.
An alternative may be to set a fixed Timezone in the settings, setting it to "Browser", to use the one from the browser (like in the editor) or another fixed value.

);
}
var fromNow = parsedDate.fromNow();

if (date.length === 4) {
format = "YYYY";
}
format = "YYYY"; // Year only format
} // Otherwise defaults to the format provided as input

var fromNow = parsedDate.fromNow();

if (settingAllowToUseFromNow && contextAllowToUseFromNow) {
return {
value: fromNow,
title: format ? parsedDate.format(format) : parsedDate.toString()
title: format ? parsedDate.format(format) : parsedDate.toString(),
value: fromNow
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change intentional? It is not changing any logic. Only the order.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for readability

};
} else {
return {
title: fromNow,
title: isDateTimeFormat ? parsedDate.toString() : fromNow,
Comment thread
PascalLike marked this conversation as resolved.
Outdated
value: format ? parsedDate.format(format) : parsedDate.toString()
};
}
Expand Down
Loading