tempo/period

Types

pub type Unit {
  Year
  Month
  Week
  Day
  Hour
  Minute
  Second
  Millisecond
  Microsecond
  Nanosecond
}

Constructors

  • Year
  • Month
  • Week
  • Day
  • Hour
  • Minute
  • Second
  • Millisecond
  • Microsecond
  • Nanosecond

Functions

pub fn as_days(period: Period) -> Int

Returns the number of days in the period.

Examples

period.new(
  start: naive_datetime.literal("2024-06-13T15:47:00"),
  end: naive_datetime.literal("2024-06-21T07:16:12"),
)
|> period.as_days
// -> 7
pub fn as_days_fractional(period: Period) -> Float

Returns the number of days in the period.

Does not account for leap seconds like the rest of the package.

Examples

period.new(
  start: naive_datetime.literal("2024-06-13T15:47:00"),
  end: naive_datetime.literal("2024-06-21T07:16:12"),
)
|> period.as_days_fractional
// -> 7.645277777777778
pub fn as_duration(period: Period) -> Duration

Returns a period as a duration, losing the context of the start and end datetimes.

Example

period.new(
  start: naive_datetime.literal("2024-06-13T15:47:00"),
  end: naive_datetime.literal("2024-06-21T07:16:12"),
)
|> period.as_duration
|> duration.as_weeks
// -> 1
pub fn as_seconds(period: Period) -> Int

Returns the number of seconds in the period.

Does not account for leap seconds like the rest of the package.

Examples

period.new(
  start: naive_datetime.literal("2024-06-13T07:16:32"),
  end: naive_datetime.literal("2024-06-13T07:16:12"),
)
|> period.as_seconds
// -> 20
pub fn new(
  start start: NaiveDateTime,
  end end: NaiveDateTime,
) -> Period

Creates a new period from the start and end naive datetimes.

Examples

period.new(
  start: naive_datetime.literal("2024-06-13T15:47:00"),
  end: naive_datetime.literal("2024-06-21T07:16:12"),
)
|> period.as_days
// -> 7
pub fn to_duration(period: Period) -> Duration
Search Document