LmnDuration
@class LmnDuration @description A wrapper class for managing durations, offering support for various formats, timezones, and date manipulation.
This class provides utilities to work with durations, allowing:
- Conversion between different duration formats (e.g., milliseconds, ISO, human-readable).
- Duration manipulation (e.g., adding/subtracting hours, minutes, seconds).
Constructor
Creates a new LmnDuration instance. | ||||||
Presentation
| ||||||
Parameters
|
Properties
Name | Type | Description |
---|---|---|
#duration |
| |
extendedTime r |
| The current duration stored in the LmnDuration, formatted as an extended hms string (i.e. "5hr 4min 25sec"). This format is the most suitable for screen readers. It is updated whenever the duration changes. |
fullTime r |
| The current duration stored in the LmnDuration, formatted as a full hms string (i.e. "5 hours 4 minutes 25 seconds"). It is updated whenever the duration changes. |
time r |
| The current duration stored in the LmnDuration, formatted as a hms string (i.e. "5h 4m 25s"). It is updated whenever the duration changes. |
Methods
add() | ||||||
---|---|---|---|---|---|---|
Adds the provided amount of time to the current LmnDuration. | ||||||
Presentation
| ||||||
Parameters
Returns |
asDays() |
---|
Returns the length of the duration in days. |
Presentation
|
Returnsnumber -The length of the duration in days. |
asHours() |
---|
Returns the length of the duration in hours. |
Presentation
|
Returnsnumber -The length of the duration in hours. |
asMilliseconds() |
---|
Returns the length of the duration in milliseconds. |
Presentation
|
Returnsnumber -The length of the duration in milliseconds. |
asMinutes() |
---|
Returns the length of the duration in minutes. |
Presentation
|
Returnsnumber -The length of the duration in minutes. |
asMonths() |
---|
Returns the length of the duration in months. |
Presentation
|
Returnsnumber -The length of the duration in months. |
asSeconds() |
---|
Returns the length of the duration in seconds. |
Presentation
|
Returnsnumber -The length of the duration in seconds. |
asWeeks() |
---|
Returns the length of the duration in weeks. |
Presentation
|
Returnsnumber -The length of the duration in weeks. |
asYears() |
---|
Returns the length of the duration in years. |
Presentation
|
Returnsnumber -The length of the duration in years. |
clone() |
---|
Returns a copy of this LmnDuration object |
Presentation
|
Returns |
format() | ||||||
---|---|---|---|---|---|---|
Formats the current LmnDuration following the provided options or the defaults. If no options are provided, the LmnDuration is formatted as an hms duration (i.e. "4h 3m 29s"). It is possible to format the LmnDuration as an hms time or an hms extended time:
By default, durations are formatted dropping the leading and trailing blank units. However, it is possible to keep them when formatting a duration:
It is also possible to provide a totally custom format:
| ||||||
Presentation
| ||||||
Parameters
Returnsstring -The formatted duration |
getDays() |
---|
Returns the days. |
Presentation
|
Returnsnumber -The days. |
getHours() |
---|
Returns the hours (0-23). |
Presentation
|
Returnsnumber -The hours. |
getMilliseconds() |
---|
Returns the milliseconds (0-999). |
Presentation
|
Returnsnumber -The milliseconds. |
getMinutes() |
---|
Returns the minutes (0-59). |
Presentation
|
Returnsnumber -The minutes. |
getMonths() |
---|
Returns the months. |
Presentation
|
Returnsnumber -The months. |
getSeconds() |
---|
Returns the seconds (0-59). |
Presentation
|
Returnsnumber -The seconds. |
getWeeks() |
---|
Returns the weeks. |
Presentation
|
Returnsnumber -The weeks. |
getYears() |
---|
Returns the years. |
Presentation
|
Returnsnumber -The years. |
humanize() |
---|
Returns the humanized duration, approximated to its biggest unit (i.e. "4 days", "3 minutes"). |
Presentation
|
Returnsstring -The humanized duration. |
subtract() | ||||||
---|---|---|---|---|---|---|
Subtracts the provided amount of time from the current LmnDuration. | ||||||
Presentation
| ||||||
Parameters
Returns |
toISOString() |
---|
Formats the current LmnDuration to the ISO8601 standard. |
Presentation
|
Returnsstring -The ISO8601 formatted duration. |