moment_timezone-rails 0.0.3.2 → 0.0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab1870c6883b821833d2ce72ef342ce90a8e53fa
|
4
|
+
data.tar.gz: 8ba2a9a96f99ca3db903ac53358557991f91cbed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1eeca069699a685c76a879304e925adff11a745cc4c7fac65579cf4674e298c5f10246a3f0b484f31e66e9c46d80558ec525f414ac2b34128a0d409d9d99b15e
|
7
|
+
data.tar.gz: 4fd4972095c57cca92f0bfd4219afbae608c31cdfd040099bbe3db4ca055bc1cb6ead46cd8a01b74670d83ebb93be1640e38a07fe96d5301d073bd8d012f6c11
|
@@ -5,7 +5,7 @@ require 'moment_timezone/rails/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "moment_timezone-rails"
|
8
|
-
spec.version = "#{MomentTimezone::Rails::VERSION}
|
8
|
+
spec.version = "#{MomentTimezone::Rails::VERSION}"
|
9
9
|
spec.authors = ["Lim Victor"]
|
10
10
|
spec.email = ["github.victor@gmail.com"]
|
11
11
|
spec.description = "moment-timezone for Rails"
|
@@ -1,12 +1,12 @@
|
|
1
1
|
// moment-timezone.js
|
2
|
-
// version : 0.0.
|
2
|
+
// version : 0.0.4
|
3
3
|
// author : Tim Wood
|
4
4
|
// license : MIT
|
5
5
|
// github.com/timrwood/moment-timezone
|
6
6
|
|
7
7
|
(function () {
|
8
8
|
|
9
|
-
var VERSION = "0.0.
|
9
|
+
var VERSION = "0.0.4";
|
10
10
|
|
11
11
|
function onload(moment) {
|
12
12
|
var oldZoneName = moment.fn.zoneName,
|
@@ -26,6 +26,11 @@
|
|
26
26
|
DAY_RULE_DAY_OF_MONTH = 7,
|
27
27
|
DAY_RULE_LAST_WEEKDAY = 8;
|
28
28
|
|
29
|
+
if (moment.tz !== undefined) {
|
30
|
+
// Do not load moment-timezone a second time.
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
|
29
34
|
// converts time in the HH:mm:ss format to absolute number of minutes
|
30
35
|
function parseMinutes (input) {
|
31
36
|
input = input + '';
|
@@ -53,6 +58,9 @@
|
|
53
58
|
this.timeRule = +timeRule;
|
54
59
|
this.offset = parseMinutes(offset);
|
55
60
|
this.letters = letters || '';
|
61
|
+
this.date = memoize(this.date);
|
62
|
+
this.weekdayAfter = memoize(this.weekdayAfter);
|
63
|
+
this.lastWeekday = memoize(this.lastWeekday);
|
56
64
|
}
|
57
65
|
|
58
66
|
Rule.prototype = {
|
@@ -135,6 +143,7 @@
|
|
135
143
|
function RuleSet (name) {
|
136
144
|
this.name = name;
|
137
145
|
this.rules = [];
|
146
|
+
this.lastYearRule = memoize(this.lastYearRule);
|
138
147
|
}
|
139
148
|
|
140
149
|
RuleSet.prototype = {
|
@@ -252,6 +261,7 @@
|
|
252
261
|
this.offset = parseMinutes(offset);
|
253
262
|
this.ruleSet = ruleSet;
|
254
263
|
this.letters = letters;
|
264
|
+
this.lastRule = memoize(this.lastRule);
|
255
265
|
|
256
266
|
for (i = 0; i < untilArray.length; i++) {
|
257
267
|
untilArray[i] = +untilArray[i];
|
@@ -265,10 +275,7 @@
|
|
265
275
|
},
|
266
276
|
|
267
277
|
lastRule : function () {
|
268
|
-
|
269
|
-
this._lastRule = this.rule(this.until);
|
270
|
-
}
|
271
|
-
return this._lastRule;
|
278
|
+
return this.rule(this.until);
|
272
279
|
},
|
273
280
|
|
274
281
|
format : function (rule) {
|
@@ -288,6 +295,9 @@
|
|
288
295
|
this.name = normalizeName(name);
|
289
296
|
this.displayName = name;
|
290
297
|
this.zones = [];
|
298
|
+
this.zoneAndRule = memoize(this.zoneAndRule, function (mom) {
|
299
|
+
return +mom;
|
300
|
+
});
|
291
301
|
}
|
292
302
|
|
293
303
|
ZoneSet.prototype = {
|
@@ -328,6 +338,16 @@
|
|
328
338
|
Global Methods
|
329
339
|
************************************/
|
330
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
|
+
}
|
350
|
+
|
331
351
|
function addRules (rules) {
|
332
352
|
var i, j, rule;
|
333
353
|
for (i in rules) {
|
@@ -432,14 +452,14 @@
|
|
432
452
|
}
|
433
453
|
|
434
454
|
// overwrite moment.updateOffset
|
435
|
-
moment.updateOffset = function (mom) {
|
455
|
+
moment.updateOffset = function (mom, keepTime) {
|
436
456
|
var offset;
|
437
457
|
if (mom._z) {
|
438
458
|
offset = mom._z.offset(mom);
|
439
459
|
if (Math.abs(offset) < 16) {
|
440
460
|
offset = offset / 60;
|
441
461
|
}
|
442
|
-
mom.zone(offset);
|
462
|
+
mom.zone(offset, keepTime);
|
443
463
|
}
|
444
464
|
};
|
445
465
|
|
@@ -479,6 +499,9 @@
|
|
479
499
|
return oldZoneAbbr.call(this);
|
480
500
|
};
|
481
501
|
|
502
|
+
// Make sure moment's clone includes the newly added properties
|
503
|
+
moment.momentProperties._z = null;
|
504
|
+
|
482
505
|
moment.tz = function () {
|
483
506
|
var args = [], i, len = arguments.length - 1;
|
484
507
|
for (i = 0; i < len; i++) {
|
@@ -497,6 +520,10 @@
|
|
497
520
|
|
498
521
|
moment.tz.version = VERSION;
|
499
522
|
|
523
|
+
moment.tz.zoneExists = function (name) {
|
524
|
+
return getZoneSet(name).zones.length > 0;
|
525
|
+
};
|
526
|
+
|
500
527
|
// add default rule
|
501
528
|
defaultRule = addRule("- 0 9999 0 0 0 0 0 0");
|
502
529
|
|
@@ -505,9 +532,9 @@
|
|
505
532
|
|
506
533
|
if (typeof define === "function" && define.amd) {
|
507
534
|
define("moment-timezone", ["moment"], onload);
|
508
|
-
} else if (typeof window !== "undefined" && window.moment) {
|
509
|
-
onload(window.moment);
|
510
535
|
} else if (typeof module !== 'undefined') {
|
511
536
|
module.exports = onload(require('moment'));
|
537
|
+
} else if (typeof window !== "undefined" && window.moment) {
|
538
|
+
onload(window.moment);
|
512
539
|
}
|
513
540
|
}).apply(this);
|
@@ -1 +1 @@
|
|
1
|
-
(function(){function
|
1
|
+
(function(){function a(a){function c(a){a+="";var b=a.split(":"),c=~a.indexOf("-")?-1:1,d=Math.abs(+b[0]),e=parseInt(b[1],10)||0,f=parseInt(b[2],10)||0;return c*(60*d+e+f/60)}function d(a,b,d,e,f,g,h,i,j,l){this.name=a,this.startYear=+b,this.endYear=+d,this.month=+e,this.day=+f,this.dayRule=+g,this.time=c(h),this.timeRule=+i,this.offset=c(j),this.letters=l||"",this.date=k(this.date),this.weekdayAfter=k(this.weekdayAfter),this.lastWeekday=k(this.lastWeekday)}function e(a,b){this.rule=b,this.start=b.start(a)}function f(a,b){return a.isLast?-1:b.isLast?1:b.start-a.start}function g(a){this.name=a,this.rules=[],this.lastYearRule=k(this.lastYearRule)}function h(b,d,e,f,g,h){var i,j="string"==typeof g?g.split("_"):[9999];for(this.name=b,this.offset=c(d),this.ruleSet=e,this.letters=f,this.lastRule=k(this.lastRule),i=0;i<j.length;i++)j[i]=+j[i];this.until=a.utc(j).subtract("m",c(h))}function i(a,b){return a.until-b.until}function j(a){this.name=n(a),this.displayName=a,this.zones=[],this.zoneAndRule=k(this.zoneAndRule,function(a){return+a})}function k(a,b){var c={};return function(d){var e=b?b.apply(this,arguments):d;return e in c?c[e]:c[e]=a.apply(this,arguments)}}function l(a){var b,c,d;for(b in a)for(d=a[b],c=0;c<d.length;c++)m(b+" "+d[c])}function m(a){if(y[a])return y[a];var b=a.split(/\s/),c=n(b[0]),e=new d(c,b[1],b[2],b[3],b[4],b[5],b[6],b[7],b[8],b[9],b[10]);return y[a]=e,r(c).add(e),e}function n(a){return(a||"").toLowerCase().replace(/\//g,"_")}function o(a){var b,c,d;for(b in a)for(d=a[b],c=0;c<d.length;c++)q(b+" "+d[c])}function p(a){var b;for(b in a)C[n(b)]=n(a[b])}function q(a){if(A[a])return A[a];var b=a.split(/\s/),c=n(b[0]),d=new h(c,b[1],r(b[2]),b[3],b[4],b[5]);return A[a]=d,s(b[0]).add(d),d}function r(a){return a=n(a),z[a]||(z[a]=new g(a)),z[a]}function s(a){var b=n(a);return C[b]&&(b=C[b]),B[b]||(B[b]=new j(a)),B[b]}function t(a){a&&(a.zones&&o(a.zones),a.rules&&l(a.rules),a.links&&p(a.links))}function u(){var a,b=[];for(a in B)b.push(B[a]);return b}var v,w=a.fn.zoneName,x=a.fn.zoneAbbr,y={},z={},A={},B={},C={},D=1,E=2,F=7,G=8;if(void 0===a.tz)return d.prototype={contains:function(a){return a>=this.startYear&&a<=this.endYear},start:function(b){return b=Math.min(Math.max(b,this.startYear),this.endYear),a.utc([b,this.month,this.date(b),0,this.time])},date:function(a){return this.dayRule===F?this.day:this.dayRule===G?this.lastWeekday(a):this.weekdayAfter(a)},weekdayAfter:function(b){for(var c=this.day,d=a([b,this.month,1]).day(),e=this.dayRule+1-d;c>e;)e+=7;return e},lastWeekday:function(b){var c=this.day,d=c%7,e=a([b,this.month+1,1]).day(),f=a([b,this.month,1]).daysInMonth(),g=f+(d-(e-1))-7*~~(c/7);return d>=e&&(g-=7),g}},e.prototype={equals:function(a){return a&&a.rule===this.rule?Math.abs(a.start-this.start)<864e5:!1}},g.prototype={add:function(a){this.rules.push(a)},ruleYears:function(a,b){var c,d,g,h=a.year(),i=[];for(c=0;c<this.rules.length;c++)d=this.rules[c],d.contains(h)?i.push(new e(h,d)):d.contains(h+1)&&i.push(new e(h+1,d));return i.push(new e(h-1,this.lastYearRule(h-1))),b&&(g=new e(h-1,b.lastRule()),g.start=b.until.clone().utc(),g.isLast=b.ruleSet!==this,i.push(g)),i.sort(f),i},rule:function(a,b,c){var d,e,f,g,h,i=this.ruleYears(a,c),j=0;for(c&&(e=c.offset+c.lastRule().offset,f=9e4*Math.abs(e)),h=i.length-1;h>-1;h--)g=d,d=i[h],d.equals(g)||(c&&!d.isLast&&Math.abs(d.start-c.until)<=f&&(j+=e-b),d.rule.timeRule===E&&(j=b),d.rule.timeRule!==D&&d.start.add("m",-j),j=d.rule.offset+b);for(h=0;h<i.length;h++)if(d=i[h],a>=d.start&&!d.isLast)return d.rule;return v},lastYearRule:function(a){var b,c,d,e=v,f=-1e30;for(b=0;b<this.rules.length;b++)c=this.rules[b],a>=c.startYear&&(d=c.start(a),d>f&&(f=d,e=c));return e}},h.prototype={rule:function(a,b){return this.ruleSet.rule(a,this.offset,b)},lastRule:function(){return this.rule(this.until)},format:function(a){return this.letters.replace("%s",a.letters)}},j.prototype={zoneAndRule:function(a){var b,c,d;for(a=a.clone().utc(),b=0;b<this.zones.length&&(c=this.zones[b],!(a<c.until));b++)d=c;return[c,c.rule(a,d)]},add:function(a){this.zones.push(a),this.zones.sort(i)},format:function(a){var b=this.zoneAndRule(a);return b[0].format(b[1])},offset:function(a){var b=this.zoneAndRule(a);return-(b[0].offset+b[1].offset)}},a.updateOffset=function(a,b){var c;a._z&&(c=a._z.offset(a),Math.abs(c)<16&&(c/=60),a.zone(c,b))},a.fn.tz=function(b){return b?(this._z=s(b),this._z&&a.updateOffset(this),this):this._z?this._z.displayName:void 0},a.fn.zoneName=function(){return this._z?this._z.format(this):w.call(this)},a.fn.zoneAbbr=function(){return this._z?this._z.format(this):x.call(this)},a.momentProperties._z=null,a.tz=function(){var b,c=[],d=arguments.length-1;for(b=0;d>b;b++)c[b]=arguments[b];var e=a.apply(null,c),f=e.zone();return e.tz(arguments[d]),e.add("minutes",e.zone()-f)},a.tz.add=t,a.tz.addRule=m,a.tz.addZone=q,a.tz.zones=u,a.tz.version=b,a.tz.zoneExists=function(a){return s(a).zones.length>0},v=m("- 0 9999 0 0 0 0 0 0"),a}var b="0.0.4";"function"==typeof define&&define.amd?define("moment-timezone",["moment"],a):"undefined"!=typeof module?module.exports=a(require("moment")):"undefined"!=typeof window&&window.moment&&a(window.moment)}).apply(this);
|
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: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lim Victor
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -81,5 +81,5 @@ rubyforge_project:
|
|
81
81
|
rubygems_version: 2.0.5
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
|
-
summary: moment-timezone-0.0.
|
84
|
+
summary: moment-timezone-0.0.4
|
85
85
|
test_files: []
|