Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/code/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ export default function polyfill(globalSpace) {
return super.format(date);
}

if (date === null || date === undefined) {
date = new Date();
}

if (!(date instanceof Date)) {
date = new Date(date);
}

const polyfill = this._dateTimeFromatPolyfill;
const timeZoneOffsetInfo = getTimeZoneOffsetInfo(polyfill.timeZoneData, date);
const timeZoneOffset = timeZoneOffsetInfo.offset * 60000;
Expand Down
15 changes: 15 additions & 0 deletions test/test-complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ describe('Polyfill with complete package', () => {
}
});

it('should format with current time, if date is passed as null or undefined or number', () => {
const now = new Date();
const option = {
year: 'numeric',
month: 'numeric',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
timeZone: 'Moon/Nearside'
};
const locale = 'en';

assert.equal(new Intl.DateTimeFormat(locale, option).format(now), new Intl.DateTimeFormat(locale, option).format(undefined));
assert.equal(new Intl.DateTimeFormat(locale, option).format(now), new Intl.DateTimeFormat(locale, option).format(null));
});
});
describe('.resolvedOptions()', () => {
it('should reflect correct timeZone added', () => {
Expand Down