-
-
Notifications
You must be signed in to change notification settings - Fork 505
Do not set humanized date when not set #9189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -594,36 +594,39 @@ | |
| "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; | ||
| var isDateGmlFormat = /[Zz]$/.test(date); | ||
| var 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) { | ||
| parsedDate = moment(date, "YYYY-MM-DDtHH-mm-SSSZ"); | ||
| } else { | ||
| parsedDate = moment(date); | ||
| } | ||
|
|
||
| if (parsedDate.isValid()) { | ||
| if (!!timezone) { | ||
| if (!!timezone && isDateTimeFormat) { | ||
| parsedDate = parsedDate.tz( | ||
| timezone === "Browser" ? moment.tz.guess() : timezone | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| ); | ||
| } | ||
| 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for readability |
||
| }; | ||
| } else { | ||
| return { | ||
| title: fromNow, | ||
| title: settingAllowToUseFromNow ? fromNow : date, | ||
| value: format ? parsedDate.format(format) : parsedDate.toString() | ||
| }; | ||
| } | ||
|
|
||

There was a problem hiding this comment.
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-SSSZis not valid anyways. I thinkmoment(date)should work fine in both cases?