Added UTC offset to scheduled editor status text

refs https://github.com/TryGhost/Ghost/issues/11965

- updated the `{{gh-format-post-time}}` helper that is used in editor status and in post settings menu email sub-menu for displaying email sent time
This commit is contained in:
Kevin Ansfield 2020-07-01 18:57:36 +01:00
parent ec925a60b0
commit 8f8fcfc8bb
2 changed files with 16 additions and 9 deletions

View File

@ -12,6 +12,13 @@ export function formatPostTime(timeago, {timezone = 'ect/UTC', draft, scheduled,
let time = moment.tz(timeago, timezone);
let now = moment.tz(moment.utc(), timezone);
let utcOffset;
if (time.utcOffset() === 0) {
utcOffset = '(UTC)';
} else {
utcOffset = `(UTC${time.format('Z').replace(/([+-])0/, '$1').replace(/:00/, '')})`;
}
// If not a draft and 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) {
@ -20,7 +27,7 @@ export function formatPostTime(timeago, {timezone = 'ect/UTC', draft, scheduled,
// 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]');
let formatted = time.format(`HH:mm [${utcOffset}] [Today]`);
return scheduled ? `at ${formatted}` : formatted;
}
@ -28,16 +35,16 @@ export function formatPostTime(timeago, {timezone = 'ect/UTC', draft, scheduled,
// 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]');
return time.format(`HH:mm [${utcOffset}] [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]');
return time.format(`[at] HH:mm [${utcOffset}] [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';
let format = scheduled ? `[at] HH:mm [${utcOffset}] [on] DD MMM YYYY` : 'DD MMM YYYY';
return time.format(format);
}

View File

@ -71,7 +71,7 @@ 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} Today`);
expect(this.element).to.have.trimmed.text(`${expectedTime} (UTC) Today`);
});
it('returns correct format if post is scheduled for the same day', async function () {
@ -83,7 +83,7 @@ describe('Integration: Helper: gh-format-post-time', function () {
this.set('mockDate', mockDate);
await render(hbs`{{gh-format-post-time mockDate scheduled=true}}`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} Today`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} (UTC) Today`);
});
it('returns correct format if post was published yesterday', async function () {
@ -94,7 +94,7 @@ 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} Yesterday`);
expect(this.element).to.have.trimmed.text(`${expectedTime} (UTC) Yesterday`);
});
it('returns correct format if post is scheduled for tomorrow', async function () {
@ -105,7 +105,7 @@ describe('Integration: Helper: gh-format-post-time', function () {
this.set('mockDate', mockDate);
await render(hbs`{{gh-format-post-time mockDate scheduled=true}}`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} Tomorrow`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} (UTC) Tomorrow`);
});
it('returns correct format if post was published prior to yesterday', async function () {
@ -127,6 +127,6 @@ describe('Integration: Helper: gh-format-post-time', function () {
this.set('mockDate', mockDate);
await render(hbs`{{gh-format-post-time mockDate scheduled=true}}`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} on 10 Sep 2017`);
expect(this.element).to.have.trimmed.text(`at ${expectedTime} (UTC) on 10 Sep 2017`);
});
});