Chrono-TZ 0.1.2
Chrono-TZ
is a library that provides implementors of the
TimeZone
trait for rust-chrono
. The
impls are generated by a build script using the IANA database
and zoneinfo_parse
.
Documentation
Documentation is hosted on docs.rs
Usage
Put this in your Cargo.toml
:
[]
= "0.2"
= "0.1"
Then you will need to write (in your crate root):
extern crate chrono;
extern crate chrono_tz;
Examples
Create a time in one timezone and convert it to UTC
use ;
use US Pacific;
let pacific_time = Pacific.ymd.and_hms;
let utc_time = pacific_time.with_timezone;
assert_eq!;
London and New York change their clocks on different days in March so only have a 4-hour difference on certain days.
use TimeZone;
use London;
use New_York;
let london_time = London.ymd.and_hms;
let ny_time = london_time.with_timezone;
assert_eq!;
Adding 24 hours across a daylight savings change causes a change in local time
use ;
use London;
let dt = London.ymd.and_hms;
let later = dt + hours;
assert_eq!;
And of course you can always convert a local time to a unix timestamp
use TimeZone;
use Kolkata;
let dt = Kolkata.ymd.and_hms;
let timestamp = dt.timestamp;
assert_eq!;
Pretty-printing a string will use the correct abbreviation for the timezone
use TimeZone;
use London;
let dt = London.ymd.and_hms;
assert_eq!;
assert_eq!;
Known Issues
The timezone info for Dushanbe is not parsed correctly by zoneinfo_parse
and so I have modified that line slightly to correct it
# Tajikistan
# From Shanks & Pottenger.
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Dushanbe 4:35:12 - LMT 1924 May 2
5:00 - +05 1930 Jun 21
6:00 RussiaAsia +06/+07 1991 Mar 31 2:00s
5:00 1:00 +06 1991 Sep 9 2:00s # TODO: This is different to the source file but should be correct
5:00 - +05
Strings cannot be parsed into appropriate datetimes currently, they can only be printed out. Chrono handles fixed offsets only for parsing.
Currently no rustc-serialize or serde support.