diff --git a/Makefile b/Makefile index 13592e3..d9cc3d4 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ DEBUG := -DNODEBUG -Ddebug TEST := TZSET := northamerica SHELL := /bin/bash - +COMPILE := ./src/*.erl all : clean compile @@ -15,13 +15,14 @@ nowarn : clean compile test : ERLC_WARNINGS := -W0 -test : TEST := -DTEST -test : all - erlc $(ERLC_WARNINGS) $(TEST) -o ./ebin ./test/*.erl - erl -noshell -pa ebin -run test all -s erlang halt +test : TEST := -DTEST +test : RUN_INIT += -run test all -s erlang halt +test : COMPILE += ./test/*.erl +test : all run + compile : - erlc $(DEBUG) $(TEST) $(ERLC_WARNINGS) $(OPTIONS) -o ./ebin ./src/*.erl + erlc $(DEBUG) $(TEST) $(ERLC_WARNINGS) $(OPTIONS) -o ./ebin $(COMPILE) -erl -noshell -pa ebin -s erldev make_app . -s erlang halt clean : diff --git a/README.md b/README.md index f3104a7..06b6d5e 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,16 @@ ezic ==== -ezic is a set of erlang utilities for the Olson timezone database files. See the [tz database](http://www.twinsun.com/tz/tz-link.htm) page for more information. +ezic is an erlang libraary for working with timezones. It compiles the Olson timezone database files into native erlang terms, which makes timezone lookup and zone conversion very fast. See the [tz database](http://www.twinsun.com/tz/tz-link.htm) page for more information about the Olson database. Status ------ +2010.11.14 + + * The Zone/Rule flattening algorithm works correctly for a handful of tested zones. `ezic:local_to_utc/2` throws `ambiguous_zone` and `no_zone` errors where appropriate. Aside from bugs and edge cases that are sure to exist, and leap seconds, ezic is mostly functional. + 2010.11.07 * The time comparisons don't consider time relativity, so they're plain wrong. Within at least 24 hours of timechange or zone change, the results cannot be trusted. @@ -34,8 +38,8 @@ API --- * `ezic:localtime(TimeZone) -> datetime()` - * `ezic:utc_to_time(universal_datetime(), TimeZone) -> local_datetime()` - * `ezic:utc_from_time(local_datetime(), TimeZone) -> universal_datetime()` + * `ezic:utc_to_local(universal_datetime(), TimeZone) -> local_datetime()` + * `ezic:local_to_utc(local_datetime(), TimeZone) -> universal_datetime()` * `ezic:zone_convert(from_datetime(), TimeZoneFrom, TimeZoneTo) -> to_datetime()` @@ -69,7 +73,7 @@ Setup Purpose ------- -Erlang/OTP doesn't have a timezone library, so I decided to write one. +Erlang/OTP didn't have a timezone library, so I wrote ezic to fill that void. The [recommended way](http://www.erlang.org/pipermail/erlang-questions/2006-December/024291.html) of handling timezones in erlang involves setting the system environment variable `TZ` to the desired timezone, then calling erlang time functions. As far as I can tell, this technique has a few key issues: @@ -85,3 +89,5 @@ Acknowledgements ---------------- I was inspired by the (anti-) license of the [SQLite project](http://www.sqlite.org/copyright.html) in my decision to release this into the public domain. + + diff --git a/test/ezic_tests.erl b/test/ezic_tests.erl new file mode 100644 index 0000000..944c2f2 --- /dev/null +++ b/test/ezic_tests.erl @@ -0,0 +1,10 @@ +-module(ezic_tests). +-include("include/ezic.hrl"). +-include_lib("eunit/include/eunit.hrl"). + +local_to_utc_errors_test_() -> + ezic_db:init(), + [ + ?_assertError(ambiguous_zone, ezic:local_to_utc({{2010,11,7},{1,0,0}}, "America/Los_Angeles")) + , ?_assertError(no_zone, ezic:local_to_utc({{2010,3,14},{2,30,0}}, "America/Los_Angeles")) + ]. diff --git a/test/test.erl b/test/test.erl index af669d2..382ffd3 100644 --- a/test/test.erl +++ b/test/test.erl @@ -3,9 +3,19 @@ -include_lib("eunit/include/eunit.hrl"). all() -> - eunit:test(ezic_record) + setup(), + + eunit:test(ezic) + , eunit:test(ezic_record) , eunit:test(ezic_date) , eunit:test(ezic_zone) , eunit:test(ezic_parse) , eunit:test(ezic_rule) ,ok. + + +%% temporary db init because mnesia data gets corrupted between starting and stopping nodes. +setup()-> + ezic_db:init(), + ezic:load("priv/tzdata"), + ezic_flatten:flatten().