z_datetime (zotonic_core v1.0.0-rc.17)
Utility functions for datetime handling and representation.
Summary
Functions
Translate a local time date to UNIX timestamp
Return the number of days in a certain year.
Return the absolute difference between two dates. Does not take daylight saving into account.
Format the current date according to the format and the timezone settings in the context.
Format a date according to the format and the timezone settings in the context.
Format the current date in UTC.
Format the date using the UTC timezone.
Shift a date if the date falls outside the valid date or time ranges. Return undefined if the date could not be mapped to some valid date.
Return the month-boundaries of a given date
Return the millisec value of the current clock.
Return the date one day later.
Return the date one hour later.
Return the date one minute later.
Return the date one month later. Gives unpredictable results if the day doesn't exist in the next month. (eg. feb 30 will become feb 28).
Return the date one second later.
Return the date one week later.
Return the date one year later.
Return the date one day earlier.
Return the date one hour earlier.
Return the date one minute earlier.
Return the date one month earlier.
Return the date one second earlier.
Return the date one week earlier.
Return the date one year earlier.
Show a humanized version of a relative datetime. Like "4 months, 3 days ago".
Show a humanized version of a period between two dates. Like "4 months, 3 days ago".
Show a humanized version of a period between two dates. Like "4 months, 3 days ago". WhenText is a string containing a maximum of three tokens. Example "ago, now, in"
Calculate the current UNIX timestamp (seconds since Jan 1, 1970)
Translate UNIX timestamp to local datetime.
Convert an input to a (universal) datetime, using to_date/1 and to_time/1. When the input is a string, it is expected to be in iso 8601 format, although it can also handle timestamps without time zones. The time component of the datetime is optional.
Convert a time to the local context time using the current timezone.
Convert a time to the local context time using the current timezone.
Return 'undefined' if a given date is invalid
Return the week-boundaries of a given date. WeekStart is optional, and determines on which day a week starts.
Return the date the current week starts (monday)
Types
-type date() :: calendar:date() | {integer(), 1..12, 1..31}.
-type datetime() :: calendar:datetime() | {{integer(), 1..12, 1..31}, {0..23, 0..59, 0..59}}.
-type ldom() :: 28 | 29 | 30 | 31.
-type month() :: 1..12.
-type timestamp() :: integer().
-type year() :: integer().
Functions
Translate a local time date to UNIX timestamp
Return the number of days in a certain year.
Return the absolute difference between two dates. Does not take daylight saving into account.
Format the current date according to the format and the timezone settings in the context.
Format a date according to the format and the timezone settings in the context.
Format the current date in UTC.
Format the date using the UTC timezone.
-spec maybe_fix_datetime(fixable_datetime() | undefined) -> datetime() | undefined.
Shift a date if the date falls outside the valid date or time ranges. Return undefined if the date could not be mapped to some valid date.
Return the month-boundaries of a given date
-spec msec() -> integer().
Return the millisec value of the current clock.
Return the date one day later.
Return the date one hour later.
Return the date one minute later.
Return the date one month later. Gives unpredictable results if the day doesn't exist in the next month. (eg. feb 30 will become feb 28).
Return the date one second later.
Return the date one week later.
Return the date one year later.
Return the date one day earlier.
Return the date one hour earlier.
Return the date one minute earlier.
Return the date one month earlier.
Return the date one second earlier.
Return the date one week earlier.
Return the date one year earlier.
Show a humanized version of a relative datetime. Like "4 months, 3 days ago".
Show a humanized version of a period between two dates. Like "4 months, 3 days ago".
Show a humanized version of a period between two dates. Like "4 months, 3 days ago". WhenText is a string containing a maximum of three tokens. Example "ago, now, in"
-spec timestamp() -> SecondsSince1970 when SecondsSince1970 :: integer().
Calculate the current UNIX timestamp (seconds since Jan 1, 1970)
Translate UNIX timestamp to local datetime.
-spec to_datetime(Input) -> calendar:datetime() | undefined when Input :: undefined | binary() | string() | integer() | calendar:datetime() | {Y :: integer(), M :: pos_integer(), D :: pos_integer()}.
Convert an input to a (universal) datetime, using to_date/1 and to_time/1. When the input is a string, it is expected to be in iso 8601 format, although it can also handle timestamps without time zones. The time component of the datetime is optional.
-spec to_local(DateTime, TimeZone) -> calendar:datetime() | undefined when DateTime :: calendar:datetime() | undefined | time_not_exists, TimeZone :: string() | binary() | z:context().
Convert a time to the local context time using the current timezone.
-spec to_utc(DateTime, TimeZone) -> calendar:datetime() | undefined when DateTime :: calendar:datetime() | undefined | time_not_exists, TimeZone :: string() | binary() | z:context().
Convert a time to the local context time using the current timezone.
Return 'undefined' if a given date is invalid
Return the week-boundaries of a given date. WeekStart is optional, and determines on which day a week starts.
Return the date the current week starts (monday)