Skip to content

Commit 001cda0

Browse files
committed
feat: Add DurationOptions
Resolves #22
1 parent 1891e80 commit 001cda0

File tree

7 files changed

+665
-3
lines changed

7 files changed

+665
-3
lines changed

package-lock.json

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"@formatjs/intl-durationformat": "^0.7.2"
4+
}
5+
}

script/generate-options/src/Main.purs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,77 @@ options =
267267
, { name: "Other", toString: "other" }
268268
]
269269
}
270+
, { name: "DurationFormatStyle"
271+
, constructors:
272+
narrowShortLong <>
273+
[ { name: "Digital", toString: "digital" } ]
274+
}
275+
, { name: "Years"
276+
, constructors: narrowShortLong
277+
}
278+
, { name: "YearsDisplay"
279+
, constructors: alwaysAuto
280+
}
281+
, { name: "Months"
282+
, constructors: narrowShortLong
283+
}
284+
, { name: "MonthsDisplay"
285+
, constructors: alwaysAuto
286+
}
287+
, { name: "Weeks"
288+
, constructors: narrowShortLong
289+
}
290+
, { name: "WeeksDisplay"
291+
, constructors: alwaysAuto
292+
}
293+
, { name: "Days"
294+
, constructors: narrowShortLong
295+
}
296+
, { name: "DaysDisplay"
297+
, constructors: alwaysAuto
298+
}
299+
, { name: "Hours"
300+
, constructors: narrowShortLong <> twoDigitNumeric
301+
}
302+
, { name: "HoursDisplay"
303+
, constructors: alwaysAuto
304+
}
305+
, { name: "Minutes"
306+
, constructors: narrowShortLong <> twoDigitNumeric
307+
}
308+
, { name: "MinutesDisplay"
309+
, constructors: alwaysAuto
310+
}
311+
, { name: "Seconds"
312+
, constructors: narrowShortLong <> twoDigitNumeric
313+
}
314+
, { name: "SecondsDisplay"
315+
, constructors: alwaysAuto
316+
}
317+
, { name: "Milliseconds"
318+
, constructors: narrowShortLong <> numeric
319+
}
320+
, { name: "MillisecondsDisplay"
321+
, constructors: alwaysAuto
322+
}
323+
, { name: "Microseconds"
324+
, constructors: narrowShortLong <> numeric
325+
}
326+
, { name: "MicrosecondsDisplay"
327+
, constructors: alwaysAuto
328+
}
329+
, { name: "Nanoseconds"
330+
, constructors: narrowShortLong <> numeric
331+
}
332+
, { name: "NanosecondsDisplay"
333+
, constructors: alwaysAuto
334+
}
270335
]
271336
where
337+
numeric = [ { name: "Numeric", toString: "numeric" } ]
272338
twoDigitNumeric =
273-
[ { name: "Numeric", toString: "numeric" }
274-
, { name: "TwoDigit", toString: "2-digit" }
275-
]
339+
[ { name: "TwoDigit", toString: "2-digit" } ]
340+
<> numeric
276341
narrowShortLong =
277342
[ { name: "Narrow", toString: "narrow" }
278343
, { name: "Short", toString: "short" }
@@ -284,6 +349,10 @@ options =
284349
, { name: "Medium", toString: "medium" }
285350
, { name: "Short", toString: "short" }
286351
]
352+
alwaysAuto =
353+
[ { name: "Always", toString: "always" }
354+
, { name: "Auto", toString: "auto" }
355+
]
287356

288357
makeModule :: String -> Option -> Module Void
289358
makeModule moduleName option = Partial.Unsafe.unsafePartial do

src/JS/Intl/DurationFormat.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
export function _new(locales, options) {
4+
return new Intl.DurationFormat(locales, options);
5+
}
6+
7+
export function _format(durationFormat, number) {
8+
return durationFormat.format(number);
9+
}
10+
11+
export function _formatToParts(durationFormat, number) {
12+
return durationFormat.formatToParts(number);
13+
}
14+
15+
export function _resolvedOptions(durationFormat) {
16+
return durationFormat.resolvedOptions();
17+
}
18+
19+
export function _supportedLocalesOf(locales, options) {
20+
return Intl.NumberFormat.supportedLocalesOf(locales, options);
21+
}

0 commit comments

Comments
 (0)