ec_date

Format dates in erlang.

Format dates in erlang

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

date() = {year(), month(), day()}
datetime() = {date(), time()}
day() = 1..31
hour() = 0..23
microsecond() = 0..1000000
minute() = 0..59
month() = 1..12 | {month, 1..12}
now() = {integer(), integer(), integer()}
second() = 0..59
time() = {hour(), minute(), second()} | {hour(), minute(), second(), microsecond()}
year() = non_neg_integer()

Functions


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

format current local time as Format

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

format Date as Format

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

parses the datetime from a string

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

parses the datetime from a string

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

parses the datetime from a string into 'now' format

View Functions