Skip to content

Commit 1716a59

Browse files
Apply suggestions from code review
fix linter problems Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 70b3e7e commit 1716a59

File tree

1 file changed

+17
-11
lines changed
  • files/en-us/web/javascript/reference/global_objects/intl/durationformat/format

1 file changed

+17
-11
lines changed

files/en-us/web/javascript/reference/global_objects/intl/durationformat/format/index.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,10 @@ It is possible to individually set the formatting of specific units by setting t
117117
</tr>
118118
</tbody>
119119
</table>
120-
121120

122121
If the formatting for `hours` or any smaller unit is set to `"2-digit"` or `"numeric"`, the formatting for all smaller units cannot be set to a value other than `"2-digit"` or `"numeric"`.
123122

124123
```js
125-
126124
const duration = {
127125
months: 2,
128126
weeks: 3,
@@ -136,9 +134,14 @@ const duration = {
136134
};
137135

138136
// a mixture of styles
139-
new Intl.DurationFormat('en', {style: "narrow", months: "long", weeks: "short", days: "long", hours: "long"}).format(duration);
137+
new Intl.DurationFormat("en", {
138+
style: "narrow",
139+
months: "long",
140+
weeks: "short",
141+
days: "long",
142+
hours: "long",
143+
}).format(duration);
140144
// => "2 months 3 wks 3 days 4 hours 5m 6s 7ms 8μs 9ns"
141-
142145
```
143146

144147
### Displaying subsecond units as fractions of a second
@@ -149,7 +152,7 @@ This setting can be overidden by setting `seconds` and the equivalent options fo
149152

150153
If the `style` option is not `"digital"` but the value for `seconds` is set to `"numeric"` or `"2-digits"`, then all units smaller than seconds will be displayed as fractions of seconds.
151154

152-
If the `style` option is not `"digital"` and `seconds` is not `"numeric"` or `"2-digit"`, but `milliseconds`, `microseconds`, or `nanoseconds` is set to `"numeric"`, then the value of that unit and all smaller units will be displayed as a fraction of the smallest unit that is set to any non-numeric style. If all sub-second values are set to "numeric", then those values will be displayed as a fraction of a second.
155+
If the `style` option is not `"digital"` and `seconds` is not `"numeric"` or `"2-digit"`, but `milliseconds`, `microseconds`, or `nanoseconds` is set to `"numeric"`, then the value of that unit and all smaller units will be displayed as a fraction of the smallest unit that is set to any non-numeric style. If all sub-second values are set to "numeric", then those values will be displayed as a fraction of a second.
153156

154157
```js
155158

@@ -174,13 +177,13 @@ new Intl.DurationFormat('en', {style: "digital", hours: "long", minutes: "long",
174177

175178
// overriding the "long" style
176179
new Intl.DurationFormat('en', {style: "long", seconds: "numeric"}).format(duration)
177-
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6.007008009"
180+
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6.007008009"
178181

179182
new Intl.DurationFormat('en', {style: "long", seconds: "2-digit"}).format(duration)
180183
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 06.007008009"
181184

182185
new Intl.DurationFormat('en', {style: "long", milliseconds: "numeric"}).format(duration)
183-
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6.007008009"
186+
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6.007008009"
184187

185188
new Intl.DurationFormat('en', {style: "long", microseconds: "numeric").format(duration)
186189
// => "2 months, 3 weeks, 3 days, 4 hours, 5 minutes, 6 seconds, 7.008009 milliseconds"
@@ -191,10 +194,9 @@ new Intl.DurationFormat('en', {style: "long", nanoseconds: "numeric"}).format(du
191194
192195
### Using the fractionalDigits option
193196
194-
If the other conditions for displaying units as fractions of a larger unit are met, and if the `fractionalDigits` option is set to any value between 0 and 9, inclusive of both, then that many fractional digits will be displayed. Rounding, if necessary, is toward 0. If `fractionalDigits` is not set, enough fractional digits (and no more than enough) will be used to fully display all components of the duration.
197+
If the other conditions for displaying units as fractions of a larger unit are met, and if the `fractionalDigits` option is set to any value between 0 and 9, inclusive of both, then that many fractional digits will be displayed. Rounding, if necessary, is toward 0. If `fractionalDigits` is not set, enough fractional digits (and no more than enough) will be used to fully display all components of the duration.
195198
196199
```js
197-
198200
const duration = {
199201
hours: 11,
200202
minutes: 30,
@@ -206,10 +208,14 @@ const duration = {
206208
new Intl.DurationFormat("en", { style: "digital" }).format(duration);
207209
// => "11:30:12.3456"
208210

209-
new Intl.DurationFormat("en", {style: "digital", fractionalDigits: 5}).format(duration);
211+
new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 5 }).format(
212+
duration,
213+
);
210214
// => "11:30:12.34560"
211215

212-
new Intl.DurationFormat("en", {style: "digital", fractionalDigits: 3}).format(duration);
216+
new Intl.DurationFormat("en", { style: "digital", fractionalDigits: 3 }).format(
217+
duration,
218+
);
213219
// => "11:30:12.346"
214220
```
215221

0 commit comments

Comments
 (0)