Chrono-TZ 0.2.0
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!;
Create a naive datetime and convert it to a timezone-aware datetime
use ;
use Johannesburg;
let naive_dt = from_ymd.and_hms;
let tz_aware = Johannesburg.from_local_datetime.unwrap;
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 # "+06" was "+05/+06"
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.
- With the current version of
zoneinfo_parse
negative offsets with nonzero minutes and/or seconds are handled incorrectly. I have submitted a pull request to fix this bug.