File tree 3 files changed +39
-10
lines changed
3 files changed +39
-10
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,11 @@ namespace('test', function () {
25
25
jake . mkdirP ( 'lib/tz' ) ;
26
26
jake . exec ( cmds , function ( ) {
27
27
console . log ( 'Retrieved new timezone data' ) ;
28
- complete ( ) ;
28
+ console . log ( 'Parsing tz...' ) ;
29
+ jake . exec ( 'node src/node-preparse.js lib/tz > lib/all_cities.json' , function ( ) {
30
+ console . log ( 'Done parsing tz' ) ;
31
+ complete ( ) ;
32
+ } , { printStdout : true , printStderr : true } ) ;
29
33
} , { printStdout : true } ) ;
30
34
} , { async : true } ) ;
31
35
Original file line number Diff line number Diff line change 1
1
var fs = require ( 'fs' ) ;
2
2
( function ( ) {
3
-
4
3
var root = this ;
5
4
6
5
var TestUtils = { } ;
@@ -18,13 +17,7 @@ var fs = require('fs');
18
17
for ( var k in ( options || { } ) ) {
19
18
opts [ k ] = options [ k ] ;
20
19
}
21
- //Reset everything
22
- timezoneJS . timezone . zones = { } ;
23
- timezoneJS . timezone . rules = { } ;
24
- timezoneJS . timezone . loadedZones = { } ;
25
-
26
- //Set up again
27
- timezoneJS . timezone . zoneFileBasePath = 'lib/tz' ;
20
+
28
21
timezoneJS . timezone . transport = function ( opts ) {
29
22
// No success handler, what's the point?
30
23
if ( opts . async ) {
@@ -36,12 +29,24 @@ var fs = require('fs');
36
29
}
37
30
return fs . readFileSync ( opts . url , 'utf8' ) ;
38
31
} ;
32
+
39
33
timezoneJS . timezone . loadingScheme = opts . loadingScheme ;
40
- timezoneJS . timezone . init ( opts ) ;
34
+ if ( opts . loadingScheme !== timezoneJS . timezone . loadingSchemes . MANUAL_LOAD ) {
35
+ //Set up again
36
+ timezoneJS . timezone . zoneFileBasePath = 'lib/tz' ;
37
+ timezoneJS . timezone . init ( opts ) ;
38
+ }
39
+
41
40
return timezoneJS ;
42
41
} ;
43
42
44
43
TestUtils . getTimezoneJS = function ( options ) {
44
+ //Delete date.js from require cache to force it to reload
45
+ for ( var k in require . cache ) {
46
+ if ( k . indexOf ( 'date.js' ) > - 1 ) {
47
+ delete require . cache [ k ] ;
48
+ }
49
+ }
45
50
return init ( require ( '../src/date' ) , options ) ;
46
51
}
47
52
Original file line number Diff line number Diff line change
1
+ var TestUtils = require ( './test-utils' )
2
+ , parseISO = TestUtils . parseISO
3
+ , date = require ( '../src/date' )
4
+ , timezoneJS = TestUtils . getTimezoneJS ( {
5
+ loadingScheme : date . timezone . loadingSchemes . MANUAL_LOAD
6
+ } ) ;
7
+ describe ( 'TimezoneJS' , function ( ) {
8
+ it ( 'should manually load everything correctly' , function ( ) {
9
+ var i = 0
10
+ , sampleTz ;
11
+
12
+ expect ( timezoneJS . timezone . loadingScheme ) . toEqual ( date . timezone . loadingSchemes . MANUAL_LOAD ) ;
13
+ //Let's load some stuff
14
+ timezoneJS . timezone . loadZoneJSONData ( 'lib/all_cities.json' , true ) ;
15
+ expect ( Object . keys ( timezoneJS . timezone . zones ) . length > 100 ) . toBeTruthy ( ) ;
16
+ sampleTz = timezoneJS . timezone . getTzInfo ( new Date ( ) , 'Asia/Bangkok' ) ;
17
+ expect ( sampleTz ) . toBeDefined ( ) ;
18
+ expect ( sampleTz . tzAbbr ) . toEqual ( 'ICT' ) ;
19
+ } ) ;
20
+ } ) ;
You can’t perform that action at this time.
0 commit comments