birl/time

Types

pub type Date {
  Date(day: Int, month: Int, year: Int)
}

Constructors

  • Date(day: Int, month: Int, year: Int)
pub opaque type DateTime
pub type Month {
  Jan
  Feb
  Mar
  Apr
  May
  Jun
  Jul
  Aug
  Sep
  Oct
  Nov
  Dec
}

Constructors

  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec
pub type Time {
  Time(hour: Int, minute: Int, second: Int, milli_second: Int)
}

Constructors

  • Time(hour: Int, minute: Int, second: Int, milli_second: Int)
pub type Weekday {
  Mon
  Tue
  Wed
  Thu
  Fri
  Sat
  Sun
}

Constructors

  • Mon
  • Tue
  • Wed
  • Thu
  • Fri
  • Sat
  • Sun

Constants

pub const unix_epoch: DateTime = DateTime(0, 0, option.None)

starting point of unix timestamps

Functions

pub fn add(value: DateTime, duration: Duration) -> DateTime
pub fn compare(a: DateTime, b: DateTime) -> Order
pub fn difference(a: DateTime, b: DateTime) -> Duration
pub fn from_erlang_local_datetime(erlang_datetime: #(
    #(Int, Int, Int),
    #(Int, Int, Int),
  )) -> DateTime

calculates the DateTime value from the erlang datetime using the local offset of the system

pub fn from_erlang_universal_datetime(erlang_datetime: #(
    #(Int, Int, Int),
    #(Int, Int, Int),
  )) -> DateTime

calculates the DateTime value from the erlang datetime in UTC

pub fn from_http(value: String) -> Result(DateTime, Nil)

see here

pub fn from_iso8601(value: String) -> Result(DateTime, Nil)
pub fn from_unix(value: Int) -> DateTime

unix timestamps are the number of seconds that have elapsed since 00:00:00 UTC on January 1st, 1970

pub fn get_date(value: DateTime) -> Date
pub fn get_offset(value: DateTime) -> String
pub fn get_time(value: DateTime) -> Time
pub fn legible_difference(a: DateTime, b: DateTime) -> String
pub fn monotonic_now() -> Int
pub fn month(value: DateTime) -> Month
pub fn now() -> DateTime

use this to get the current time in the local timezone offset

pub fn now_with_offset(offset: String) -> Result(DateTime, Nil)

use this to get the current time with a given offset.

Some examples of acceptable offsets:

"+330", "03:30", "-8:00","-7", "-0400", "03"

pub fn range(from a: DateTime, to b: Option(DateTime), step s: Duration) -> Iterator(
  DateTime,
)

can be used to create a time range starting from time a with step s

if b is option.None the range will be infinite

pub fn set_date(value: DateTime, date: Date) -> DateTime
pub fn set_offset(value: DateTime, new_offset: String) -> Result(
  DateTime,
  Nil,
)

use this tp change the offset of a given time value.

Some examples of acceptable offsets:

"+330", "03:30", "-8:00","-7", "-0400", "03", "Z"

pub fn set_time(value: DateTime, time: Time) -> DateTime
pub fn short_string_month(value: DateTime) -> String
pub fn short_string_weekday(value: DateTime) -> String
pub fn string_month(value: DateTime) -> String
pub fn string_weekday(value: DateTime) -> String
pub fn subtract(value: DateTime, duration: Duration) -> DateTime
pub fn to_erlang_datetime(value: DateTime) -> #(
  #(Int, Int, Int),
  #(Int, Int, Int),
)

calculates erlang datetime using the offset in the DateTime value

pub fn to_erlang_universal_datetime(value: DateTime) -> #(
  #(Int, Int, Int),
  #(Int, Int, Int),
)

calculates the universal erlang datetime regardless of the offset in the DateTime value

pub fn to_http(value: DateTime) -> String

see here

pub fn to_iso8601(value: DateTime) -> String
pub fn to_unix(value: DateTime) -> Int

unix timestamps are the number of seconds that have elapsed since 00:00:00 UTC on January 1st, 1970

pub fn utc_now() -> DateTime

use this to get the current time in utc

pub fn weekday(value: DateTime) -> Weekday
Search Document