aj a7b0adcbce repaired ezic_date:add_offset. able to normalize plain dates. notes and tests
add_offset was calculating DST differences wrong. It assumed to lose an hour, DST would be {-1,0,0}, in fact, DST went from {1,0,0} to {0,0,0}. add_offset now uses their differences (hence requires both as arguments)
normalize/2 was added to be able to set an arbitrary flag on a plain (i.e. native erlang datetime tuple) date. This is complicated by the fact that atoms "minimum", "max", etc. are still valid and need to fall through the normalization unaltered (for now).
2010-11-12 03:07:15 -08:00

ezic

ezic is a set of erlang utilities for the Olson timezone database files. See the tz database page for more information.

Status

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.

2010.11.04

  • ezic is "apparently functional". It has been tested very lightly, a bit by unit tests, but mostly by inspection. It's probably not fit for production use.

License

I have dedicated this work to the public domain. Anyone is free to copy, modify, publish, use, compile, sell, or distribute the original code, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

Contributed Code

To maintain ezic's status as a public domain work, all contributions must also be dedicated to the public domain.

API

  • ezic:localtime(TimeZone) -> datetime()
  • ezic:utc_to_time(universal_datetime(), TimeZone) -> local_datetime()
  • ezic:utc_from_time(local_datetime(), TimeZone) -> universal_datetime()
  • ezic:zone_convert(from_datetime(), TimeZoneFrom, TimeZoneTo) -> to_datetime()

Admin API

  • ezic:load("/path/to/tzdata") -> ok

Setup

# download the timezone data files
wget 'ftp://elsie.nci.nih.gov/pub/tzdata*.tar.gz'
tar -xvzf tzdata*.tar.gz -C /path/to/tzdata

# remove a few troublesome files
cd /path/to/tzdata
rm *.sh *.tab factory

# build and run ezic
make all run
1> ezic:load("/path/to/tzdata").
2> ezic:localtime("Australia/Adelaide").

Purpose

Erlang/OTP doesn't have a timezone library, so I decided to write one.

The recommended way 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:

  • it only works on *nix systems,
  • it depends on your system's timezone data (preventing custom timezone hackery), and
  • you can create race conditions if you aren't careful

ezic doesn't have these problems. ezic is, however, a young project with who-knows-how-many problems of its own ;)

Acknowledgements

I was inspired by the (anti-) license of the SQLite project in my decision to release this into the public domain.

Description
No description provided
Readme 206 KiB
Languages
Erlang 99.2%
Makefile 0.8%