mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
c4d16d5d67
Bumped all non-ember-core dependencies that do not require significant work or that contain unresolvable inter-dependencies. Skipped: - `ember-drag-drop` - our usage needs re-working for closure actions - `ember-infinity`, `ember-in-viewport` - one depends on the other and `ember-light-table` depends on a particular version of `ember-in-viewport` in a way that breaks if they are upgraded Removed/bumped: - removed ember-cli-es6-transform - removed ember-cli-cjs-transform - removed current-device - removed ember-responsive - bumped yarn.lock sub-dependencies - bumped @ember/jquery - bumped @tryghost/mobiledoc-kit - bumped autoprefixer - bumped broccoli-funnel - bumped coveralls - bumped ember-auto-import - bumped ember-moment - bumped ember-power-select - bumped ember-simple-auth - bumped broccoli-uglify-sourcemap - bumped ember-cli-eslint and eslint-plugin-ghost with fixes for new rules - bumped ember-cli-mirage - bumped ember-cli-pretender - bumped ember-power-calendar-moment - bumped ember-power-datepicker - bumped ember-composable-helpers - bumped ember-concurrency - bumped ember-load - bumped eslint - bumped walk-sync - bumped ember-useragent - bumped fs-extra - bumped ember-resolver - bumped @html-next/vertical-collection - bumped ember-cli-babel
50 lines
1.9 KiB
JavaScript
50 lines
1.9 KiB
JavaScript
import Helper from '@ember/component/helper';
|
|
import moment from 'moment';
|
|
import {assert} from '@ember/debug';
|
|
import {inject as service} from '@ember/service';
|
|
|
|
export default Helper.extend({
|
|
settings: service(),
|
|
|
|
compute([timeago], {draft, scheduled, published}) {
|
|
assert('You must pass a time to the gh-format-post-time helper', timeago);
|
|
|
|
if (draft) {
|
|
// No special handling for drafts, just use moment.from
|
|
return moment(timeago).from(moment.utc());
|
|
}
|
|
|
|
let timezone = this.get('settings.activeTimezone');
|
|
let time = moment.tz(timeago, timezone);
|
|
let now = moment.tz(moment.utc(), timezone);
|
|
|
|
// If not a draft and post was published <= 15 minutes ago
|
|
// or scheduled to be published <= 15 minutes from now, use moment.from
|
|
if (Math.abs(now.diff(time, 'minutes')) <= 15) {
|
|
return time.from(now);
|
|
}
|
|
|
|
// If scheduled for or published on the same day, render the time + Today
|
|
if (time.isSame(now, 'day')) {
|
|
let formatted = time.format('HH:mm [Today]');
|
|
return scheduled ? `at ${formatted}` : formatted;
|
|
}
|
|
|
|
// if published yesterday, render time + yesterday
|
|
// This check comes before scheduled, because there are likely to be more published
|
|
// posts than scheduled posts.
|
|
if (published && time.isSame(now.clone().subtract(1, 'days').startOf('day'), 'day')) {
|
|
return time.format('HH:mm [Yesterday]');
|
|
}
|
|
|
|
// if scheduled for tomorrow, render the time + Tomorrow
|
|
if (scheduled && time.isSame(now.clone().add(1, 'days').startOf('day'), 'day')) {
|
|
return time.format('[at] HH:mm [Tomorrow]');
|
|
}
|
|
|
|
// Else, render just the date if published, or the time & date if scheduled
|
|
let format = scheduled ? '[at] HH:mm [on] DD MMM YYYY' : 'DD MMM YYYY';
|
|
return time.format(format);
|
|
}
|
|
});
|