From b2a2e4f1e5d03d8f1e7d9bfd4841543f0aee65ea Mon Sep 17 00:00:00 2001 From: Joffrey JAFFEUX Date: Mon, 6 Jul 2020 09:26:31 +0200 Subject: [PATCH] FIX: ensures seconds are displayed when used with dates (#10170) --- .../javascripts/lib/local-date-builder.js.es6 | 3 ++- .../lib/local-date-builder-test.js.es6 | 21 +++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/discourse-local-dates/assets/javascripts/lib/local-date-builder.js.es6 b/plugins/discourse-local-dates/assets/javascripts/lib/local-date-builder.js.es6 index 63a9a884789..0ce3ff8b5fc 100644 --- a/plugins/discourse-local-dates/assets/javascripts/lib/local-date-builder.js.es6 +++ b/plugins/discourse-local-dates/assets/javascripts/lib/local-date-builder.js.es6 @@ -24,7 +24,7 @@ export default class LocalDateBuilder { build() { const [year, month, day] = this.date.split("-").map(x => parseInt(x, 10)); - const [hour, minute] = (this.time || "") + const [hour, minute, second] = (this.time || "") .split(":") .map(x => (x ? parseInt(x, 10) : undefined)); @@ -42,6 +42,7 @@ export default class LocalDateBuilder { day, hour, minute, + second, timezone: this.timezone, localTimezone: this.localTimezone }); diff --git a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 index d4864f742b2..ff0ab121e0f 100644 --- a/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 +++ b/plugins/discourse-local-dates/test/javascripts/lib/local-date-builder-test.js.es6 @@ -1,3 +1,4 @@ +import I18n from "I18n"; import LocalDateBuilder from "./local-date-builder"; const UTC = "Etc/UTC"; @@ -68,15 +69,23 @@ QUnit.test("date", assert => { { formated: "March 22, 2020" }, "it displays the date without time" ); - - assert.buildsCorrectDate( - { date: "2020-04-11", time: "11:00" }, - { formated: "April 11, 2020 1:00 PM" }, - "it displays the date with time" - ); }); }); +QUnit.test("date and time", assert => { + assert.buildsCorrectDate( + { date: "2020-04-11", time: "11:00" }, + { formated: "April 11, 2020 1:00 PM" }, + "it displays the date with time" + ); + + assert.buildsCorrectDate( + { date: "2020-04-11", time: "11:05:12", format: "LTS" }, + { formated: "1:05:12 PM" }, + "it displays full time (hours, minutes, seconds)" + ); +}); + QUnit.test("option[format]", assert => { freezeTime({ date: "2020-03-11" }, () => { assert.buildsCorrectDate(