Module z_convert

Conversion functions for all kinds of data types.

Copyright © Copyright (c) 2008-2009 Rusty Klophaus, Copyright (c) 2009 Marc Worrell

Authors: Rusty Klophaus.

Description

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

Function Index

clean_lower/1Convert to lower case, strip surrounding whitespace.
convert_json/1Convert json from facebook favour to an easy to use format for zotonic templates.
ip_to_list/1
ip_to_long/1Convert an IP address from a string, IPv4 tuple or IPv6 tuple to the big endian integer representation.
long_to_ip/1Convert long int to IP address tuple.
to_atom/1Convert (almost) any value to an atom.
to_binary/1Convert (almost) any value to an atom.
to_binary/2
to_bool/1Quite loose conversion of values to boolean.
to_bool_strict/1Convert values to boolean values according to the Django rules.
to_date/1Convert an input to a date.
to_datetime/1Convert an input to a (universal) datetime, using to_date/1 and to_time/1.
to_flatlist/1Flatten list and convert to string.
to_float/1Convert (almost) any value to a float.
to_integer/1Convert (almost) any value to an integer.
to_isotime/1Convert a datetime (in universal time) to an ISO time string.
to_json/1Convert an Erlang structure to a format that can be serialized by mochijson.
to_list/1Convert (almost) any value to a list.
to_localtime/1Convert a utc date time to local.
to_time/1Convert an input to a time.
to_utc/1Convert a local date time to utc.
unicode_to_utf8/1

Function Details

clean_lower/1

clean_lower(L::binary() | list() | atom()) -> binary()

Convert to lower case, strip surrounding whitespace.

convert_json/1

convert_json(L) -> any()

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

ip_to_list/1

ip_to_list(IPv6) -> any()

ip_to_long/1

ip_to_long(X1::Address) -> {ok, integer()} | {error, badmatch}

Convert an IP address from a string, IPv4 tuple or IPv6 tuple to the big endian integer representation.

long_to_ip/1

long_to_ip(L) -> any()

Convert long int to IP address tuple. FIXME: ipv6

to_atom/1

to_atom(A::term()) -> atom() | undefined

Convert (almost) any value to an atom.

to_binary/1

to_binary(A::term()) -> binary()

Convert (almost) any value to an atom.

to_binary/2

to_binary(Tr, Context) -> any()

to_bool/1

to_bool(V::term()) -> boolean()

Quite loose conversion of values to boolean

to_bool_strict/1

to_bool_strict(M::term()) -> boolean()

Convert values to boolean values according to the Django rules

to_date/1

to_date(D::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/1

to_datetime(DT::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/1

to_flatlist(L::term()) -> string()

Flatten list and convert to string.

to_float/1

to_float(A::term()) -> float() | undefined

Convert (almost) any value to a float.

to_integer/1

to_integer(A::term()) -> integer() | undefined

Convert (almost) any value to an integer.

to_isotime/1

to_isotime(DateTime::z_dateformat:datetime()) -> binary()

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

to_json/1

to_json(X) -> any()

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

to_list/1

to_list(L::term()) -> string()

Convert (almost) any value to a list.

to_localtime/1

to_localtime(D::z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined

Convert a utc date time to local

to_time/1

to_time(D::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/1

to_utc(D::z_dateformat:datetime() | undefined) -> z_dateformat:datetime() | undefined

Convert a local date time to utc

unicode_to_utf8/1

unicode_to_utf8(List) -> any()


Generated by EDoc