Skip to content

Commit e209b3d

Browse files
adobesamrLFDanLudannifyreidbarberMichael Jordan
authored
Adds parseDuration documentation (#3844)
* Adding parseDuration functionality Adds parseDuration function to internationalized/date package to parse ISO 8601 Duration strings into a DateTimeDuration object * separating parseDuration documentation to separate PR * corrects formatting issues * corrects documentation for parseDuration function * fix deps in @react-types/list (#4073) * fix(#4067): Storybook Provider addon: Express input:checkbox requires id to be labelled by htmlFor prop (#4068) * Explain Proxy in TableView (#4072) Explain proxy usage in TableView * Update lightningcss (#4070) update lightnincss * fix(#4078): MobileComboBox: searchbox should not have aria-expanded property (#4079) * Get rid of dupe id in DatePicker/useDatePicker (#4085) * Getting rid of duplicated id present in presentational element * generate a separate id instead to avoid useField complaining in useDateField a date field in a datepicker/rangepicker gets the field props removed from it, but we still need to call useField in useDateField which will complain that there isnt a aria labelledby so we still need to pass the field props * Code changes from docs-ts branch (#4090) * Add docs to more pages, and small wording updates --------- Co-authored-by: Daniel Lu <[email protected]> Co-authored-by: Danni <[email protected]> Co-authored-by: Reid Barber <[email protected]> Co-authored-by: Michael Jordan <[email protected]> Co-authored-by: Robert Snow <[email protected]> Co-authored-by: Devon Govett <[email protected]>
1 parent a0efee8 commit e209b3d

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

packages/@internationalized/date/docs/CalendarDate.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,18 @@ date.subtract({years: 1, months: 1, days: 1}); // 2021-01-02
130130

131131
Adding or subtracting a duration that goes beyond the limits of a particular field will cause the date to be _balanced_. For example, adding one day to August 31st results in September 1st. In addition, if adding or subtracting one field causes another to be invalid, the date will be _constrained_. For example, adding one month to August 31st results in September 30th because September 31st does not exist.
132132

133+
### Parsing durations
134+
135+
The <TypeLink links={docs.links} type={docs.exports.parseDuration} /> function can be used to convert a [ISO 8601 duration string](https://en.wikipedia.org/wiki/ISO_8601#Durations) into a <TypeLink links={docs.links} type={docs.exports.DateTimeDuration} /> object. Negative values can be written by prefixing the entire string with a minus sign.
136+
137+
```tsx
138+
parseDuration('P3Y6M6W4D');
139+
// => {years: 3, months: 6, weeks: 6, days: 4}
140+
141+
parseDuration('-P3Y6M6W4D');
142+
// => {years: -3, months: -6, weeks: -6, days: -4}
143+
```
144+
133145
### Setting fields
134146

135147
`CalendarDate` objects are immutable, which means their properties cannot be set directly. Instead, use the `set` method, and pass the fields to be modified. This will return a new `CalendarDate` with the updated values.

packages/@internationalized/date/docs/CalendarDateTime.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ date.subtract({minutes: 30}); // 2022-02-03T09:15
128128

129129
Adding or subtracting a duration that goes beyond the limits of a particular field will cause the date to be _balanced_. For example, adding one day to August 31st results in September 1st. In addition, if adding or subtracting one field causes another to be invalid, the date will be _constrained_. For example, adding one month to August 31st results in September 30th because September 31st does not exist.
130130

131+
### Parsing durations
132+
133+
The <TypeLink links={docs.links} type={docs.exports.parseDuration} /> function can be used to convert a [ISO 8601 duration string](https://en.wikipedia.org/wiki/ISO_8601#Durations) into a <TypeLink links={docs.links} type={docs.exports.DateTimeDuration} /> object. The smallest time unit may include decimal values written with a comma or period, and negative values can be written by prefixing the entire string with a minus sign.
134+
135+
```tsx
136+
parseDuration('P3Y6M6W4DT12H30M5S');
137+
// => {years: 3, months: 6, weeks: 6, days: 4, hours: 12, minutes: 30, seconds: 5}
138+
139+
parseDuration('-P3Y6M6W4DT12H30M5S');
140+
// => {years: -3, months: -6, weeks: -6, days: -4, hours: -12, minutes: -30, seconds: -5}
141+
142+
parseDuration('P3Y6M6W4DT12H30M5.5S');
143+
// => {years: 3, months: 6, weeks: 6, days: 4, hours: 12, minutes: 30, seconds: 5.5}
144+
```
145+
131146
### Setting fields
132147

133148
`CalendarDateTime` objects are immutable, which means their properties cannot be set directly. Instead, use the `set` method, and pass the fields to be modified. This will return a new `CalendarDateTime` with the updated values.

packages/@internationalized/date/docs/Time.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,21 @@ time.add({seconds: 1}); // 09:45:01
7474

7575
Adding or subtracting a duration that goes beyond the limits of a particular field will cause the time to be _balanced_. For example, adding one minute to `09:59` results in `10:00`.
7676

77+
### Parsing durations
78+
79+
The <TypeLink links={docs.links} type={docs.exports.parseDuration} /> function can be used to convert a [ISO 8601 duration string](https://en.wikipedia.org/wiki/ISO_8601#Durations) into a <TypeLink links={docs.links} type={docs.exports.DateTimeDuration} /> object. The smallest time unit may include decimal values written with a comma or period, and negative values can be written by prefixing the entire string with a minus sign.
80+
81+
```tsx
82+
parseDuration('PT20H35M15S')
83+
// => {hours: 20, minutes: 35, seconds: 15}
84+
85+
parseDuration('-PT20H35M15S')
86+
// => {hours: -20, minutes: -35, seconds: -15}
87+
88+
parseDuration('PT20H35M15,75S')
89+
// => {hours: 20, minutes: 35, seconds: 15.75}
90+
```
91+
7792
### Setting fields
7893

7994
`Time` objects are immutable, which means their properties cannot be set directly. Instead, use the `set` method, and pass the fields to be modified. This will return a new `Time` with the updated values.

packages/@internationalized/date/docs/ZonedDateTime.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ let date = parseZonedDateTime('2020-03-07T02:00-08:00[America/Los_Angeles]');
185185
date.add({days: 1}); // 2020-03-08T03:00-07:00[America/Los_Angeles]
186186
```
187187

188+
### Parsing durations
189+
190+
The <TypeLink links={docs.links} type={docs.exports.parseDuration} /> function can be used to convert a [ISO 8601 duration string](https://en.wikipedia.org/wiki/ISO_8601#Durations) into a <TypeLink links={docs.links} type={docs.exports.DateTimeDuration} /> object. The smallest time unit may include decimal values written with a comma or period, and negative values can be written by prefixing the entire string with a minus sign.
191+
192+
```tsx
193+
parseDuration('P3Y6M6W4DT12H30M5S');
194+
// => {years: 3, months: 6, weeks: 6, days: 4, hours: 12, minutes: 30, seconds: 5}
195+
196+
parseDuration('-P3Y6M6W4DT12H30M5S');
197+
// => {years: -3, months: -6, weeks: -6, days: -4, hours: -12, minutes: -30, seconds: -5}
198+
199+
parseDuration('P3Y6M6W4DT12H30M5.5S');
200+
// => {years: 3, months: 6, weeks: 6, days: 4, hours: 12, minutes: 30, seconds: 5.5}
201+
```
202+
188203
### Setting fields
189204

190205
`ZonedDateTime` objects are immutable, which means their properties cannot be set directly. Instead, use the `set` method, and pass the fields to be modified. This will return a new `ZonedDateTime` with the updated values.

0 commit comments

Comments
 (0)