File tree Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Expand file tree Collapse file tree 5 files changed +46
-3
lines changed Original file line number Diff line number Diff line change 21
21
global :
22
22
- LD_LIBRARY_PATH : /usr/local/lib
23
23
- CLIPPY : n
24
+ install :
25
+ - curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
24
26
script : ./ci/travis.sh
25
27
notifications :
26
28
email : false
Original file line number Diff line number Diff line change @@ -39,15 +39,16 @@ serde = { version = "1", optional = true }
39
39
wasm-bindgen = { version = " 0.2" }
40
40
js-sys = " 0.3" # contains FFI bindings for the JS Date API
41
41
42
-
43
-
44
42
[dev-dependencies ]
45
43
serde_json = { version = " 1" }
46
44
serde_derive = { version = " 1" }
47
45
bincode = { version = " 0.8.0" }
48
46
num-iter = { version = " 0.1.35" , default-features = false }
49
47
doc-comment = " 0.3"
50
48
49
+ [target .'cfg(target_arch = "wasm32")' .dev-dependencies ]
50
+ wasm-bindgen-test = " 0.2"
51
+
51
52
[package .metadata .docs .rs ]
52
53
all-features = true
53
54
Original file line number Diff line number Diff line change @@ -48,6 +48,16 @@ build_and_test() {
48
48
channel build -v --no-default-features --features serde,rustc-serialize
49
49
TZ=Asia/Katmandu channel test -v --no-default-features --features serde,rustc-serialize --lib
50
50
51
+ # wasm tests
52
+ touch tests/wasm.rs # ensure rebuild happens so TZ / NOW take effect
53
+ TZ=ACST-9:30 NOW=$( date +%s) wasm-pack test --node
54
+ touch tests/wasm.rs
55
+ TZ=EST4 NOW=$( date +%s) wasm-pack test --node
56
+ touch tests/wasm.rs
57
+ TZ=UTC0 NOW=$( date +%s) wasm-pack test --node
58
+ touch tests/wasm.rs
59
+ TZ=Asia/Katmandu NOW=$( date +%s) wasm-pack test --node
60
+
51
61
if [[ " $CHANNEL " == stable ]]; then
52
62
if [[ -n " $TRAVIS " ]] ; then
53
63
check_readme
Original file line number Diff line number Diff line change @@ -97,7 +97,10 @@ impl Local {
97
97
pub fn now ( ) -> DateTime < Local > {
98
98
use super :: Utc ;
99
99
let now: DateTime < Utc > = super :: Utc :: now ( ) ;
100
- now. with_timezone ( & Local )
100
+
101
+ // Workaround missing timezone logic in `time` crate
102
+ let offset = FixedOffset :: west ( ( js_sys:: Date :: new_0 ( ) . get_timezone_offset ( ) as i32 ) * 60 ) ;
103
+ DateTime :: from_utc ( now. naive_utc ( ) , offset)
101
104
}
102
105
}
103
106
Original file line number Diff line number Diff line change
1
+ extern crate chrono;
2
+ extern crate wasm_bindgen_test;
3
+
4
+ use chrono:: prelude:: * ;
5
+ use wasm_bindgen_test:: * ;
6
+
7
+ use std:: env;
8
+
9
+ #[ wasm_bindgen_test]
10
+ fn now ( ) {
11
+ let utc: DateTime < Utc > = Utc :: now ( ) ;
12
+ let local: DateTime < Local > = Local :: now ( ) ;
13
+
14
+ // Ensure time fetched is correct
15
+ let actual = Utc . datetime_from_str ( env ! ( "NOW" ) , "%s" ) . unwrap ( ) ;
16
+ assert ! ( utc - actual < chrono:: Duration :: minutes( 5 ) ) ;
17
+
18
+ // Ensure offset retrieved when getting local time is correct
19
+ let expected_offset = match env ! ( "TZ" ) {
20
+ "ACST-9:30" => FixedOffset :: east ( 19 * 30 * 60 ) ,
21
+ "Asia/Katmandu" => FixedOffset :: east ( 23 * 15 * 60 ) , // No DST thankfully
22
+ "EST4" => FixedOffset :: east ( -4 * 60 * 60 ) ,
23
+ "UTC0" => FixedOffset :: east ( 0 ) ,
24
+ _ => panic ! ( "unexpected TZ" ) ,
25
+ } ;
26
+ assert_eq ! ( & expected_offset, local. offset( ) ) ;
27
+ }
You can’t perform that action at this time.
0 commit comments