This commit is contained in:
antelle 2020-11-26 23:33:37 +01:00
parent 85a67b533a
commit 22754f32ec
No known key found for this signature in database
GPG Key ID: 63C9777AAB7C563C
2 changed files with 16 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { SettingsManager } from 'comp/settings/settings-manager';
import { StringFormat } from 'util/formatting/string-format';
const DateFormat = {
getMonthsForLocale() {
@ -61,7 +62,19 @@ const DateFormat = {
if (typeof dt === 'number') {
dt = new Date(dt);
}
return dt ? dt.toISOString().replaceAll(':', '-').slice(0, 19) : '';
return dt
? dt.getFullYear() +
'-' +
StringFormat.pad(dt.getMonth() + 1, 2) +
'-' +
StringFormat.pad(dt.getDate(), 2) +
'T' +
StringFormat.pad(dt.getHours(), 2) +
'-' +
StringFormat.pad(dt.getMinutes(), 2) +
'-' +
StringFormat.pad(dt.getSeconds(), 2)
: '';
}
};

View File

@ -2,14 +2,14 @@ import { expect } from 'chai';
import { DateFormat } from 'comp/util/date-format';
describe('DateFormat', () => {
const dt = new Date.UTC(2020, 0, 2, 3, 4, 5, 6);
const dt = new Date(2020, 0, 2, 3, 4, 5, 6);
it('should format date', () => {
expect(DateFormat.dStr(dt)).to.eql('Jan 2, 2020');
});
it('should format date and time', () => {
expect(DateFormat.dtStr(dt)).to.eql('Jan 2, 2020, 03:04:05 AM');
expect(DateFormat.dtStr(dt)).to.eql('Jan 2, 2020, 03:04:05');
});
it('should format date and time in sortable format', () => {