2018-09-26 18:26:00 +03:00
|
|
|
use js_sys::*;
|
|
|
|
use wasm_bindgen::JsCast;
|
2018-07-20 22:07:26 +03:00
|
|
|
use wasm_bindgen::JsValue;
|
|
|
|
use wasm_bindgen_test::*;
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_date() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date.get_date(), 19);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_day() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date.get_day(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_full_year() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"July 20, 1969 00:20:18".into());
|
|
|
|
let abbr = Date::new(&"Thu, 06 Sep 12 00:00:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_full_year(), 1969);
|
|
|
|
assert_eq!(abbr.get_full_year(), 2012);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_hours() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"March 13, 08 04:20".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date.get_hours(), 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_milliseconds() {
|
2018-07-24 20:59:21 +03:00
|
|
|
let date = Date::new(&"1995-12-17T09:24:00Z".into());
|
|
|
|
let ms = Date::new(&"1995-12-17T09:24:00.123Z".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_milliseconds(), 0);
|
|
|
|
assert_eq!(ms.get_milliseconds(), 123);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_minutes() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"March 13, 08 04:20".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_minutes(), 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_month() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"July 20, 69 00:20:18".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_month(), 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_seconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"July 20, 69 00:20:18".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_seconds(), 18);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_time() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"July 20, 69 00:20:18 GMT+00:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_time(), -14254782000.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_timezone_offset() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+07:00".into());
|
|
|
|
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-02:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date1.get_timezone_offset(), date2.get_timezone_offset());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_date() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+11:00".into());
|
|
|
|
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-11:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date1.get_utc_date(), 19);
|
|
|
|
assert_eq!(date2.get_utc_date(), 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_day() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"August 19, 1975 23:15:30 GMT+11:00".into());
|
|
|
|
let date2 = Date::new(&"August 19, 1975 23:15:30 GMT-11:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date1.get_utc_day(), 2);
|
|
|
|
assert_eq!(date2.get_utc_day(), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_full_year() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
|
|
|
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date1.get_utc_full_year(), 1975);
|
|
|
|
assert_eq!(date2.get_utc_full_year(), 1976);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_hours() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
|
|
|
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date1.get_utc_hours(), 12);
|
|
|
|
assert_eq!(date2.get_utc_hours(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_milliseconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"2018-01-02T03:04:05.678Z".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date.get_utc_milliseconds(), 678);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_minutes() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"1 January 2000 03:15:30 GMT+07:00".into());
|
|
|
|
let date2 = Date::new(&"1 January 2000 03:15:30 GMT+03:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date1.get_utc_minutes(), 15);
|
|
|
|
assert_eq!(date2.get_utc_minutes(), 45);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_month() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date1 = Date::new(&"December 31, 1975, 23:15:30 GMT+11:00".into());
|
|
|
|
let date2 = Date::new(&"December 31, 1975, 23:15:30 GMT-11:00".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date1.get_utc_month(), 11);
|
|
|
|
assert_eq!(date2.get_utc_month(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn get_utc_seconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"July 20, 1969, 20:18:04 UTC".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date.get_utc_seconds(), 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn new() {
|
2018-07-26 00:33:44 +03:00
|
|
|
assert!(JsValue::from(Date::new(&JsValue::undefined())).is_object());
|
2018-07-20 22:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn now() {
|
|
|
|
assert!(Date::now() > 0.);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn parse() {
|
2018-07-26 02:50:30 +03:00
|
|
|
let date = Date::parse("04 Dec 1995 00:12:00 GMT");
|
|
|
|
let zero = Date::parse("01 Jan 1970 00:00:00 GMT");
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(date, 818035920000.0);
|
|
|
|
assert_eq!(zero, 0.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_date() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"August 24, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_date(24);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_date(), 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_full_year() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"August 19, 1976 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_full_year(1976);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_full_year(), 1976);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_hours() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"August 19, 1975 20:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_hours(20);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_hours(), 20);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_milliseconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event.set_milliseconds(456);
|
|
|
|
|
|
|
|
assert_eq!(ms, event.get_time());
|
|
|
|
assert_eq!(event.get_milliseconds(), 456);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_minutes() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"August 19, 1975 23:45:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_minutes(45);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_minutes(), 45);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_month() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"April 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_month(3);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_month(), 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_seconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
let event2 = Date::new(&"August 19, 1975 23:15:42".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_seconds(42);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_seconds(), 42);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_time() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"July 1, 1999".into());
|
|
|
|
let event2 = Date::new(&JsValue::undefined());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event2.set_time(event1.get_time());
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_date() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"August 19, 1975 02:15:30 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_date(19);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_date(), 19);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_full_year() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"January 01, 1975 02:15:30 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_full_year(1975);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_full_year(), 1975);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_hours() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"August 19, 1975 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"August 20, 1975 23:15:30 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_hours(23);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_hours(), 23);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_milliseconds() {
|
2018-07-24 20:59:21 +03:00
|
|
|
let event1 = Date::new(&"1995-12-17T09:24:00Z".into());
|
|
|
|
let event2 = Date::new(&"1995-12-17T09:24:00.420Z".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_milliseconds(420);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_milliseconds(), 420);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_minutes() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"December 31, 1975, 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"January 01, 1976 02:25:30 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_minutes(25);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_minutes(), 25);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_month() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"December 01, 1976 02:15:30 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_month(11);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_month(), 11);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn set_utc_seconds() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let event1 = Date::new(&"December 31, 1975 23:15:30 GMT-3:00".into());
|
|
|
|
let event2 = Date::new(&"January 01, 1976 02:15:39 GMT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
let ms = event1.set_utc_seconds(39);
|
|
|
|
|
|
|
|
assert_eq!(ms, event2.get_time());
|
|
|
|
assert_eq!(event1.get_time(), event2.get_time());
|
|
|
|
assert_eq!(event1.get_utc_seconds(), 39);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_date_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"05 October 2011 14:48 UTC".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(JsValue::from(date.to_date_string()), "Wed Oct 05 2011");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_iso_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"05 October 2011 14:48 UTC".into());
|
2018-09-26 18:26:00 +03:00
|
|
|
assert_eq!(
|
|
|
|
JsValue::from(date.to_iso_string()),
|
|
|
|
"2011-10-05T14:48:00.000Z"
|
|
|
|
);
|
2018-07-20 22:07:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_json() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
|
|
|
|
assert_eq!(JsValue::from(date.to_json()), "1975-08-19T23:15:30.000Z");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_locale_date_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
2018-07-26 02:50:30 +03:00
|
|
|
let s = date.to_locale_date_string("de-DE", &JsValue::undefined());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert!(s.length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_locale_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30 UTC".into());
|
2018-07-26 02:50:30 +03:00
|
|
|
let s = date.to_locale_string("de-DE", &JsValue::undefined());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert!(s.length() > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_locale_time_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(
|
2018-07-26 02:50:30 +03:00
|
|
|
JsValue::from(date.to_locale_time_string("en-US")),
|
2018-07-20 22:07:26 +03:00
|
|
|
"11:15:30 PM",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
let s = JsValue::from(date.to_string()).as_string().unwrap();
|
|
|
|
assert_eq!(&s[0..15], "Tue Aug 19 1975");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_time_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
let s = JsValue::from(date.to_time_string()).as_string().unwrap();
|
|
|
|
assert_eq!(&s[0..8], "23:15:30");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn to_utc_string() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&"14 Jun 2017 00:00:00 PDT".into());
|
2018-07-20 22:07:26 +03:00
|
|
|
let s = JsValue::from(date.to_utc_string()).as_string().unwrap();
|
|
|
|
assert_eq!(s, "Wed, 14 Jun 2017 07:00:00 GMT");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn utc() {
|
|
|
|
assert_eq!(Date::utc(2018f64, 6f64), 1530403200000.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn value_of() {
|
2018-07-26 00:33:44 +03:00
|
|
|
let date = Date::new(&Date::utc(2018f64, 6f64).into());
|
2018-07-20 22:07:26 +03:00
|
|
|
assert_eq!(date.value_of(), 1530403200000.0);
|
|
|
|
}
|
2018-08-09 05:49:06 +03:00
|
|
|
|
|
|
|
#[wasm_bindgen_test]
|
|
|
|
fn date_inheritance() {
|
|
|
|
let date = Date::new(&"August 19, 1975 23:15:30".into());
|
|
|
|
assert!(date.is_instance_of::<Date>());
|
|
|
|
assert!(date.is_instance_of::<Object>());
|
2018-08-17 23:09:30 +03:00
|
|
|
let _: &Object = date.as_ref();
|
2018-08-09 05:49:06 +03:00
|
|
|
}
|