birl/time

Types

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

Constructors

  • Date(year: Int, month: Int, day: 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,
  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

also supports other similar formats:

Tue, 01-Nov-2016 08:49:37 GMT

Tue, 01 Nov 2016 08:49:37 +0630

Tue, 01-November-2016 08:49:37 Z

Tuesday, 01-Nov-2016 08:49:37 +330

Tuesday, 01 November 2016 08:49:37 +06:30

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

the naive format is the same as ISO8601 except that it does not contain the offset

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 get_timezone(value: DateTime) -> Option(String)
pub fn legible_difference(a: DateTime, b: DateTime) -> String
pub fn local_timezone() -> Option(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 now_with_timezone(timezone: String) -> Result(
  DateTime,
  Nil,
)
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 to 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 set_timezone(value: DateTime, new_timezone: String) -> Result(
  DateTime,
  Nil,
)
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_http_with_offset(value: DateTime) -> String

like to_http but assumes the offset in the DateTime value instead of GMT

pub fn to_iso8601(value: DateTime) -> String
pub fn to_naive(value: DateTime) -> String

the naive format is the same as ISO8601 except that it does not contain the offset

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