moment-timezone-rails 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  //! moment-timezone.js
2
- //! version : 0.5.14
2
+ //! version : 0.5.41
3
3
  //! Copyright (c) JS Foundation and other contributors
4
4
  //! license : MIT
5
5
  //! github.com/moment/moment-timezone
@@ -8,30 +8,40 @@
8
8
  "use strict";
9
9
 
10
10
  /*global define*/
11
- if (typeof define === 'function' && define.amd) {
12
- define(['moment'], factory); // AMD
13
- } else if (typeof module === 'object' && module.exports) {
11
+ if (typeof module === 'object' && module.exports) {
14
12
  module.exports = factory(require('moment')); // Node
13
+ } else if (typeof define === 'function' && define.amd) {
14
+ define(['moment'], factory); // AMD
15
15
  } else {
16
16
  factory(root.moment); // Browser
17
17
  }
18
18
  }(this, function (moment) {
19
19
  "use strict";
20
20
 
21
+ // Resolves es6 module loading issue
22
+ if (moment.version === undefined && moment.default) {
23
+ moment = moment.default;
24
+ }
25
+
21
26
  // Do not load moment-timezone a second time.
22
27
  // if (moment.tz !== undefined) {
23
28
  // logError('Moment Timezone ' + moment.tz.version + ' was already loaded ' + (moment.tz.dataVersion ? 'with data from ' : 'without any data') + moment.tz.dataVersion);
24
29
  // return moment;
25
30
  // }
26
31
 
27
- var VERSION = "0.5.14",
32
+ var VERSION = "0.5.41",
28
33
  zones = {},
29
34
  links = {},
35
+ countries = {},
30
36
  names = {},
31
37
  guesses = {},
32
- cachedGuess,
38
+ cachedGuess;
33
39
 
34
- momentVersion = moment.version.split('.'),
40
+ if (!moment || typeof moment.version !== 'string') {
41
+ logError('Moment Timezone requires Moment.js. See https://momentjs.com/timezone/docs/#/use-it/browser/');
42
+ }
43
+
44
+ var momentVersion = moment.version.split('.'),
35
45
  major = +momentVersion[0],
36
46
  minor = +momentVersion[1];
37
47
 
@@ -161,6 +171,13 @@
161
171
  }
162
172
  },
163
173
 
174
+ countries : function () {
175
+ var zone_name = this.name;
176
+ return Object.keys(countries).filter(function (country_code) {
177
+ return countries[country_code].zones.indexOf(zone_name) !== -1;
178
+ });
179
+ },
180
+
164
181
  parse : function (timestamp) {
165
182
  var target = +timestamp,
166
183
  offsets = this.offsets,
@@ -201,6 +218,15 @@
201
218
  }
202
219
  };
203
220
 
221
+ /************************************
222
+ Country object
223
+ ************************************/
224
+
225
+ function Country (country_name, zone_names) {
226
+ this.name = country_name;
227
+ this.zones = zone_names;
228
+ }
229
+
204
230
  /************************************
205
231
  Current Timezone
206
232
  ************************************/
@@ -288,7 +314,10 @@
288
314
  if (a.abbrScore !== b.abbrScore) {
289
315
  return a.abbrScore - b.abbrScore;
290
316
  }
291
- return b.zone.population - a.zone.population;
317
+ if (a.zone.population !== b.zone.population) {
318
+ return b.zone.population - a.zone.population;
319
+ }
320
+ return b.zone.name.localeCompare(a.zone.name);
292
321
  }
293
322
 
294
323
  function addToGuesses (name, offsets) {
@@ -393,6 +422,7 @@
393
422
  }
394
423
 
395
424
  function getZone (name, caller) {
425
+
396
426
  name = normalizeName(name);
397
427
 
398
428
  var zone = zones[name];
@@ -431,6 +461,10 @@
431
461
  return out.sort();
432
462
  }
433
463
 
464
+ function getCountryNames () {
465
+ return Object.keys(countries);
466
+ }
467
+
434
468
  function addLink (aliases) {
435
469
  var i, alias, normal0, normal1;
436
470
 
@@ -452,9 +486,49 @@
452
486
  }
453
487
  }
454
488
 
489
+ function addCountries (data) {
490
+ var i, country_code, country_zones, split;
491
+ if (!data || !data.length) return;
492
+ for (i = 0; i < data.length; i++) {
493
+ split = data[i].split('|');
494
+ country_code = split[0].toUpperCase();
495
+ country_zones = split[1].split(' ');
496
+ countries[country_code] = new Country(
497
+ country_code,
498
+ country_zones
499
+ );
500
+ }
501
+ }
502
+
503
+ function getCountry (name) {
504
+ name = name.toUpperCase();
505
+ return countries[name] || null;
506
+ }
507
+
508
+ function zonesForCountry(country, with_offset) {
509
+ country = getCountry(country);
510
+
511
+ if (!country) return null;
512
+
513
+ var zones = country.zones.sort();
514
+
515
+ if (with_offset) {
516
+ return zones.map(function (zone_name) {
517
+ var zone = getZone(zone_name);
518
+ return {
519
+ name: zone_name,
520
+ offset: zone.utcOffset(new Date())
521
+ };
522
+ });
523
+ }
524
+
525
+ return zones;
526
+ }
527
+
455
528
  function loadData (data) {
456
529
  addZone(data.zones);
457
530
  addLink(data.links);
531
+ addCountries(data.countries);
458
532
  tz.dataVersion = data.version;
459
533
  }
460
534
 
@@ -501,6 +575,7 @@
501
575
  tz._zones = zones;
502
576
  tz._links = links;
503
577
  tz._names = names;
578
+ tz._countries = countries;
504
579
  tz.add = addZone;
505
580
  tz.link = addLink;
506
581
  tz.load = loadData;
@@ -514,6 +589,8 @@
514
589
  tz.needsOffset = needsOffset;
515
590
  tz.moveInvalidForward = true;
516
591
  tz.moveAmbiguousForward = false;
592
+ tz.countries = getCountryNames;
593
+ tz.zonesForCountry = zonesForCountry;
517
594
 
518
595
  /************************************
519
596
  Interface with Moment.js
@@ -542,7 +619,9 @@
542
619
  offset = offset / 60;
543
620
  }
544
621
  if (mom.utcOffset !== undefined) {
622
+ var z = mom._z;
545
623
  mom.utcOffset(-offset, keepTime);
624
+ mom._z = z;
546
625
  } else {
547
626
  mom.zone(offset, keepTime);
548
627
  }
@@ -551,6 +630,9 @@
551
630
 
552
631
  fn.tz = function (name, keepTime) {
553
632
  if (name) {
633
+ if (typeof name !== 'string') {
634
+ throw new Error('Time zone name must be a string, got ' + name + ' [' + typeof name + ']');
635
+ }
554
636
  this._z = getZone(name);
555
637
  if (this._z) {
556
638
  moment.updateOffset(this, keepTime);
@@ -576,9 +658,18 @@
576
658
  };
577
659
  }
578
660
 
579
- fn.zoneName = abbrWrap(fn.zoneName);
580
- fn.zoneAbbr = abbrWrap(fn.zoneAbbr);
581
- fn.utc = resetZoneWrap(fn.utc);
661
+ function resetZoneWrap2 (old) {
662
+ return function () {
663
+ if (arguments.length > 0) this._z = null;
664
+ return old.apply(this, arguments);
665
+ };
666
+ }
667
+
668
+ fn.zoneName = abbrWrap(fn.zoneName);
669
+ fn.zoneAbbr = abbrWrap(fn.zoneAbbr);
670
+ fn.utc = resetZoneWrap(fn.utc);
671
+ fn.local = resetZoneWrap(fn.local);
672
+ fn.utcOffset = resetZoneWrap2(fn.utcOffset);
582
673
 
583
674
  moment.tz.setDefault = function(name) {
584
675
  if (major < 2 || (major === 2 && minor < 9)) {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: moment-timezone-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Fagan
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2023-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: momentjs-rails
@@ -42,6 +42,8 @@ files:
42
42
  - lib/moment-timezone-rails.rb
43
43
  - lib/moment_timezone_rails/engine.rb
44
44
  - lib/moment_timezone_rails/version.rb
45
+ - vendor/assets/javascripts/moment-timezone-with-data-10-year-range.js
46
+ - vendor/assets/javascripts/moment-timezone-with-data-1970-2030.js
45
47
  - vendor/assets/javascripts/moment-timezone-with-data-2012-2022.js
46
48
  - vendor/assets/javascripts/moment-timezone-with-data.js
47
49
  - vendor/assets/javascripts/moment-timezone.js
@@ -49,7 +51,7 @@ homepage: https://github.com/Bialogs/moment-timezone-rails
49
51
  licenses:
50
52
  - MIT
51
53
  metadata: {}
52
- post_install_message:
54
+ post_install_message:
53
55
  rdoc_options: []
54
56
  require_paths:
55
57
  - lib
@@ -64,9 +66,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
66
  - !ruby/object:Gem::Version
65
67
  version: '0'
66
68
  requirements: []
67
- rubyforge_project:
68
- rubygems_version: 2.7.6
69
- signing_key:
69
+ rubygems_version: 3.4.1
70
+ signing_key:
70
71
  specification_version: 4
71
- summary: moment-timezone-0.5.14
72
+ summary: moment-timezone-0.5.41
72
73
  test_files: []