View Source z_convert (zotonic_stdlib v1.20.2)

Conversion functions for all kinds of data types. Changes to Rusty's version: added date conversion, undefined handling and more to_bool cases.

Summary

Functions

Convert to lower case, strip surrounding whitespace.
Convert json from facebook favour to an easy to use format for zotonic templates.
Convert an IP address from a string, IPv4 tuple or IPv6 tuple to the big endian integer representation.
Convert long int to IP address tuple. FIXME: ipv6
Convert (almost) any value to an atom.
Convert (almost) any value to an atom.
Quite loose conversion of values to boolean
Convert values to boolean values according to the Django rules
Convert an input to a date. Input is expected to be YYYY-MM-DD or YYYY/MM/DD.
Convert an input to a (universal) datetime, using to_date/1 and to_time/1. If 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 datatime is optional.
Flatten list and convert to string.
Convert (almost) any value to a float.
Convert (almost) any value to an integer.
Convert a datetime (in universal time) to an ISO time string.
Convert an Erlang structure to a format that can be serialized by mochijson.
Convert (almost) any value to a list.
Convert a utc date time to local
Convert an input to a time. Input is expected to be HH:MM:SS or HH.MM.SS.
Convert a local date time to utc

Functions

-spec clean_lower(binary() | list() | atom()) -> binary().
Convert to lower case, strip surrounding whitespace.
Convert json from facebook favour to an easy to use format for zotonic templates.
Convert an IP address from a string, IPv4 tuple or IPv6 tuple to the big endian integer representation.
Convert long int to IP address tuple. FIXME: ipv6
-spec to_atom(term()) -> atom() | undefined.
Convert (almost) any value to an atom.
-spec to_binary(term()) -> binary().
Convert (almost) any value to an atom.
-spec to_bool(term()) -> boolean().
Quite loose conversion of values to boolean
-spec to_bool_strict(term()) -> boolean().
Convert values to boolean values according to the Django rules
-spec to_date(z_dateformat:date() | binary() | string() | undefined) -> z_dateformat:date() | undefined.
Convert an input to a date. Input is expected to be YYYY-MM-DD or YYYY/MM/DD.
-spec to_datetime(z_dateformat:datetime() | calendar:date() | binary() | string() | undefined) ->
               z_dateformat:datetime() | undefined.
Convert an input to a (universal) datetime, using to_date/1 and to_time/1. If 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 datatime is optional.
-spec to_flatlist(term()) -> string().
Flatten list and convert to string.
-spec to_float(term()) -> float() | undefined.
Convert (almost) any value to a float.
-spec to_integer(term()) -> integer() | undefined.
Convert (almost) any value to an integer.
-spec to_isotime(z_dateformat:datetime()) -> binary().
Convert a datetime (in universal time) to an ISO time string.
Convert an Erlang structure to a format that can be serialized by mochijson.
-spec to_list(term()) -> string().
Convert (almost) any value to a list.
-spec to_localtime(z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined.
Convert a utc date time to local
-spec to_time(calendar:time() | binary() | string() | undefined) -> calendar:time() | undefined.
Convert an input to a time. Input is expected to be HH:MM:SS or HH.MM.SS.
-spec to_utc(z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined.
Convert a local date time to utc