Skip to content

Commit 150c616

Browse files
katemihalikovaptomato
authored andcommitted
Add dateStyle/timeStyle to Intl helpers
Fixes #1590
1 parent bf1ee1f commit 150c616

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

lib/intl.mjs

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,33 @@ function formatRangeToParts(a, b) {
144144

145145
function amend(options = {}, amended = {}) {
146146
options = ObjectAssign({}, options);
147-
for (let opt of ['year', 'month', 'day', 'hour', 'minute', 'second', 'weekday', 'timeZoneName']) {
147+
for (let opt of [
148+
'year',
149+
'month',
150+
'day',
151+
'hour',
152+
'minute',
153+
'second',
154+
'weekday',
155+
'timeZoneName',
156+
'dateStyle',
157+
'timeStyle'
158+
]) {
148159
options[opt] = opt in amended ? amended[opt] : options[opt];
149160
if (options[opt] === false || options[opt] === undefined) delete options[opt];
150161
}
151162
return options;
152163
}
153164

154165
function timeAmend(options) {
155-
options = amend(options, { year: false, month: false, day: false, weekday: false, timeZoneName: false });
166+
options = amend(options, {
167+
year: false,
168+
month: false,
169+
day: false,
170+
weekday: false,
171+
timeZoneName: false,
172+
dateStyle: false
173+
});
156174
if (!hasTimeOptions(options)) {
157175
options = ObjectAssign({}, options, {
158176
hour: 'numeric',
@@ -170,7 +188,9 @@ function yearMonthAmend(options) {
170188
minute: false,
171189
second: false,
172190
weekday: false,
173-
timeZoneName: false
191+
timeZoneName: false,
192+
dateStyle: false,
193+
timeStyle: false
174194
});
175195
if (!('year' in options || 'month' in options)) {
176196
options = ObjectAssign(options, { year: 'numeric', month: 'numeric' });
@@ -185,7 +205,9 @@ function monthDayAmend(options) {
185205
minute: false,
186206
second: false,
187207
weekday: false,
188-
timeZoneName: false
208+
timeZoneName: false,
209+
dateStyle: false,
210+
timeStyle: false
189211
});
190212
if (!('month' in options || 'day' in options)) {
191213
options = ObjectAssign({}, options, { month: 'numeric', day: 'numeric' });
@@ -194,7 +216,13 @@ function monthDayAmend(options) {
194216
}
195217

196218
function dateAmend(options) {
197-
options = amend(options, { hour: false, minute: false, second: false, timeZoneName: false });
219+
options = amend(options, {
220+
hour: false,
221+
minute: false,
222+
second: false,
223+
timeZoneName: false,
224+
timeStyle: false
225+
});
198226
if (!hasDateOptions(options)) {
199227
options = ObjectAssign({}, options, {
200228
year: 'numeric',
@@ -250,11 +278,11 @@ function instantAmend(options) {
250278
}
251279

252280
function hasDateOptions(options) {
253-
return 'year' in options || 'month' in options || 'day' in options || 'weekday' in options;
281+
return 'year' in options || 'month' in options || 'day' in options || 'weekday' in options || 'dateStyle' in options;
254282
}
255283

256284
function hasTimeOptions(options) {
257-
return 'hour' in options || 'minute' in options || 'second' in options;
285+
return 'hour' in options || 'minute' in options || 'second' in options || 'timeStyle' in options;
258286
}
259287

260288
function isTemporalObject(obj) {

0 commit comments

Comments
 (0)