duration-helper: Construct a duration

Description Usage Arguments Value Internal Representation Examples

Description

These helpers construct durations of the specified precision. Durations represent units of time.

Durations are separated into two categories:

Calendrical

Chronological

Calendrical durations are generally used when manipulating calendar types, like year-month-day. Chronological durations are generally used when working with time points, like sys-time or naive-time.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21

Arguments

n

[integer]

The number of units of time to use when creating the duration.

Value

A duration of the specified precision.

Internal Representation

Durations are internally represented as an integer number of "ticks" along with a ratio describing how it converts to a number of seconds. The following duration ratios are used in clock:

A duration of 1 year is defined to correspond to the average length of a proleptic Gregorian year, i.e. 365.2425 days.

A duration of 1 month is defined as exactly 1/12 of a year.

A duration of 1 quarter is defined as exactly 1/4 of a year.

A duration of 1 week is defined as exactly 7 days.

These conversions come into play when doing operations like adding or flooring durations. Generally, you add two calendrical durations together to get a new calendrical duration, rather than adding a calendrical and a chronological duration together. The one exception is duration_cast(), which can cast durations to any other precision, with a potential loss of information.

Examples

1
2

clock documentation built on July 23, 2021, 1:06 a.m.