-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(formatDate): add locale option to be extensible for absolute format #19157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
fc43853
7ee00de
75939cc
bafc84f
29d5a90
daac0e8
43e4f76
3568311
7c24587
cec0ae4
f9b75b8
08832a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ const styles = ['full', 'long', 'medium', 'short']; | |
const date = new Date('2016-04-28T19:12:47Z'); | ||
const endDate = new Date('2018-07-01T09:00:02Z'); | ||
const sameDayEndDate = new Date('2016-04-28T21:04:30Z'); | ||
const timeZones = ['UTC', 'America/New_York', 'Asia/Tokyo']; | ||
|
||
describe(locale, () => { | ||
describe('formatTime', () => { | ||
|
@@ -23,6 +24,23 @@ describe(locale, () => { | |
const actualOutput = absolute.formatTime(date, { locale, style }); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
|
||
timeZones.forEach((timeZone) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { | ||
timeStyle: style, | ||
timeZone, | ||
}); | ||
const expectedOutput = dtf.format(date); | ||
|
||
test(`${style} with timeZone ${timeZone} → ${expectedOutput}`, () => { | ||
const actualOutput = absolute.formatTime(date, { | ||
locale, | ||
style, | ||
timeZone, | ||
}); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't put this within the We don't even need to test three different time zones, for
I'd personally go with # 2 as it's more of a true unit test, but seeing how none of the preexisting tests are written this way, it might be less controversial to stick with # 1. Whichever you choose, please replicate to all tests. 🙏🏻 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I chose the 1st option. I chose two timezones This will how the tests would show up. At the end there will be 2 test cases for each function (8 iterations in all) |
||
}); | ||
}); | ||
|
||
|
@@ -35,6 +53,23 @@ describe(locale, () => { | |
const actualOutput = absolute.formatDate(date, { locale, style }); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
|
||
timeZones.forEach((timeZone) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { | ||
dateStyle: style, | ||
timeZone, | ||
}); | ||
const expectedOutput = dtf.format(date); | ||
|
||
test(`${style} with timeZone ${timeZone} → ${expectedOutput}`, () => { | ||
const actualOutput = absolute.formatDate(date, { | ||
locale, | ||
style, | ||
timeZone, | ||
}); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
|
@@ -54,6 +89,26 @@ describe(locale, () => { | |
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
|
||
describe('with timeZone', () => { | ||
timeZones.forEach((timeZone) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { | ||
timeStyle, | ||
dateStyle: timeStyle, | ||
timeZone, | ||
}); | ||
const expectedOutput = dtf.format(date); | ||
|
||
test(`${timeStyle} in ${timeZone} → ${expectedOutput}`, () => { | ||
const actualOutput = absolute.format(date, { | ||
locale, | ||
style: timeStyle, | ||
timeZone, | ||
}); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
}); | ||
}); | ||
|
||
dkaushik95 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
describe('manual', () => { | ||
styles.forEach((dateStyle) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { timeStyle, dateStyle }); | ||
|
@@ -99,6 +154,26 @@ describe(locale, () => { | |
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
|
||
describe('with timeZone', () => { | ||
timeZones.forEach((timeZone) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { | ||
timeStyle: dateStyle, | ||
dateStyle, | ||
timeZone, | ||
}); | ||
const expectedOutput = dtf.formatRange(date, endDate); | ||
|
||
test(`${dateStyle} in ${timeZone} → ${expectedOutput}`, () => { | ||
const actualOutput = absolute.formatRange(date, endDate, { | ||
locale, | ||
style: dateStyle, | ||
timeZone, | ||
}); | ||
expect(actualOutput).toBe(expectedOutput); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('manual', () => { | ||
[...styles, null].forEach((timeStyle) => { | ||
const dtf = new Intl.DateTimeFormat(locale, { | ||
|
dkaushik95 marked this conversation as resolved.
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.