moment_timezone-rails 0.0.4 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab1870c6883b821833d2ce72ef342ce90a8e53fa
4
- data.tar.gz: 8ba2a9a96f99ca3db903ac53358557991f91cbed
3
+ metadata.gz: 34fb06044fcd232cebb6940b4e9d5ce0530b41db
4
+ data.tar.gz: cab067330843c1104899f723db40e86e4caaa31b
5
5
  SHA512:
6
- metadata.gz: 1eeca069699a685c76a879304e925adff11a745cc4c7fac65579cf4674e298c5f10246a3f0b484f31e66e9c46d80558ec525f414ac2b34128a0d409d9d99b15e
7
- data.tar.gz: 4fd4972095c57cca92f0bfd4219afbae608c31cdfd040099bbe3db4ca055bc1cb6ead46cd8a01b74670d83ebb93be1640e38a07fe96d5301d073bd8d012f6c11
6
+ metadata.gz: 80bc732d49f06ca3d0c22a2f55f67bfad3b383624cb3b6095b80d77f619d378136189cd6985663a105ee9e96760d4cac4bc10a252a36ef73649e823adba569c0
7
+ data.tar.gz: b7cb6f1fc57c8d86b728a2ca7f134134733e8c722ae7c05ea1ac0b63dae57ba36e40cc57cead49645dfbd878dd91399acc8c311dfe11d8349a9208182177ed83
data/README.md CHANGED
@@ -4,7 +4,13 @@
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ `momentjs-rails` need to be explicitly included in your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'momentjs-rails'
11
+ ```
12
+
13
+ Then add this line to your application's Gemfile:
8
14
 
9
15
  ```ruby
10
16
  gem 'moment_timezone-rails'
@@ -26,12 +32,30 @@ $ gem install moment_timezone-rails
26
32
 
27
33
  Add the following directives to `application.js`.
28
34
 
35
+ ### For v0.0.4 and below
36
+
29
37
  ```js
30
38
  //= require moment
31
39
  //= require moment-timezone
32
40
  //= require moment-timezone-data
33
41
  ```
34
42
 
43
+ ### For v0.1.0
44
+
45
+ ```js
46
+ //= require moment
47
+
48
+ // moment-timezone without timezone data
49
+ //= require moment-timezone
50
+
51
+ // moment-timezone with timezone data from 2010-2020
52
+ //= require moment-timezone-2010-2020
53
+
54
+ // moment-timezone all timezone data
55
+ //= require moment-timezone-all-years
56
+
57
+ ```
58
+
35
59
  ## Contributing
36
60
 
37
61
  1. Fork it
@@ -1,5 +1,5 @@
1
1
  module MomentTimezone
2
2
  module Rails
3
- VERSION = "0.0.4"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_development_dependency "rails", "~> 3.2.11"
21
+ spec.add_development_dependency "rails", "~> 3.2"
22
22
 
23
- spec.add_runtime_dependency "momentjs-rails", "~> 2.1"
23
+ spec.add_runtime_dependency "momentjs-rails", "~> 2.7"
24
24
  end
@@ -1,540 +1,330 @@
1
- // moment-timezone.js
2
- // version : 0.0.4
3
- // author : Tim Wood
4
- // license : MIT
5
- // github.com/timrwood/moment-timezone
6
-
7
- (function () {
8
-
9
- var VERSION = "0.0.4";
10
-
11
- function onload(moment) {
12
- var oldZoneName = moment.fn.zoneName,
13
- oldZoneAbbr = moment.fn.zoneAbbr,
1
+ //! moment-timezone.js
2
+ //! version : 0.1.0
3
+ //! author : Tim Wood
4
+ //! license : MIT
5
+ //! github.com/moment/moment-timezone
6
+
7
+ (function (root, factory) {
8
+ "use strict";
9
+
10
+ /*global define*/
11
+ if (typeof define === 'function' && define.amd) {
12
+ define(['moment'], factory); // AMD
13
+ } else if (typeof exports === 'object') {
14
+ module.exports = factory(require('moment')); // Node
15
+ } else {
16
+ factory(root.moment); // Browser
17
+ }
18
+ }(this, function (moment) {
19
+ "use strict";
14
20
 
15
- defaultRule,
16
- rules = {},
17
- ruleSets = {},
18
- zones = {},
19
- zoneSets = {},
20
- links = {},
21
+ // Do not load moment-timezone a second time.
22
+ if (moment.tz !== undefined) { return moment; }
21
23
 
22
- TIME_RULE_WALL_CLOCK = 0,
23
- TIME_RULE_UTC = 1,
24
- TIME_RULE_STANDARD = 2,
24
+ var VERSION = "0.1.0",
25
+ zones = {},
26
+ links = {};
25
27
 
26
- DAY_RULE_DAY_OF_MONTH = 7,
27
- DAY_RULE_LAST_WEEKDAY = 8;
28
+ /************************************
29
+ Unpacking
30
+ ************************************/
28
31
 
29
- if (moment.tz !== undefined) {
30
- // Do not load moment-timezone a second time.
31
- return;
32
+ function charCodeToInt(charCode) {
33
+ if (charCode > 96) {
34
+ return charCode - 87;
35
+ } else if (charCode > 64) {
36
+ return charCode - 29;
32
37
  }
38
+ return charCode - 48;
39
+ }
33
40
 
34
- // converts time in the HH:mm:ss format to absolute number of minutes
35
- function parseMinutes (input) {
36
- input = input + '';
37
- var output = input.split(':'),
38
- sign = ~input.indexOf('-') ? -1 : 1,
39
- hour = Math.abs(+output[0]),
40
- minute = parseInt(output[1], 10) || 0,
41
- second = parseInt(output[2], 10) || 0;
42
-
43
- return sign * ((hour * 60) + (minute) + (second / 60));
41
+ function unpackBase60(string) {
42
+ var i = 0,
43
+ parts = string.split('.'),
44
+ whole = parts[0],
45
+ fractional = parts[1] || '',
46
+ multiplier = 1,
47
+ num,
48
+ out = 0,
49
+ sign = 1;
50
+
51
+ // handle negative numbers
52
+ if (string.charCodeAt(0) === 45) {
53
+ i = 1;
54
+ sign = -1;
44
55
  }
45
56
 
46
- /************************************
47
- Rules
48
- ************************************/
49
-
50
- function Rule (name, startYear, endYear, month, day, dayRule, time, timeRule, offset, letters) {
51
- this.name = name;
52
- this.startYear = +startYear;
53
- this.endYear = +endYear;
54
- this.month = +month;
55
- this.day = +day;
56
- this.dayRule = +dayRule;
57
- this.time = parseMinutes(time);
58
- this.timeRule = +timeRule;
59
- this.offset = parseMinutes(offset);
60
- this.letters = letters || '';
61
- this.date = memoize(this.date);
62
- this.weekdayAfter = memoize(this.weekdayAfter);
63
- this.lastWeekday = memoize(this.lastWeekday);
57
+ // handle digits before the decimal
58
+ for (i; i < whole.length; i++) {
59
+ num = charCodeToInt(whole.charCodeAt(i));
60
+ out = 60 * out + num;
64
61
  }
65
62
 
66
- Rule.prototype = {
67
- contains : function (year) {
68
- return (year >= this.startYear && year <= this.endYear);
69
- },
70
-
71
- start : function (year) {
72
- year = Math.min(Math.max(year, this.startYear), this.endYear);
73
- return moment.utc([year, this.month, this.date(year), 0, this.time]);
74
- },
75
-
76
- date : function (year) {
77
- if (this.dayRule === DAY_RULE_DAY_OF_MONTH) {
78
- return this.day;
79
- } else if (this.dayRule === DAY_RULE_LAST_WEEKDAY) {
80
- return this.lastWeekday(year);
81
- }
82
- return this.weekdayAfter(year);
83
- },
84
-
85
- weekdayAfter : function (year) {
86
- var day = this.day,
87
- firstDayOfWeek = moment([year, this.month, 1]).day(),
88
- output = this.dayRule + 1 - firstDayOfWeek;
89
-
90
- while (output < day) {
91
- output += 7;
92
- }
93
-
94
- return output;
95
- },
96
-
97
- lastWeekday : function (year) {
98
- var day = this.day,
99
- dow = day % 7,
100
- lastDowOfMonth = moment([year, this.month + 1, 1]).day(),
101
- daysInMonth = moment([year, this.month, 1]).daysInMonth(),
102
- output = daysInMonth + (dow - (lastDowOfMonth - 1)) - (~~(day / 7) * 7);
103
-
104
- if (dow >= lastDowOfMonth) {
105
- output -= 7;
106
- }
107
- return output;
108
- }
109
- };
63
+ // handle digits after the decimal
64
+ for (i = 0; i < fractional.length; i++) {
65
+ multiplier = multiplier / 60;
66
+ num = charCodeToInt(fractional.charCodeAt(i));
67
+ out += num * multiplier;
68
+ }
110
69
 
111
- /************************************
112
- Rule Year
113
- ************************************/
70
+ return out * sign;
71
+ }
114
72
 
115
- function RuleYear (year, rule) {
116
- this.rule = rule;
117
- this.start = rule.start(year);
73
+ function arrayToInt (array) {
74
+ for (var i = 0; i < array.length; i++) {
75
+ array[i] = unpackBase60(array[i]);
118
76
  }
77
+ }
119
78
 
120
- RuleYear.prototype = {
121
- equals : function (other) {
122
- if (!other || other.rule !== this.rule) {
123
- return false;
124
- }
125
- return Math.abs(other.start - this.start) < 86400000; // 24 * 60 * 60 * 1000
126
- }
127
- };
128
-
129
- function sortRuleYears (a, b) {
130
- if (a.isLast) {
131
- return -1;
132
- }
133
- if (b.isLast) {
134
- return 1;
135
- }
136
- return b.start - a.start;
79
+ function intToUntil (array, length) {
80
+ for (var i = 0; i < length; i++) {
81
+ array[i] = Math.round((array[i - 1] || 0) + (array[i] * 60000)); // minutes to milliseconds
137
82
  }
138
83
 
139
- /************************************
140
- Rule Sets
141
- ************************************/
84
+ array[length - 1] = Infinity;
85
+ }
86
+
87
+ function mapIndices (source, indices) {
88
+ var out = [], i;
142
89
 
143
- function RuleSet (name) {
144
- this.name = name;
145
- this.rules = [];
146
- this.lastYearRule = memoize(this.lastYearRule);
90
+ for (i = 0; i < indices.length; i++) {
91
+ out[i] = source[indices[i]];
147
92
  }
148
93
 
149
- RuleSet.prototype = {
150
- add : function (rule) {
151
- this.rules.push(rule);
152
- },
153
-
154
- ruleYears : function (mom, lastZone) {
155
- var i, j,
156
- year = mom.year(),
157
- rule,
158
- lastZoneRule,
159
- rules = [];
160
-
161
- for (i = 0; i < this.rules.length; i++) {
162
- rule = this.rules[i];
163
- if (rule.contains(year)) {
164
- rules.push(new RuleYear(year, rule));
165
- } else if (rule.contains(year + 1)) {
166
- rules.push(new RuleYear(year + 1, rule));
167
- }
168
- }
169
- rules.push(new RuleYear(year - 1, this.lastYearRule(year - 1)));
94
+ return out;
95
+ }
170
96
 
171
- if (lastZone) {
172
- lastZoneRule = new RuleYear(year - 1, lastZone.lastRule());
173
- lastZoneRule.start = lastZone.until.clone().utc();
174
- lastZoneRule.isLast = lastZone.ruleSet !== this;
175
- rules.push(lastZoneRule);
176
- }
97
+ function unpack (string) {
98
+ var data = string.split('|'),
99
+ offsets = data[2].split(' '),
100
+ indices = data[3].split(''),
101
+ untils = data[4].split(' ');
177
102
 
178
- rules.sort(sortRuleYears);
179
- return rules;
180
- },
181
-
182
- rule : function (mom, offset, lastZone) {
183
- var rules = this.ruleYears(mom, lastZone),
184
- lastOffset = 0,
185
- rule,
186
- lastZoneOffset,
187
- lastZoneOffsetAbs,
188
- lastRule,
189
- i;
190
-
191
- if (lastZone) {
192
- lastZoneOffset = lastZone.offset + lastZone.lastRule().offset;
193
- lastZoneOffsetAbs = Math.abs(lastZoneOffset) * 90000;
194
- }
103
+ arrayToInt(offsets);
104
+ arrayToInt(indices);
105
+ arrayToInt(untils);
195
106
 
196
- // make sure to include the previous rule's offset
197
- for (i = rules.length - 1; i > -1; i--) {
198
- lastRule = rule;
199
- rule = rules[i];
107
+ intToUntil(untils, indices.length);
200
108
 
201
- if (rule.equals(lastRule)) {
202
- continue;
203
- }
109
+ return {
110
+ name : data[0],
111
+ abbrs : mapIndices(data[1].split(' '), indices),
112
+ offsets : mapIndices(offsets, indices),
113
+ untils : untils
114
+ };
115
+ }
204
116
 
205
- if (lastZone && !rule.isLast && Math.abs(rule.start - lastZone.until) <= lastZoneOffsetAbs) {
206
- lastOffset += lastZoneOffset - offset;
207
- }
117
+ /************************************
118
+ Zone object
119
+ ************************************/
208
120
 
209
- if (rule.rule.timeRule === TIME_RULE_STANDARD) {
210
- lastOffset = offset;
211
- }
121
+ function Zone (packedString) {
122
+ var unpacked = unpack(packedString);
123
+ this.name = unpacked.name;
124
+ this.abbrs = unpacked.abbrs;
125
+ this.untils = unpacked.untils;
126
+ this.offsets = unpacked.offsets;
127
+ }
212
128
 
213
- if (rule.rule.timeRule !== TIME_RULE_UTC) {
214
- rule.start.add('m', -lastOffset);
215
- }
129
+ Zone.prototype = {
130
+ _index : function (timestamp) {
131
+ var target = +timestamp,
132
+ untils = this.untils,
133
+ i;
216
134
 
217
- lastOffset = rule.rule.offset + offset;
135
+ for (i = 0; i < untils.length; i++) {
136
+ if (target < untils[i]) {
137
+ return i;
218
138
  }
139
+ }
140
+ },
219
141
 
220
- for (i = 0; i < rules.length; i++) {
221
- rule = rules[i];
222
- if (mom >= rule.start && !rule.isLast) {
223
- return rule.rule;
224
- }
225
- }
142
+ parse : function (timestamp) {
143
+ var target = +timestamp,
144
+ offsets = this.offsets,
145
+ untils = this.untils,
146
+ i;
226
147
 
227
- return defaultRule;
228
- },
229
-
230
- lastYearRule : function (year) {
231
- var i,
232
- rule,
233
- start,
234
- bestRule = defaultRule,
235
- largest = -1e30;
236
-
237
- for (i = 0; i < this.rules.length; i++) {
238
- rule = this.rules[i];
239
- if (year >= rule.startYear) {
240
- start = rule.start(year);
241
- if (start > largest) {
242
- largest = start;
243
- bestRule = rule;
244
- }
245
- }
148
+ for (i = 0; i < untils.length; i++) {
149
+ if (target < untils[i] - (offsets[i] * 60000)) {
150
+ return offsets[i];
246
151
  }
247
-
248
- return bestRule;
249
152
  }
250
- };
251
-
252
- /************************************
253
- Zone
254
- ************************************/
153
+ },
255
154
 
256
- function Zone (name, offset, ruleSet, letters, until, untilOffset) {
257
- var i,
258
- untilArray = typeof until === 'string' ? until.split('_') : [9999];
155
+ abbr : function (mom) {
156
+ return this.abbrs[this._index(mom)];
157
+ },
259
158
 
260
- this.name = name;
261
- this.offset = parseMinutes(offset);
262
- this.ruleSet = ruleSet;
263
- this.letters = letters;
264
- this.lastRule = memoize(this.lastRule);
265
-
266
- for (i = 0; i < untilArray.length; i++) {
267
- untilArray[i] = +untilArray[i];
268
- }
269
- this.until = moment.utc(untilArray).subtract('m', parseMinutes(untilOffset));
159
+ offset : function (mom) {
160
+ return this.offsets[this._index(mom)];
270
161
  }
162
+ };
271
163
 
272
- Zone.prototype = {
273
- rule : function (mom, lastZone) {
274
- return this.ruleSet.rule(mom, this.offset, lastZone);
275
- },
164
+ /************************************
165
+ Global Methods
166
+ ************************************/
276
167
 
277
- lastRule : function () {
278
- return this.rule(this.until);
279
- },
280
-
281
- format : function (rule) {
282
- return this.letters.replace("%s", rule.letters);
283
- }
284
- };
168
+ function normalizeName (name) {
169
+ return (name || '').toLowerCase().replace(/\//g, '_');
170
+ }
285
171
 
286
- /************************************
287
- Zone Set
288
- ************************************/
172
+ function addZone (packed) {
173
+ var i, zone;
289
174
 
290
- function sortZones (a, b) {
291
- return a.until - b.until;
175
+ if (typeof packed === "string") {
176
+ packed = [packed];
292
177
  }
293
178
 
294
- function ZoneSet (name) {
295
- this.name = normalizeName(name);
296
- this.displayName = name;
297
- this.zones = [];
298
- this.zoneAndRule = memoize(this.zoneAndRule, function (mom) {
299
- return +mom;
300
- });
179
+ for (i = 0; i < packed.length; i++) {
180
+ zone = new Zone(packed[i]);
181
+ zones[normalizeName(zone.name)] = zone;
301
182
  }
183
+ }
302
184
 
303
- ZoneSet.prototype = {
304
- zoneAndRule : function (mom) {
305
- var i,
306
- zone,
307
- lastZone;
308
-
309
- mom = mom.clone().utc();
310
- for (i = 0; i < this.zones.length; i++) {
311
- zone = this.zones[i];
312
- if (mom < zone.until) {
313
- break;
314
- }
315
- lastZone = zone;
316
- }
317
-
318
- return [zone, zone.rule(mom, lastZone)];
319
- },
320
-
321
- add : function (zone) {
322
- this.zones.push(zone);
323
- this.zones.sort(sortZones);
324
- },
185
+ function getZone (name) {
186
+ name = normalizeName(name);
187
+ var linkName = links[name];
325
188
 
326
- format : function (mom) {
327
- var zoneAndRule = this.zoneAndRule(mom);
328
- return zoneAndRule[0].format(zoneAndRule[1]);
329
- },
189
+ if (linkName && zones[linkName]) {
190
+ name = linkName;
191
+ }
330
192
 
331
- offset : function (mom) {
332
- var zoneAndRule = this.zoneAndRule(mom);
333
- return -(zoneAndRule[0].offset + zoneAndRule[1].offset);
334
- }
335
- };
193
+ return zones[name] || null;
194
+ }
336
195
 
337
- /************************************
338
- Global Methods
339
- ************************************/
340
-
341
- function memoize (fn, keyFn) {
342
- var cache = {};
343
- return function (first) {
344
- var key = keyFn ? keyFn.apply(this, arguments) : first;
345
- return key in cache ?
346
- cache[key] :
347
- (cache[key] = fn.apply(this, arguments));
348
- };
349
- }
196
+ function getNames () {
197
+ var i, out = [];
350
198
 
351
- function addRules (rules) {
352
- var i, j, rule;
353
- for (i in rules) {
354
- rule = rules[i];
355
- for (j = 0; j < rule.length; j++) {
356
- addRule(i + '\t' + rule[j]);
357
- }
199
+ for (i in zones) {
200
+ if (zones.hasOwnProperty(i) && zones[i]) {
201
+ out.push(zones[i].name);
358
202
  }
359
203
  }
360
204
 
361
- function addRule (ruleString) {
362
- // don't duplicate rules
363
- if (rules[ruleString]) {
364
- return rules[ruleString];
365
- }
366
-
367
- var p = ruleString.split(/\s/),
368
- name = normalizeName(p[0]),
369
- rule = new Rule(name, p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10]);
370
-
371
- // cache the rule so we don't add it again
372
- rules[ruleString] = rule;
205
+ return out.sort();
206
+ }
373
207
 
374
- // add to the ruleset
375
- getRuleSet(name).add(rule);
208
+ function addLink (aliases) {
209
+ var i, alias;
376
210
 
377
- return rule;
211
+ if (typeof aliases === "string") {
212
+ aliases = [aliases];
378
213
  }
379
214
 
380
- function normalizeName (name) {
381
- return (name || '').toLowerCase().replace(/\//g, '_');
215
+ for (i = 0; i < aliases.length; i++) {
216
+ alias = normalizeName(aliases[i]).split('|');
217
+ links[alias[0]] = alias[1];
218
+ links[alias[1]] = alias[0];
382
219
  }
220
+ }
383
221
 
384
- function addZones (zones) {
385
- var i, j, zone;
386
- for (i in zones) {
387
- zone = zones[i];
388
- for (j = 0; j < zone.length; j++) {
389
- addZone(i + '\t' + zone[j]);
390
- }
391
- }
392
- }
222
+ function loadData (data) {
223
+ addZone(data.zones);
224
+ addLink(data.links);
225
+ tz.dataVersion = data.version;
226
+ }
393
227
 
394
- function addLinks (linksToAdd) {
395
- var i;
396
- for (i in linksToAdd) {
397
- links[normalizeName(i)] = normalizeName(linksToAdd[i]);
228
+ function zoneExists (name) {
229
+ if (!zoneExists.didShowError) {
230
+ zoneExists.didShowError = true;
231
+ if (typeof console !== 'undefined' && typeof console.error === 'function') {
232
+ console.error("moment.tz.zoneExists('" + name + "') has been deprecated in favor of !moment.tz.zone('" + name + "')");
398
233
  }
399
234
  }
235
+ return !!getZone(name);
236
+ }
400
237
 
401
- function addZone (zoneString) {
402
- // don't duplicate zones
403
- if (zones[zoneString]) {
404
- return zones[zoneString];
405
- }
406
-
407
- var p = zoneString.split(/\s/),
408
- name = normalizeName(p[0]),
409
- zone = new Zone(name, p[1], getRuleSet(p[2]), p[3], p[4], p[5]);
238
+ function needsOffset (m) {
239
+ return !!(m._a && (m._tzm === undefined));
240
+ }
410
241
 
411
- // cache the zone so we don't add it again
412
- zones[zoneString] = zone;
242
+ /************************************
243
+ moment.tz namespace
244
+ ************************************/
413
245
 
414
- // add to the zoneset
415
- getZoneSet(p[0]).add(zone);
246
+ function tz () {
247
+ var args = Array.prototype.slice.call(arguments, 0, -1),
248
+ name = arguments[arguments.length - 1],
249
+ zone = getZone(name),
250
+ out = moment.utc.apply(null, args);
416
251
 
417
- return zone;
252
+ if (zone && needsOffset(out)) {
253
+ out.add('minutes', zone.parse(out));
418
254
  }
419
255
 
420
- function getRuleSet (name) {
421
- name = normalizeName(name);
422
- if (!ruleSets[name]) {
423
- ruleSets[name] = new RuleSet(name);
424
- }
425
- return ruleSets[name];
426
- }
256
+ out.tz(name);
427
257
 
428
- function getZoneSet (name) {
429
- var machineName = normalizeName(name);
430
- if (links[machineName]) {
431
- machineName = links[machineName];
432
- }
433
- if (!zoneSets[machineName]) {
434
- zoneSets[machineName] = new ZoneSet(name);
435
- }
436
- return zoneSets[machineName];
437
- }
438
-
439
- function add (data) {
440
- if (!data) {
441
- return;
442
- }
443
- if (data.zones) {
444
- addZones(data.zones);
445
- }
446
- if (data.rules) {
447
- addRules(data.rules);
448
- }
449
- if (data.links) {
450
- addLinks(data.links);
451
- }
452
- }
453
-
454
- // overwrite moment.updateOffset
455
- moment.updateOffset = function (mom, keepTime) {
456
- var offset;
457
- if (mom._z) {
458
- offset = mom._z.offset(mom);
459
- if (Math.abs(offset) < 16) {
460
- offset = offset / 60;
461
- }
462
- mom.zone(offset, keepTime);
463
- }
464
- };
258
+ return out;
259
+ }
465
260
 
466
- function getZoneSets() {
467
- var sets = [],
468
- zoneName;
469
- for (zoneName in zoneSets) {
470
- sets.push(zoneSets[zoneName]);
261
+ tz.version = VERSION;
262
+ tz.dataVersion = '';
263
+ tz._zones = zones;
264
+ tz._links = links;
265
+ tz.add = addZone;
266
+ tz.link = addLink;
267
+ tz.load = loadData;
268
+ tz.zone = getZone;
269
+ tz.zoneExists = zoneExists; // deprecated in 0.1.0
270
+ tz.names = getNames;
271
+ tz.Zone = Zone;
272
+ tz.unpack = unpack;
273
+ tz.unpackBase60 = unpackBase60;
274
+ tz.needsOffset = needsOffset;
275
+
276
+ /************************************
277
+ Interface with Moment.js
278
+ ************************************/
279
+
280
+ var fn = moment.fn;
281
+
282
+ moment.tz = tz;
283
+
284
+ moment.updateOffset = function (mom, keepTime) {
285
+ var offset;
286
+ if (mom._z) {
287
+ offset = mom._z.offset(mom);
288
+ if (Math.abs(offset) < 16) {
289
+ offset = offset / 60;
471
290
  }
472
- return sets;
291
+ mom.zone(offset, keepTime);
473
292
  }
293
+ };
474
294
 
475
- moment.fn.tz = function (name) {
476
- if (name) {
477
- this._z = getZoneSet(name);
478
- if (this._z) {
479
- moment.updateOffset(this);
480
- }
481
- return this;
482
- }
483
- if (this._z) {
484
- return this._z.displayName;
485
- }
486
- };
487
-
488
- moment.fn.zoneName = function () {
295
+ fn.tz = function (name) {
296
+ if (name) {
297
+ this._z = getZone(name);
489
298
  if (this._z) {
490
- return this._z.format(this);
299
+ moment.updateOffset(this);
491
300
  }
492
- return oldZoneName.call(this);
493
- };
301
+ return this;
302
+ }
303
+ if (this._z) { return this._z.name; }
304
+ };
494
305
 
495
- moment.fn.zoneAbbr = function () {
496
- if (this._z) {
497
- return this._z.format(this);
498
- }
499
- return oldZoneAbbr.call(this);
306
+ function abbrWrap (old) {
307
+ return function () {
308
+ if (this._z) { return this._z.abbr(this); }
309
+ return old.call(this);
500
310
  };
311
+ }
501
312
 
502
- // Make sure moment's clone includes the newly added properties
503
- moment.momentProperties._z = null;
504
-
505
- moment.tz = function () {
506
- var args = [], i, len = arguments.length - 1;
507
- for (i = 0; i < len; i++) {
508
- args[i] = arguments[i];
509
- }
510
- var m = moment.apply(null, args);
511
- var preTzOffset = m.zone();
512
- m.tz(arguments[len]);
513
- return m.add('minutes', m.zone() - preTzOffset);
313
+ function resetZoneWrap (old) {
314
+ return function () {
315
+ this._z = null;
316
+ return old.call(this);
514
317
  };
318
+ }
515
319
 
516
- moment.tz.add = add;
517
- moment.tz.addRule = addRule;
518
- moment.tz.addZone = addZone;
519
- moment.tz.zones = getZoneSets;
520
-
521
- moment.tz.version = VERSION;
522
-
523
- moment.tz.zoneExists = function (name) {
524
- return getZoneSet(name).zones.length > 0;
525
- };
320
+ fn.zoneName = abbrWrap(fn.zoneName);
321
+ fn.zoneAbbr = abbrWrap(fn.zoneAbbr);
322
+ fn.utc = resetZoneWrap(fn.utc);
526
323
 
527
- // add default rule
528
- defaultRule = addRule("- 0 9999 0 0 0 0 0 0");
324
+ // Cloning a moment should include the _z property.
325
+ moment.momentProperties._z = null;
529
326
 
530
- return moment;
531
- }
327
+ // INJECT DATA
532
328
 
533
- if (typeof define === "function" && define.amd) {
534
- define("moment-timezone", ["moment"], onload);
535
- } else if (typeof module !== 'undefined') {
536
- module.exports = onload(require('moment'));
537
- } else if (typeof window !== "undefined" && window.moment) {
538
- onload(window.moment);
539
- }
540
- }).apply(this);
329
+ return moment;
330
+ }));