Introduce a locale/12-hour/24-hour preference on the clock service and a shared Intl-based formatter used across the dashboard.
39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import {
|
|
DEFAULT_TIME_FORMAT,
|
|
formatTime,
|
|
timeParts,
|
|
} from 'dashtab/utils/time-format';
|
|
|
|
const DATE = new Date(2026, 7, 3, 13, 5);
|
|
|
|
module('Unit | Utility | time-format', function () {
|
|
test('defaults to the locale format', function (assert) {
|
|
assert.strictEqual(DEFAULT_TIME_FORMAT, 'locale');
|
|
assert.ok(formatTime(DATE).length > 0);
|
|
assert.strictEqual(
|
|
formatTime(DATE, 'bogus'),
|
|
formatTime(DATE, DEFAULT_TIME_FORMAT)
|
|
);
|
|
});
|
|
|
|
test('24-hour format has no day period', function (assert) {
|
|
const { time, period } = timeParts(DATE, '24h');
|
|
|
|
assert.strictEqual(period, '');
|
|
assert.ok(/^13[:.]05$/.test(time), `unexpected time: ${time}`);
|
|
assert.strictEqual(formatTime(DATE, '24h'), time);
|
|
});
|
|
|
|
test('12-hour format includes a day period', function (assert) {
|
|
const { time, period } = timeParts(DATE, '12h');
|
|
|
|
assert.ok(period.length > 0);
|
|
assert.ok(/^1[:.]05$/.test(time), `unexpected time: ${time}`);
|
|
|
|
const formatted = formatTime(DATE, '12h');
|
|
assert.ok(formatted.includes(time));
|
|
assert.ok(formatted.includes(period));
|
|
});
|
|
});
|