1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use std::marker::PhantomData;
use webcore::try_from::TryInto;

/// [(JavaScript docs)](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Date)
#[derive(Debug)]
pub struct Date {
    dummy: PhantomData< () >
}

impl Date {
    /// The Date.now() method returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC.
    ///
    /// [(JavaScript docs)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now)
    pub fn now() -> f64 {
        js!(
            return Date.now();
        ).try_into().unwrap()
    }
}

#[test]
fn test_date_now() {
    let now = Date::now();
    assert!( now > 0.0 );
}