momentjs-rails 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +3 -5
- data/changelog.md +3 -0
- data/vendor/assets/javascripts/moment.js +145 -60
- metadata +4 -4
data/README.md
CHANGED
@@ -20,11 +20,9 @@ Add the following directive to your Javascript manifest file (application.js):
|
|
20
20
|
|
21
21
|
## Versioning
|
22
22
|
|
23
|
-
momentjs-rails 1.
|
23
|
+
momentjs-rails 1.5.0 == Moment.js 1.5.0
|
24
24
|
|
25
25
|
Every attempt is made to mirror the currently shipping Momentum.js version number wherever possible.
|
26
|
-
The major and
|
27
|
-
|
28
|
-
|
29
|
-
When the versions differ, it will be noted in the readme.
|
26
|
+
The major, minor, and patch version numbers will always represent the Momentum.js version. Should a gem
|
27
|
+
bug be discovered, a 4th version identifier will be added and incremented.
|
30
28
|
|
data/changelog.md
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
-
//
|
2
|
-
//
|
3
|
-
//
|
4
|
-
//
|
5
|
-
//
|
6
|
-
// Version 1.4.0
|
7
|
-
|
8
|
-
/*global define:false */
|
1
|
+
// moment.js
|
2
|
+
// version : 1.5.0
|
3
|
+
// author : Tim Wood
|
4
|
+
// license : MIT
|
5
|
+
// momentjs.com
|
9
6
|
|
10
7
|
(function (Date, undefined) {
|
11
8
|
|
@@ -15,19 +12,27 @@
|
|
15
12
|
hasModule = (typeof module !== 'undefined'),
|
16
13
|
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),
|
17
14
|
i,
|
18
|
-
jsonRegex = /^\/?Date\((
|
15
|
+
jsonRegex = /^\/?Date\((\-?\d+)/i,
|
19
16
|
charactersToReplace = /(\[[^\[]*\])|(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?|ZZ?|LT|LL?L?L?)/g,
|
20
17
|
nonuppercaseLetters = /[^A-Z]/g,
|
21
18
|
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,
|
22
19
|
tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,
|
23
20
|
inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,
|
21
|
+
isoRegex = /\d{4}.\d\d.\d\d(T(\d\d(.\d\d(.\d\d)?)?)?([\+\-]\d\d:?\d\d)?)?/,
|
22
|
+
isoFormat = 'YYYY-MM-DDTHH:mm:ssZ',
|
23
|
+
isoTimes = [
|
24
|
+
['HH:mm:ss', /T\d\d:\d\d:\d\d/],
|
25
|
+
['HH:mm', /T\d\d:\d\d/],
|
26
|
+
['HH', /T\d\d/]
|
27
|
+
],
|
24
28
|
timezoneParseRegex = /([\+\-]|\d\d)/gi,
|
25
|
-
VERSION = "1.
|
29
|
+
VERSION = "1.5.0",
|
26
30
|
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
|
27
31
|
|
28
32
|
// Moment prototype object
|
29
|
-
function Moment(date) {
|
33
|
+
function Moment(date, isUTC) {
|
30
34
|
this._d = date;
|
35
|
+
this._isUTC = !!isUTC;
|
31
36
|
}
|
32
37
|
|
33
38
|
// left zero fill a number
|
@@ -85,9 +90,8 @@
|
|
85
90
|
}
|
86
91
|
|
87
92
|
// format date using native date object
|
88
|
-
function
|
89
|
-
var
|
90
|
-
currentMonth = m.month(),
|
93
|
+
function formatMoment(m, inputString) {
|
94
|
+
var currentMonth = m.month(),
|
91
95
|
currentDate = m.date(),
|
92
96
|
currentYear = m.year(),
|
93
97
|
currentDay = m.day(),
|
@@ -188,18 +192,18 @@
|
|
188
192
|
case 'zz' :
|
189
193
|
// depreciating 'zz' fall through to 'z'
|
190
194
|
case 'z' :
|
191
|
-
return (
|
195
|
+
return (m._d.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, '');
|
192
196
|
case 'Z' :
|
193
|
-
return (currentZone
|
197
|
+
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2);
|
194
198
|
case 'ZZ' :
|
195
|
-
return (currentZone
|
199
|
+
return (currentZone < 0 ? '-' : '+') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4);
|
196
200
|
// LONG DATES
|
197
201
|
case 'L' :
|
198
202
|
case 'LL' :
|
199
203
|
case 'LLL' :
|
200
204
|
case 'LLLL' :
|
201
205
|
case 'LT' :
|
202
|
-
return
|
206
|
+
return formatMoment(m, moment.longDateFormat[input]);
|
203
207
|
// DEFAULT
|
204
208
|
default :
|
205
209
|
return input.replace(/(^\[)|(\\)|\]$/g, "");
|
@@ -216,6 +220,7 @@
|
|
216
220
|
isUsingUTC = false,
|
217
221
|
inputParts = string.match(inputCharacters),
|
218
222
|
formatParts = format.match(tokenCharacters),
|
223
|
+
len = Math.min(inputParts.length, formatParts.length),
|
219
224
|
i,
|
220
225
|
isPm;
|
221
226
|
|
@@ -305,7 +310,7 @@
|
|
305
310
|
break;
|
306
311
|
}
|
307
312
|
}
|
308
|
-
for (i = 0; i <
|
313
|
+
for (i = 0; i < len; i++) {
|
309
314
|
addTime(formatParts[i], inputParts[i]);
|
310
315
|
}
|
311
316
|
// handle am pm
|
@@ -348,7 +353,7 @@
|
|
348
353
|
curScore;
|
349
354
|
for (i = 0; i < formats.length; i++) {
|
350
355
|
curDate = makeDateFromStringAndFormat(string, formats[i]);
|
351
|
-
curScore = compareArrays(inputParts,
|
356
|
+
curScore = compareArrays(inputParts, formatMoment(new Moment(curDate), formats[i]).match(inputCharacters));
|
352
357
|
if (curScore < scoreToBeat) {
|
353
358
|
scoreToBeat = curScore;
|
354
359
|
output = curDate;
|
@@ -357,8 +362,52 @@
|
|
357
362
|
return output;
|
358
363
|
}
|
359
364
|
|
365
|
+
// date from iso format
|
366
|
+
function makeDateFromString(string) {
|
367
|
+
var format = 'YYYY-MM-DDT',
|
368
|
+
i;
|
369
|
+
if (isoRegex.exec(string)) {
|
370
|
+
for (i = 0; i < 3; i++) {
|
371
|
+
if (isoTimes[i][1].exec(string)) {
|
372
|
+
format += isoTimes[i][0];
|
373
|
+
break;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
return makeDateFromStringAndFormat(string, format + 'Z');
|
377
|
+
}
|
378
|
+
return new Date(string);
|
379
|
+
}
|
380
|
+
|
381
|
+
// helper function for _date.from() and _date.fromNow()
|
382
|
+
function substituteTimeAgo(string, number, withoutSuffix) {
|
383
|
+
var rt = moment.relativeTime[string];
|
384
|
+
return (typeof rt === 'function') ?
|
385
|
+
rt(number || 1, !!withoutSuffix, string) :
|
386
|
+
rt.replace(/%d/i, number || 1);
|
387
|
+
}
|
388
|
+
|
389
|
+
function relativeTime(milliseconds, withoutSuffix) {
|
390
|
+
var seconds = round(Math.abs(milliseconds) / 1000),
|
391
|
+
minutes = round(seconds / 60),
|
392
|
+
hours = round(minutes / 60),
|
393
|
+
days = round(hours / 24),
|
394
|
+
years = round(days / 365),
|
395
|
+
args = seconds < 45 && ['s', seconds] ||
|
396
|
+
minutes === 1 && ['m'] ||
|
397
|
+
minutes < 45 && ['mm', minutes] ||
|
398
|
+
hours === 1 && ['h'] ||
|
399
|
+
hours < 22 && ['hh', hours] ||
|
400
|
+
days === 1 && ['d'] ||
|
401
|
+
days <= 25 && ['dd', days] ||
|
402
|
+
days <= 45 && ['M'] ||
|
403
|
+
days < 345 && ['MM', round(days / 30)] ||
|
404
|
+
years === 1 && ['y'] || ['yy', years];
|
405
|
+
args[2] = withoutSuffix;
|
406
|
+
return substituteTimeAgo.apply({}, args);
|
407
|
+
}
|
408
|
+
|
360
409
|
moment = function (input, format) {
|
361
|
-
if (input === null) {
|
410
|
+
if (input === null || input === '') {
|
362
411
|
return null;
|
363
412
|
}
|
364
413
|
var date,
|
@@ -380,14 +429,61 @@
|
|
380
429
|
matched ? new Date(+matched[1]) :
|
381
430
|
input instanceof Date ? input :
|
382
431
|
isArray(input) ? dateFromArray(input) :
|
432
|
+
typeof input === 'string' ? makeDateFromString(input) :
|
383
433
|
new Date(input);
|
384
434
|
}
|
385
435
|
return new Moment(date);
|
386
436
|
};
|
387
437
|
|
438
|
+
// creating with utc
|
439
|
+
moment.utc = function (input, format) {
|
440
|
+
if (isArray(input)) {
|
441
|
+
return new Moment(new Date(Date.UTC.apply({}, input)), true);
|
442
|
+
}
|
443
|
+
return (format && input) ? moment(input + ' 0', format + ' Z').utc() : moment(input).utc();
|
444
|
+
};
|
445
|
+
|
446
|
+
// humanizeDuration
|
447
|
+
moment.humanizeDuration = function (num, type, withSuffix) {
|
448
|
+
var difference = +num,
|
449
|
+
rel = moment.relativeTime,
|
450
|
+
output;
|
451
|
+
switch (type) {
|
452
|
+
case "seconds" :
|
453
|
+
difference *= 1000; // 1000
|
454
|
+
break;
|
455
|
+
case "minutes" :
|
456
|
+
difference *= 60000; // 60 * 1000
|
457
|
+
break;
|
458
|
+
case "hours" :
|
459
|
+
difference *= 3600000; // 60 * 60 * 1000
|
460
|
+
break;
|
461
|
+
case "days" :
|
462
|
+
difference *= 86400000; // 24 * 60 * 60 * 1000
|
463
|
+
break;
|
464
|
+
case "weeks" :
|
465
|
+
difference *= 604800000; // 7 * 24 * 60 * 60 * 1000
|
466
|
+
break;
|
467
|
+
case "months" :
|
468
|
+
difference *= 2592000000; // 30 * 24 * 60 * 60 * 1000
|
469
|
+
break;
|
470
|
+
case "years" :
|
471
|
+
difference *= 31536000000; // 365 * 24 * 60 * 60 * 1000
|
472
|
+
break;
|
473
|
+
default :
|
474
|
+
withSuffix = !!type;
|
475
|
+
break;
|
476
|
+
}
|
477
|
+
output = relativeTime(difference, !withSuffix);
|
478
|
+
return withSuffix ? (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output) : output;
|
479
|
+
};
|
480
|
+
|
388
481
|
// version number
|
389
482
|
moment.version = VERSION;
|
390
483
|
|
484
|
+
// default format
|
485
|
+
moment.defaultFormat = isoFormat;
|
486
|
+
|
391
487
|
// language switching and caching
|
392
488
|
moment.lang = function (key, values) {
|
393
489
|
var i,
|
@@ -465,33 +561,10 @@
|
|
465
561
|
}
|
466
562
|
});
|
467
563
|
|
468
|
-
//
|
469
|
-
function
|
470
|
-
|
471
|
-
|
472
|
-
rt(number || 1, !!withoutSuffix, string) :
|
473
|
-
rt.replace(/%d/i, number || 1);
|
474
|
-
}
|
475
|
-
|
476
|
-
function relativeTime(milliseconds, withoutSuffix) {
|
477
|
-
var seconds = round(Math.abs(milliseconds) / 1000),
|
478
|
-
minutes = round(seconds / 60),
|
479
|
-
hours = round(minutes / 60),
|
480
|
-
days = round(hours / 24),
|
481
|
-
years = round(days / 365),
|
482
|
-
args = seconds < 45 && ['s', seconds] ||
|
483
|
-
minutes === 1 && ['m'] ||
|
484
|
-
minutes < 45 && ['mm', minutes] ||
|
485
|
-
hours === 1 && ['h'] ||
|
486
|
-
hours < 22 && ['hh', hours] ||
|
487
|
-
days === 1 && ['d'] ||
|
488
|
-
days <= 25 && ['dd', days] ||
|
489
|
-
days <= 45 && ['M'] ||
|
490
|
-
days < 345 && ['MM', round(days / 30)] ||
|
491
|
-
years === 1 && ['y'] || ['yy', years];
|
492
|
-
args[2] = withoutSuffix;
|
493
|
-
return substituteTimeAgo.apply({}, args);
|
494
|
-
}
|
564
|
+
// compare moment object
|
565
|
+
moment.isMoment = function (obj) {
|
566
|
+
return obj instanceof Moment;
|
567
|
+
};
|
495
568
|
|
496
569
|
// shortcut for prototype
|
497
570
|
moment.fn = Moment.prototype = {
|
@@ -516,8 +589,18 @@
|
|
516
589
|
return this._d;
|
517
590
|
},
|
518
591
|
|
592
|
+
utc : function () {
|
593
|
+
this._isUTC = true;
|
594
|
+
return this;
|
595
|
+
},
|
596
|
+
|
597
|
+
local : function () {
|
598
|
+
this._isUTC = false;
|
599
|
+
return this;
|
600
|
+
},
|
601
|
+
|
519
602
|
format : function (inputString) {
|
520
|
-
return
|
603
|
+
return formatMoment(this, inputString ? inputString : moment.defaultFormat);
|
521
604
|
},
|
522
605
|
|
523
606
|
add : function (input, val) {
|
@@ -554,10 +637,7 @@
|
|
554
637
|
},
|
555
638
|
|
556
639
|
from : function (time, withoutSuffix) {
|
557
|
-
|
558
|
-
rel = moment.relativeTime,
|
559
|
-
output = relativeTime(difference, withoutSuffix);
|
560
|
-
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
|
640
|
+
return moment.humanizeDuration(this.diff(time), !withoutSuffix);
|
561
641
|
},
|
562
642
|
|
563
643
|
fromNow : function (withoutSuffix) {
|
@@ -607,17 +687,26 @@
|
|
607
687
|
d : 1,
|
608
688
|
ms : -1
|
609
689
|
});
|
690
|
+
},
|
691
|
+
|
692
|
+
zone : function () {
|
693
|
+
return this._isUTC ? 0 : this._d.getTimezoneOffset();
|
694
|
+
},
|
695
|
+
|
696
|
+
daysInMonth : function () {
|
697
|
+
return this.clone().month(this.month() + 1).date(0).date();
|
610
698
|
}
|
611
699
|
};
|
612
700
|
|
613
701
|
// helper for adding shortcuts
|
614
702
|
function makeShortcut(name, key) {
|
615
703
|
moment.fn[name] = function (input) {
|
704
|
+
var utc = this._isUTC ? 'UTC' : '';
|
616
705
|
if (input != null) {
|
617
|
-
this._d['set' + key](input);
|
706
|
+
this._d['set' + utc + key](input);
|
618
707
|
return this;
|
619
708
|
} else {
|
620
|
-
return this._d['get' + key]();
|
709
|
+
return this._d['get' + utc + key]();
|
621
710
|
}
|
622
711
|
};
|
623
712
|
}
|
@@ -630,11 +719,6 @@
|
|
630
719
|
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
|
631
720
|
makeShortcut('year', 'FullYear');
|
632
721
|
|
633
|
-
// add shortcut for timezone offset (no setter)
|
634
|
-
moment.fn.zone = function () {
|
635
|
-
return this._d.getTimezoneOffset();
|
636
|
-
};
|
637
|
-
|
638
722
|
// CommonJS module is defined
|
639
723
|
if (hasModule) {
|
640
724
|
module.exports = moment;
|
@@ -642,6 +726,7 @@
|
|
642
726
|
if (typeof window !== 'undefined') {
|
643
727
|
window.moment = moment;
|
644
728
|
}
|
729
|
+
/*global define:false */
|
645
730
|
if (typeof define === "function" && define.amd) {
|
646
731
|
define("moment", [], function () {
|
647
732
|
return moment;
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: momentjs-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-03-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152697760 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152697760
|
25
25
|
description: ! " Moment.js is a lightweight javascript date library for parsing,
|
26
26
|
manipulating, and formatting dates.\n This gem allows for its easy inclusion
|
27
27
|
into the rails asset pipeline.\n"
|