%%%------------------------------------------------------------------- %%% @author Fernando Benavides %%% @author Chad DePue %%% @copyright (C) 2011 InakaLabs SRL %%% @doc edis utilities %%% @end %%%------------------------------------------------------------------- -module(edis_util). -author('Fernando Benavides '). -author('Chad DePue '). -export([timestamp/0, now/0, upper/1]). -define(EPOCH, 62167219200). %% @doc Current timestamp -spec timestamp() -> float(). timestamp() -> ?MODULE:now() + element(3, erlang:timestamp()) / 1000000. %% @doc UTC in *NIX seconds -spec now() -> pos_integer(). now() -> calendar:datetime_to_gregorian_seconds(calendar:universal_time()) - ?EPOCH. %% @doc converts all characters in the specified binary to uppercase. -spec upper(binary()) -> binary(). upper(Bin) -> upper(Bin, <<>>). %% @private upper(<<>>, Acc) -> Acc; upper(<>, Acc) when $a =< C, C =< $z -> upper(Rest, <>); upper(<<195, C, Rest/binary>>, Acc) when 160 =< C, C =< 182 -> %% A-0 with tildes plus enye upper(Rest, <>); upper(<<195, C, Rest/binary>>, Acc) when 184 =< C, C =< 190 -> %% U and Y with tilde plus greeks upper(Rest, <>); upper(<>, Acc) -> upper(Rest, <>).