Skip to content

Latest commit

 

History

History
274 lines (169 loc) · 7.05 KB

File metadata and controls

274 lines (169 loc) · 7.05 KB

Module bucdate

Format dates in erlang.

Copyright (c) Dale Harvey

Description

Licensed under the MIT license

This module formats erlang dates in the form {{Year, Month, Day}, {Hour, Minute, Second}} to printable strings, using (almost) equivalent formatting rules as http://uk.php.net/date, US vs European dates are disambiguated in the same way as http://uk.php.net/manual/en/function.strtotime.php That is, Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed. To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates.

erlang has no concept of timezone so the following formats are not implemented: B e I O P T Z formats c and r will also differ slightly

See tests at bottom for examples

Data Types


dt_unit() = second | minute | hour | day | month | year

dt_units() = seconds | minutes | hours | days | months | years

now() = {integer(), integer(), integer()}

Function Index

add/2 Add 1 unit to the given DateTime.
add/3 Add N units to the given DateTime.
compare/2 Compate Date1 and Date2
format/1format current local time as Format.
format/2format Date as Format.
local_timezone/0 Return the local timezone.
nparse/1parses the datetime from a string into 'now' format.
parse/1parses the datetime from a string.
parse/2parses the datetime from a string.
timezone_offset/0 Returns the time difference between UTC time and local time, in minutes.
to_iso8601/1 Return date using iso8601 format.
today/0 return now local datetime.
today_utc/0 return now UTC datetime.
tomorrow/0 return tomorrow local datetime.
tomorrow_utc/0 return tomorrow UTC datetime.
yesterday/0 return yesterday local datetime.
yesterday_utc/0 return yesterday UTC datetime.

Function Details

add/2


Add 1 unit to the given DateTime.

add/3


add(DateTime::calendar:datetime(), N::integer(), X3::dt_units()) -> calendar:datetime()

Add N units to the given DateTime.

compare/2


compare(Date1::calendar:datetime(), Date2::calendar:datetime()) -> -1 | 1 | 0

Compate Date1 and Date2

format/1


format(Format::string()) -> string()

format current local time as Format

format/2


format(Format::string(), Now::calendar:datetime() | now()) -> string()

format Date as Format

local_timezone/0

local_timezone() -> any()

Return the local timezone

nparse/1


nparse(Date::string()) -> now()

parses the datetime from a string into 'now' format

parse/1


parse(Date::string()) -> calendar:datetime()

parses the datetime from a string

parse/2


parse(Date::string(), Now::calendar:datetime() | now()) -> calendar:datetime()

parses the datetime from a string

timezone_offset/0

timezone_offset() -> any()

Returns the time difference between UTC time and local time, in minutes.

to_iso8601/1


to_iso8601(Date::calendar:datetime()) -> string()

Return date using iso8601 format

today/0


today() -> calendar:datetime()

return now local datetime.

today_utc/0


today_utc() -> calendar:datetime()

return now UTC datetime.

tomorrow/0


tomorrow() -> calendar:datetime()

return tomorrow local datetime.

tomorrow_utc/0


tomorrow_utc() -> calendar:datetime()

return tomorrow UTC datetime.

yesterday/0


yesterday() -> calendar:datetime()

return yesterday local datetime.

yesterday_utc/0


yesterday_utc() -> calendar:datetime()

return yesterday UTC datetime.