extern crate chrono;
mod timezone_impl;
mod binary_search;
mod timezones;
mod directory;
pub use directory::*;
#[cfg(test)]
mod tests {
use super::America::Danmarkshavn;
use super::Etc::UTC;
use super::Europe::Berlin;
use super::Europe::London;
use super::Europe::Vilnius;
use super::Europe::Warsaw;
use super::Pacific::Apia;
use super::US::Eastern;
use chrono::{TimeZone, Duration};
#[test]
fn london_to_berlin() {
let dt = London.ymd(2016, 10, 8).and_hms(17, 0, 0);
let converted = dt.with_timezone(&Berlin);
let expected = Berlin.ymd(2016, 10, 8).and_hms(18, 0, 0);
assert_eq!(converted, expected);
}
#[test]
fn us_eastern_dst_commutativity() {
let dt = UTC.ymd(2002, 4, 7).and_hms(7, 0, 0);
for days in -420..720 {
let dt1 = (dt + Duration::days(days)).with_timezone(&Eastern);
let dt2 = dt.with_timezone(&Eastern) + Duration::days(days);
assert_eq!(dt1, dt2);
}
}
#[test]
fn warsaw_tz_name() {
let dt = UTC.ymd(1915, 8, 4).and_hms(22, 35, 59);
assert_eq!(dt.with_timezone(&Warsaw).format("%Z").to_string(), "WMT");
let dt = dt + Duration::seconds(1);
assert_eq!(dt.with_timezone(&Warsaw).format("%Z").to_string(), "CET");
}
#[test]
fn vilnius_utc_offset() {
let dt = UTC.ymd(1916, 12, 31).and_hms(22, 35, 59).with_timezone(&Vilnius);
assert_eq!(dt, Vilnius.ymd(1916, 12, 31).and_hms(23, 59, 59));
let dt = dt + Duration::seconds(1);
assert_eq!(dt, Vilnius.ymd(1917, 1, 1).and_hms(0, 11, 36));
}
#[test]
fn victorian_times() {
let dt = UTC.ymd(1847, 12, 1).and_hms(0, 1, 14).with_timezone(&London);
assert_eq!(dt, London.ymd(1847, 11, 30).and_hms(23, 59, 59));
let dt = dt + Duration::seconds(1);
assert_eq!(dt, London.ymd(1847, 12, 1).and_hms(0, 1, 15));
}
#[test]
fn london_dst() {
let dt = London.ymd(2016, 3, 10).and_hms(5, 0, 0);
let later = dt + Duration::days(180);
let expected = London.ymd(2016, 9, 6).and_hms(6, 0, 0);
assert_eq!(later, expected);
}
#[test]
fn international_date_line_change() {
let dt = UTC.ymd(2011, 12, 30).and_hms(9, 59, 59).with_timezone(&Apia);
assert_eq!(dt, Apia.ymd(2011, 12, 29).and_hms(23, 59, 59));
let dt = dt + Duration::seconds(1);
assert_eq!(dt, Apia.ymd(2011, 12, 31).and_hms(0, 0, 0));
}
#[test]
fn negative_offset_with_minutes_and_seconds() {
let dt = UTC.ymd(1900, 1, 1).and_hms(12, 0, 0).with_timezone(&Danmarkshavn);
assert_eq!(dt, Danmarkshavn.ymd(1900, 1, 1).and_hms(10, 45, 20));
}
#[test]
#[should_panic]
fn nonexistent_time() {
let _ = London.ymd(2016, 3, 27).and_hms(1, 30, 0);
}
#[test]
#[should_panic]
fn nonexistent_time_2() {
let _ = London.ymd(2016, 3, 27).and_hms(1, 0, 0);
}
#[test]
fn time_exists() {
let _ = London.ymd(2016, 3, 27).and_hms(2, 0, 0);
}
#[test]
#[should_panic]
fn ambiguous_time() {
let _ = London.ymd(2016, 10, 30).and_hms(1, 0, 0);
}
#[test]
#[should_panic]
fn ambiguous_time_2() {
let _ = London.ymd(2016, 10, 30).and_hms(1, 30, 0);
}
#[test]
fn unambiguous_time() {
let _ = London.ymd(2016, 10, 30); }
}