z_convert (zotonic_stdlib v1.29.0)

View Source

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 IPv4 or IPv6 tuple to the big endian integer representation.

Convert long int to IPv4 or IPv6 address tuple. Note that IP addresses fitting in the 32 bit IPv4 address space are always converted to IPv4 tuples. Integers outside the IPv4 address space are converted to IPv6 tuples. Error badarg is returned for negative integers and integers larger than the maximum 128 bit integer.

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

clean_lower(L)

-spec clean_lower(binary() | list() | atom()) -> binary().

Convert to lower case, strip surrounding whitespace.

convert_json(L)

Convert json from facebook favour to an easy to use format for zotonic templates.

ip_to_list(IPv6)

ip_to_long(_)

-spec ip_to_long(inet:ip_address()) -> {ok, integer()} | {error, badmatch}.

Convert an IPv4 or IPv6 tuple to the big endian integer representation.

long_to_ip(L)

-spec long_to_ip(integer()) -> {ok, inet:ip_address()} | {error, badmatch}.

Convert long int to IPv4 or IPv6 address tuple. Note that IP addresses fitting in the 32 bit IPv4 address space are always converted to IPv4 tuples. Integers outside the IPv4 address space are converted to IPv6 tuples. Error badarg is returned for negative integers and integers larger than the maximum 128 bit integer.

to_atom(A)

-spec to_atom(term()) -> atom() | undefined.

Convert (almost) any value to an atom.

to_binary(A)

-spec to_binary(term()) -> binary().

Convert (almost) any value to an atom.

to_binary(Tr, Context)

to_bool(V)

-spec to_bool(term()) -> boolean().

Quite loose conversion of values to boolean

to_bool_strict(M)

-spec to_bool_strict(term()) -> boolean().

Convert values to boolean values according to the Django rules

to_date(D)

-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.

to_datetime(DT)

-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.

to_flatlist(L)

-spec to_flatlist(term()) -> string().

Flatten list and convert to string.

to_float(A)

-spec to_float(term()) -> float() | undefined.

Convert (almost) any value to a float.

to_integer(A)

-spec to_integer(term()) -> integer() | undefined.

Convert (almost) any value to an integer.

to_isotime(DateTime)

-spec to_isotime(z_dateformat:datetime()) -> binary().

Convert a datetime (in universal time) to an ISO time string.

to_json(X)

Convert an Erlang structure to a format that can be serialized by mochijson.

to_list(L)

-spec to_list(term()) -> string().

Convert (almost) any value to a list.

to_localtime(D)

-spec to_localtime(z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined.

Convert a utc date time to local

to_time(D)

-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.

to_utc(D)

-spec to_utc(z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined.

Convert a local date time to utc

unicode_to_utf8(List)