Module ec_date

Format dates in erlang.

Copyright © Dale Harvey

Description

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()

date() = {year(), month(), day()}

datetime()

datetime() = {date(), time()}

day()

day() = 1..31

hour()

hour() = 0..23

microsecond()

microsecond() = 0..999999

minute()

minute() = 0..59

month()

month() = 1..12 | {month, 1..12}

now()

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

second()

second() = 0..59

time()

time() = {hour(), minute(), second()} | {hour(), minute(), second(), microsecond()}

year()

year() = non_neg_integer()

Function Index

format/1format current local time as Format.
format/2format Date as Format.
format_iso8601/1format date in the ISO8601 format This always puts 'Z' as time zone, since we have no notion of 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.
tokenise/2

Function Details

format/1

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

format current local time as Format

format/2

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

format Date as Format

format_iso8601/1

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

format date in the ISO8601 format This always puts 'Z' as time zone, since we have no notion of timezone

nparse/1

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

parses the datetime from a string into 'now' format

parse/1

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

parses the datetime from a string

parse/2

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

parses the datetime from a string

tokenise/2

tokenise(Rest, Acc) -> any()


Generated by EDoc, May 1 2024, 06:09:58.