mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed gh-format-post-time not showing hours when time is <12 hours away
refs https://github.com/TryGhost/Ghost/issues/11965 - changed to native class syntax - extracted main method out so that it can be used outside of templates - switched the "in x hours" logic to use moment's `.from()` method when time is within 12 hours rather than 15 minutes
This commit is contained in:
parent
07ac30076a
commit
eacf8a72d8
1 changed files with 43 additions and 40 deletions
|
@ -3,24 +3,18 @@ import moment from 'moment';
|
||||||
import {assert} from '@ember/debug';
|
import {assert} from '@ember/debug';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
|
|
||||||
export default Helper.extend({
|
export function formatPostTime(timeago, {timezone = 'ect/UTC', draft, scheduled, published}) {
|
||||||
settings: service(),
|
|
||||||
|
|
||||||
compute([timeago], {draft, scheduled, published}) {
|
|
||||||
assert('You must pass a time to the gh-format-post-time helper', timeago);
|
|
||||||
|
|
||||||
if (draft) {
|
if (draft) {
|
||||||
// No special handling for drafts, just use moment.from
|
// No special handling for drafts, just use moment.from
|
||||||
return moment(timeago).from(moment.utc());
|
return moment(timeago).from(moment.utc());
|
||||||
}
|
}
|
||||||
|
|
||||||
let timezone = this.get('settings.timezone');
|
|
||||||
let time = moment.tz(timeago, timezone);
|
let time = moment.tz(timeago, timezone);
|
||||||
let now = moment.tz(moment.utc(), timezone);
|
let now = moment.tz(moment.utc(), timezone);
|
||||||
|
|
||||||
// If not a draft and post was published <= 15 minutes ago
|
// If not a draft and post was published <= 12 hours ago
|
||||||
// or scheduled to be published <= 15 minutes from now, use moment.from
|
// or scheduled to be published <= 12 hours from now, use moment.from
|
||||||
if (Math.abs(now.diff(time, 'minutes')) <= 15) {
|
if (Math.abs(now.diff(time, 'hours')) <= 12) {
|
||||||
return time.from(now);
|
return time.from(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,4 +40,13 @@ export default Helper.extend({
|
||||||
let format = scheduled ? '[at] HH:mm [on] DD MMM YYYY' : 'DD MMM YYYY';
|
let format = scheduled ? '[at] HH:mm [on] DD MMM YYYY' : 'DD MMM YYYY';
|
||||||
return time.format(format);
|
return time.format(format);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
export default class GhFormatPostTimeHelper extends Helper {
|
||||||
|
@service settings;
|
||||||
|
|
||||||
|
compute([timeago], options) {
|
||||||
|
assert('You must pass a time to the gh-format-post-time helper', timeago);
|
||||||
|
|
||||||
|
return formatPostTime(timeago, Object.assign({}, options, {timezone: this.settings.get('timezone')}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue