diff --git a/ghost/admin/app/components/editor/modals/publish-flow/options.hbs b/ghost/admin/app/components/editor/modals/publish-flow/options.hbs index 42dd5d2852..3be1d3d097 100644 --- a/ghost/admin/app/components/editor/modals/publish-flow/options.hbs +++ b/ghost/admin/app/components/editor/modals/publish-flow/options.hbs @@ -129,7 +129,7 @@
{{#if @publishOptions.isScheduled}} - {{capitalize (gh-format-post-time @publishOptions.scheduledAtUTC draft=true)}} + {{capitalize (gh-format-post-time @publishOptions.scheduledAtUTC relative=true)}} {{else}} Right now {{/if}} diff --git a/ghost/admin/app/components/posts-list/list-item.hbs b/ghost/admin/app/components/posts-list/list-item.hbs index a3a21b58db..e588189a58 100644 --- a/ghost/admin/app/components/posts-list/list-item.hbs +++ b/ghost/admin/app/components/posts-list/list-item.hbs @@ -22,13 +22,15 @@ - - - {{#if this.isHovered}} - {{gh-format-post-time @post.updatedAtUTC format="D MMM YYYY"}} - {{else}} - {{gh-format-post-time @post.updatedAtUTC draft=true}} - {{/if}} - + {{#if (or @post.isDraft @post.isScheduled)}} + + {{gh-format-post-time @post.updatedAtUTC absolute=true short=true}} + + {{else}} + + {{gh-format-post-time @post.publishedAtUTC absolute=true short=true}} + + {{/if}}

@@ -72,12 +74,15 @@ {{/if}} - - + {{#if (or @post.isDraft @post.isScheduled)}} + + {{else}} + + {{/if}} {{!-- {{#if @post.lexical}} {{/if}} --}} diff --git a/ghost/admin/app/helpers/gh-format-post-time.js b/ghost/admin/app/helpers/gh-format-post-time.js index c9f4c108ee..84a9a58f89 100644 --- a/ghost/admin/app/helpers/gh-format-post-time.js +++ b/ghost/admin/app/helpers/gh-format-post-time.js @@ -3,9 +3,9 @@ import moment from 'moment-timezone'; import {assert} from '@ember/debug'; import {inject as service} from '@ember/service'; -export function formatPostTime(timeago, {timezone = 'etc/UTC', format, draft, scheduled, published}) { - if (draft) { - // No special handling for drafts, just use moment.from +export function formatPostTime(timeago, {timezone = 'etc/UTC', format, relative, absolute, scheduled, short}) { + if (relative) { + // No special handling, just use moment.from return moment(timeago).from(moment.utc()); } @@ -24,7 +24,8 @@ export function formatPostTime(timeago, {timezone = 'etc/UTC', format, draft, sc utcOffset = `(UTC${time.format('Z').replace(/([+-])0/, '$1').replace(/:00/, '')})`; } - // If not a draft and post was published <= 12 hours ago + // If draft was edited <= 12 hours ago + // or post was published <= 12 hours ago // or scheduled to be published <= 12 hours from now, use moment.from if (Math.abs(now.diff(time, 'hours')) <= 12) { return time.from(now); @@ -36,11 +37,16 @@ export function formatPostTime(timeago, {timezone = 'etc/UTC', format, draft, sc return scheduled ? `at ${formatted}` : formatted; } - // if published yesterday, render time + yesterday + // if draft was edited yesterday, render time + yesterday + // if post was published yesterday, render time + yesterday + // if short format, just render Yesterday (without time) // 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 [${utcOffset}] [Yesterday]`); + if (absolute && time.isSame(now.clone().subtract(1, 'days').startOf('day'), 'day')) { + if (short) { + return time.format(`[Yesterday]`); + } + return time.format(`HH:mm [${utcOffset}] [yesterday]`); } // if scheduled for tomorrow, render the time + tomorrow @@ -48,7 +54,7 @@ export function formatPostTime(timeago, {timezone = 'etc/UTC', format, draft, sc return time.format(`[at] HH:mm [${utcOffset}] [tomorrow]`); } - // Else, render just the date if published, or the time & date if scheduled + // Else, render just the date if edited or published, or the time & date if scheduled let f = scheduled ? `[at] HH:mm [${utcOffset}] [on] DD MMM YYYY` : 'DD MMM YYYY'; return time.format(f); } diff --git a/ghost/admin/tests/integration/helpers/gh-format-post-time-test.js b/ghost/admin/tests/integration/helpers/gh-format-post-time-test.js index 26ac760a12..9495280e78 100644 --- a/ghost/admin/tests/integration/helpers/gh-format-post-time-test.js +++ b/ghost/admin/tests/integration/helpers/gh-format-post-time-test.js @@ -42,7 +42,7 @@ describe('Integration: Helper: gh-format-post-time', function () { let mockDate = moment.utc().subtract(1, 'hour'); this.set('mockDate', mockDate); - await render(hbs`{{gh-format-post-time mockDate draft=true}}`); + await render(hbs`{{gh-format-post-time mockDate relative=true}}`); expect(this.element).to.have.trimmed.text('an hour ago'); }); @@ -50,7 +50,7 @@ describe('Integration: Helper: gh-format-post-time', function () { let mockDate = moment.utc().subtract(13, 'minutes'); this.set('mockDate', mockDate); - await render(hbs`{{gh-format-post-time mockDate published=true}}`); + await render(hbs`{{gh-format-post-time mockDate absolute=true}}`); expect(this.element).to.have.trimmed.text('13 minutes ago'); }); @@ -70,7 +70,7 @@ describe('Integration: Helper: gh-format-post-time', function () { }); this.set('mockDate', mockDate); - await render(hbs`{{gh-format-post-time mockDate published=true}}`); + await render(hbs`{{gh-format-post-time mockDate absolute=true}}`); expect(this.element).to.have.trimmed.text(`${expectedTime} (UTC) Today`); }); @@ -93,8 +93,19 @@ describe('Integration: Helper: gh-format-post-time', function () { }); this.set('mockDate', mockDate); - await render(hbs`{{gh-format-post-time mockDate published=true}}`); - expect(this.element).to.have.trimmed.text(`${expectedTime} (UTC) Yesterday`); + await render(hbs`{{gh-format-post-time mockDate absolute=true}}`); + expect(this.element).to.have.trimmed.text(`${expectedTime} (UTC) yesterday`); + }); + + it('returns correct short format if post was published yesterday', async function () { + let {mockDate} = setupMockDate({ + date: '2017-09-05T16:00:00Z', + utcDate: '2017-09-06T18:00:00Z' + }); + this.set('mockDate', mockDate); + + await render(hbs`{{gh-format-post-time mockDate absolute=true short=true}}`); + expect(this.element).to.have.trimmed.text(`Yesterday`); }); it('returns correct format if post is scheduled for tomorrow', async function () { @@ -115,7 +126,7 @@ describe('Integration: Helper: gh-format-post-time', function () { }); this.set('mockDate', mockDate); - await render(hbs`{{gh-format-post-time mockDate published=true}}`); + await render(hbs`{{gh-format-post-time mockDate absolute=true}}`); expect(this.element).to.have.trimmed.text('02 Sep 2017'); });