Duration¶
The Duration widget allows users to specify a time period, expressing it in various units (days, hours, minutes, etc.).
Duration Template¶
The units of duration are defined using a template expression. If no template is provided, the default template P0DT0H0M (representing zero duration) is used.
Duration Expression Format¶
A duration expression adheres to the following structure:
- Begins with
P - Followed by year (
Y), month (M), and day (D) units (optional, in that order). - Followed by
T(if time units are specified). - Followed by hour (
H), minute (M), and second (S) units (optional, in that order).
Unit Identifiers:
Y: YearM: MonthD: DayH: HourM: MinuteS: Second
Examples¶
P1D: 1 DayP1M2D: 1 Month and 2 DaysP1MT8H: 1 Month and 8 HoursPT2H: 2 Hours
Relative Date Specifiers¶
To enhance usability, the widget supports relative date specifiers in addition to the standard ISO-8601 duration format. These specifiers modify the date relative to the current date.
YB: Year Begin (beginning of the year)YE: Year End (end of the year)MB: Month Begin (beginning of the month)ME: Month End (end of the month)DB: Day Begin (beginning of the day)DE: Day End (end of the day)
Relative Date Examples¶
P2YB: Adds 2 years to the current date, then sets the date to the beginning of that year.P1M2DB: Adds 1 month and 2 days to the current date, then sets the date to the beginning of that day.P1M2DE: Adds 1 month and 2 days to the current date, then sets the date to the end of that day.