2019-11-27 05:57:51 +00:00
|
|
|
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi"), feature = "wasmbind"))]
|
2019-08-16 17:11:30 +00:00
|
|
|
mod test {
|
|
|
|
extern crate chrono;
|
|
|
|
extern crate wasm_bindgen_test;
|
2019-08-16 09:35:56 +00:00
|
|
|
|
2019-08-16 17:11:30 +00:00
|
|
|
use self::chrono::prelude::*;
|
|
|
|
use self::wasm_bindgen_test::*;
|
2019-08-16 09:35:56 +00:00
|
|
|
|
2019-08-16 17:11:30 +00:00
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn now() {
|
|
|
|
let utc: DateTime<Utc> = Utc::now();
|
|
|
|
let local: DateTime<Local> = Local::now();
|
2019-08-16 09:35:56 +00:00
|
|
|
|
2019-08-16 17:11:30 +00:00
|
|
|
// Ensure time fetched is correct
|
|
|
|
let actual = Utc.datetime_from_str(env!("NOW"), "%s").unwrap();
|
|
|
|
assert!(utc - actual < chrono::Duration::minutes(5));
|
2019-08-16 09:35:56 +00:00
|
|
|
|
2019-08-16 17:11:30 +00:00
|
|
|
// Ensure offset retrieved when getting local time is correct
|
|
|
|
let expected_offset = match env!("TZ") {
|
|
|
|
"ACST-9:30" => FixedOffset::east(19 * 30 * 60),
|
|
|
|
"Asia/Katmandu" => FixedOffset::east(23 * 15 * 60), // No DST thankfully
|
|
|
|
"EST4" => FixedOffset::east(-4 * 60 * 60),
|
|
|
|
"UTC0" => FixedOffset::east(0),
|
|
|
|
_ => panic!("unexpected TZ"),
|
|
|
|
};
|
|
|
|
assert_eq!(&expected_offset, local.offset());
|
|
|
|
}
|
2019-08-16 09:35:56 +00:00
|
|
|
}
|