From a29ccb070b0587a59f4266d0524b25a4efe98ccd Mon Sep 17 00:00:00 2001 From: Tom Burdick Date: Wed, 25 May 2011 17:51:56 -0500 Subject: Add cowboy_cookies for cookie creation and parsing Based on Mochi Media, Inc.'s work in Mochiweb. Conflicts: rebar.config --- src/cowboy_clock.erl | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/cowboy_clock.erl') diff --git a/src/cowboy_clock.erl b/src/cowboy_clock.erl index e028559..333df94 100644 --- a/src/cowboy_clock.erl +++ b/src/cowboy_clock.erl @@ -21,7 +21,7 @@ -module(cowboy_clock). -behaviour(gen_server). --export([start_link/0, stop/0, rfc1123/0]). %% API. +-export([start_link/0, stop/0, rfc1123/0, rfc2109/1]). %% API. -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). %% gen_server. @@ -69,6 +69,29 @@ stop() -> rfc1123() -> ets:lookup_element(?TABLE, rfc1123, 2). +-spec rfc2109(datetime()) -> binary(). +rfc2109(LocalTime) -> + {{YYYY,MM,DD},{Hour,Min,Sec}} = + case calendar:local_time_to_universal_time_dst(LocalTime) of + [Gmt] -> Gmt; + [_,Gmt] -> Gmt + end, + Wday = calendar:day_of_the_week({YYYY,MM,DD}), + DayBin = pad_int(DD), + YearBin = list_to_binary(integer_to_list(YYYY)), + HourBin = pad_int(Hour), + MinBin = pad_int(Min), + SecBin = pad_int(Sec), + WeekDay = weekday(Wday), + Month = month(MM), + <>. + + %% gen_server. %% @private -- cgit v1.2.3