momentjs-rails 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +30 -0
- data/lib/momentjs-rails.rb +8 -0
- data/vendor/assets/javascripts/moment.js +624 -0
- metadata +61 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# momentjs-rails
|
2
|
+
|
3
|
+
momentjs-rails wraps the [Moment.js](http://momentjs.com/) library in a rails engine for simple
|
4
|
+
use with the asset pipeline provided by rails 3.1. The gem includes the development (non-minified)
|
5
|
+
source for ease of exploration. The asset pipeline will minify in production.
|
6
|
+
|
7
|
+
Moment.js is "a lightweight javascript date library for parsing, manipulating, and formatting dates."
|
8
|
+
Moment.js does not modify the native Date object. Rather, it creates a warpper for it. Please see the
|
9
|
+
[documentation](http://momentjs.com/docs/) for details.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Add the following to your gemfile:
|
14
|
+
|
15
|
+
gem 'momentjs-rails'
|
16
|
+
|
17
|
+
Add the following directive to your Javascript manifest file (application.js):
|
18
|
+
|
19
|
+
//= require moment
|
20
|
+
|
21
|
+
## Versioning
|
22
|
+
|
23
|
+
momentjs-rails 1.3.0 == Moment.js 1.3.0
|
24
|
+
|
25
|
+
Every attempt is made to mirror the currently shipping Momentum.js version number wherever possible.
|
26
|
+
The major and minor version numbers will always represent the Momentum.js version, but the patch level
|
27
|
+
may differ should a fix to gem need to be pushed before Moment.js ships an update to the library.
|
28
|
+
|
29
|
+
When the versions differ, it will be noted in the readme.
|
30
|
+
|
@@ -0,0 +1,624 @@
|
|
1
|
+
// Moment.js
|
2
|
+
//
|
3
|
+
// (c) 2011 Tim Wood
|
4
|
+
// Moment.js is freely distributable under the terms of the MIT license.
|
5
|
+
//
|
6
|
+
// Version 1.3.0
|
7
|
+
|
8
|
+
(function (Date, undefined) {
|
9
|
+
|
10
|
+
var moment,
|
11
|
+
round = Math.round,
|
12
|
+
languages = {},
|
13
|
+
hasModule = (typeof module !== 'undefined'),
|
14
|
+
paramsToParse = 'months|monthsShort|monthsParse|weekdays|weekdaysShort|longDateFormat|calendar|relativeTime|ordinal|meridiem'.split('|'),
|
15
|
+
i,
|
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,
|
17
|
+
nonuppercaseLetters = /[^A-Z]/g,
|
18
|
+
timezoneRegex = /\([A-Za-z ]+\)|:[0-9]{2} [A-Z]{3} /g,
|
19
|
+
tokenCharacters = /(\\)?(MM?M?M?|dd?d?d|DD?D?D?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|ZZ?|T)/g,
|
20
|
+
inputCharacters = /(\\)?([0-9]+|([a-zA-Z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+|([\+\-]\d\d:?\d\d))/gi,
|
21
|
+
timezoneParseRegex = /([\+\-]|\d\d)/gi,
|
22
|
+
VERSION = "1.3.0",
|
23
|
+
shortcuts = 'Month|Date|Hours|Minutes|Seconds|Milliseconds'.split('|');
|
24
|
+
|
25
|
+
// Moment prototype object
|
26
|
+
function Moment(date) {
|
27
|
+
this._d = date;
|
28
|
+
}
|
29
|
+
|
30
|
+
// left zero fill a number
|
31
|
+
// see http://jsperf.com/left-zero-filling for performance comparison
|
32
|
+
function leftZeroFill(number, targetLength) {
|
33
|
+
var output = number + '';
|
34
|
+
while (output.length < targetLength) {
|
35
|
+
output = '0' + output;
|
36
|
+
}
|
37
|
+
return output;
|
38
|
+
}
|
39
|
+
|
40
|
+
// helper function for _.addTime and _.subtractTime
|
41
|
+
function dateAddRemove(date, _input, adding, val) {
|
42
|
+
var isString = (typeof _input === 'string'),
|
43
|
+
input = isString ? {} : _input,
|
44
|
+
ms, d, M, currentDate;
|
45
|
+
if (isString && val) {
|
46
|
+
input[_input] = val;
|
47
|
+
}
|
48
|
+
ms = (input.ms || input.milliseconds || 0) +
|
49
|
+
(input.s || input.seconds || 0) * 1e3 + // 1000
|
50
|
+
(input.m || input.minutes || 0) * 6e4 + // 1000 * 60
|
51
|
+
(input.h || input.hours || 0) * 36e5; // 1000 * 60 * 60
|
52
|
+
d = (input.d || input.days || 0) +
|
53
|
+
(input.w || input.weeks || 0) * 7;
|
54
|
+
M = (input.M || input.months || 0) +
|
55
|
+
(input.y || input.years || 0) * 12;
|
56
|
+
if (ms) {
|
57
|
+
date.setTime(+date + ms * adding);
|
58
|
+
}
|
59
|
+
if (d) {
|
60
|
+
date.setDate(date.getDate() + d * adding);
|
61
|
+
}
|
62
|
+
if (M) {
|
63
|
+
currentDate = date.getDate();
|
64
|
+
date.setDate(1);
|
65
|
+
date.setMonth(date.getMonth() + M * adding);
|
66
|
+
date.setDate(Math.min(new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate(), currentDate));
|
67
|
+
}
|
68
|
+
return date;
|
69
|
+
}
|
70
|
+
|
71
|
+
// check if is an array
|
72
|
+
function isArray(input) {
|
73
|
+
return Object.prototype.toString.call(input) === '[object Array]';
|
74
|
+
}
|
75
|
+
|
76
|
+
// convert an array to a date.
|
77
|
+
// the array should mirror the parameters below
|
78
|
+
// note: all values past the year are optional and will default to the lowest possible value.
|
79
|
+
// [year, month, day , hour, minute, second, millisecond]
|
80
|
+
function dateFromArray(input) {
|
81
|
+
return new Date(input[0], input[1] || 0, input[2] || 1, input[3] || 0, input[4] || 0, input[5] || 0, input[6] || 0);
|
82
|
+
}
|
83
|
+
|
84
|
+
// format date using native date object
|
85
|
+
function formatDate(date, inputString) {
|
86
|
+
var m = new Moment(date),
|
87
|
+
currentMonth = m.month(),
|
88
|
+
currentDate = m.date(),
|
89
|
+
currentYear = m.year(),
|
90
|
+
currentDay = m.day(),
|
91
|
+
currentHours = m.hours(),
|
92
|
+
currentMinutes = m.minutes(),
|
93
|
+
currentSeconds = m.seconds(),
|
94
|
+
currentZone = m.zone(),
|
95
|
+
ordinal = moment.ordinal,
|
96
|
+
meridiem = moment.meridiem;
|
97
|
+
// check if the character is a format
|
98
|
+
// return formatted string or non string.
|
99
|
+
//
|
100
|
+
// uses switch/case instead of an object of named functions (like http://phpjs.org/functions/date:380)
|
101
|
+
// for minification and performance
|
102
|
+
// see http://jsperf.com/object-of-functions-vs-switch for performance comparison
|
103
|
+
function replaceFunction(input) {
|
104
|
+
// create a couple variables to be used later inside one of the cases.
|
105
|
+
var a, b;
|
106
|
+
switch (input) {
|
107
|
+
// MONTH
|
108
|
+
case 'M' :
|
109
|
+
return currentMonth + 1;
|
110
|
+
case 'Mo' :
|
111
|
+
return (currentMonth + 1) + ordinal(currentMonth + 1);
|
112
|
+
case 'MM' :
|
113
|
+
return leftZeroFill(currentMonth + 1, 2);
|
114
|
+
case 'MMM' :
|
115
|
+
return moment.monthsShort[currentMonth];
|
116
|
+
case 'MMMM' :
|
117
|
+
return moment.months[currentMonth];
|
118
|
+
// DAY OF MONTH
|
119
|
+
case 'D' :
|
120
|
+
return currentDate;
|
121
|
+
case 'Do' :
|
122
|
+
return currentDate + ordinal(currentDate);
|
123
|
+
case 'DD' :
|
124
|
+
return leftZeroFill(currentDate, 2);
|
125
|
+
// DAY OF YEAR
|
126
|
+
case 'DDD' :
|
127
|
+
a = new Date(currentYear, currentMonth, currentDate);
|
128
|
+
b = new Date(currentYear, 0, 1);
|
129
|
+
return ~~ (((a - b) / 864e5) + 1.5);
|
130
|
+
case 'DDDo' :
|
131
|
+
a = replaceFunction('DDD');
|
132
|
+
return a + ordinal(a);
|
133
|
+
case 'DDDD' :
|
134
|
+
return leftZeroFill(replaceFunction('DDD'), 3);
|
135
|
+
// WEEKDAY
|
136
|
+
case 'd' :
|
137
|
+
return currentDay;
|
138
|
+
case 'do' :
|
139
|
+
return currentDay + ordinal(currentDay);
|
140
|
+
case 'ddd' :
|
141
|
+
return moment.weekdaysShort[currentDay];
|
142
|
+
case 'dddd' :
|
143
|
+
return moment.weekdays[currentDay];
|
144
|
+
// WEEK OF YEAR
|
145
|
+
case 'w' :
|
146
|
+
a = new Date(currentYear, currentMonth, currentDate - currentDay + 5);
|
147
|
+
b = new Date(a.getFullYear(), 0, 4);
|
148
|
+
return ~~ ((a - b) / 864e5 / 7 + 1.5);
|
149
|
+
case 'wo' :
|
150
|
+
a = replaceFunction('w');
|
151
|
+
return a + ordinal(a);
|
152
|
+
case 'ww' :
|
153
|
+
return leftZeroFill(replaceFunction('w'), 2);
|
154
|
+
// YEAR
|
155
|
+
case 'YY' :
|
156
|
+
return leftZeroFill(currentYear % 100, 2);
|
157
|
+
case 'YYYY' :
|
158
|
+
return currentYear;
|
159
|
+
// AM / PM
|
160
|
+
case 'a' :
|
161
|
+
return currentHours > 11 ? meridiem.pm : meridiem.am;
|
162
|
+
case 'A' :
|
163
|
+
return currentHours > 11 ? meridiem.PM : meridiem.AM;
|
164
|
+
// 24 HOUR
|
165
|
+
case 'H' :
|
166
|
+
return currentHours;
|
167
|
+
case 'HH' :
|
168
|
+
return leftZeroFill(currentHours, 2);
|
169
|
+
// 12 HOUR
|
170
|
+
case 'h' :
|
171
|
+
return currentHours % 12 || 12;
|
172
|
+
case 'hh' :
|
173
|
+
return leftZeroFill(currentHours % 12 || 12, 2);
|
174
|
+
// MINUTE
|
175
|
+
case 'm' :
|
176
|
+
return currentMinutes;
|
177
|
+
case 'mm' :
|
178
|
+
return leftZeroFill(currentMinutes, 2);
|
179
|
+
// SECOND
|
180
|
+
case 's' :
|
181
|
+
return currentSeconds;
|
182
|
+
case 'ss' :
|
183
|
+
return leftZeroFill(currentSeconds, 2);
|
184
|
+
// TIMEZONE
|
185
|
+
case 'zz' :
|
186
|
+
// depreciating 'zz' fall through to 'z'
|
187
|
+
case 'z' :
|
188
|
+
return (date.toString().match(timezoneRegex) || [''])[0].replace(nonuppercaseLetters, '');
|
189
|
+
case 'Z' :
|
190
|
+
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(Math.abs(currentZone) / 60), 2) + ':' + leftZeroFill(~~(Math.abs(currentZone) % 60), 2);
|
191
|
+
case 'ZZ' :
|
192
|
+
return (currentZone > 0 ? '+' : '-') + leftZeroFill(~~(10 * Math.abs(currentZone) / 6), 4);
|
193
|
+
// LONG DATES
|
194
|
+
case 'L' :
|
195
|
+
case 'LL' :
|
196
|
+
case 'LLL' :
|
197
|
+
case 'LLLL' :
|
198
|
+
case 'LT' :
|
199
|
+
return formatDate(date, moment.longDateFormat[input]);
|
200
|
+
// DEFAULT
|
201
|
+
default :
|
202
|
+
return input.replace(/(^\[)|(\\)|\]$/g, "");
|
203
|
+
}
|
204
|
+
}
|
205
|
+
return inputString.replace(charactersToReplace, replaceFunction);
|
206
|
+
}
|
207
|
+
|
208
|
+
// date from string and format string
|
209
|
+
function makeDateFromStringAndFormat(string, format) {
|
210
|
+
var inArray = [0, 0, 1, 0, 0, 0, 0],
|
211
|
+
timezoneHours = 0,
|
212
|
+
timezoneMinutes = 0,
|
213
|
+
isUsingUTC = false,
|
214
|
+
inputParts = string.match(inputCharacters),
|
215
|
+
formatParts = format.match(tokenCharacters),
|
216
|
+
i,
|
217
|
+
isPm;
|
218
|
+
|
219
|
+
// function to convert string input to date
|
220
|
+
function addTime(format, input) {
|
221
|
+
var a;
|
222
|
+
switch (format) {
|
223
|
+
// MONTH
|
224
|
+
case 'M' :
|
225
|
+
// fall through to MM
|
226
|
+
case 'MM' :
|
227
|
+
inArray[1] = ~~input - 1;
|
228
|
+
break;
|
229
|
+
case 'MMM' :
|
230
|
+
// fall through to MMMM
|
231
|
+
case 'MMMM' :
|
232
|
+
for (a = 0; a < 12; a++) {
|
233
|
+
if (moment.monthsParse[a].test(input)) {
|
234
|
+
inArray[1] = a;
|
235
|
+
break;
|
236
|
+
}
|
237
|
+
}
|
238
|
+
break;
|
239
|
+
// DAY OF MONTH
|
240
|
+
case 'D' :
|
241
|
+
// fall through to DDDD
|
242
|
+
case 'DD' :
|
243
|
+
// fall through to DDDD
|
244
|
+
case 'DDD' :
|
245
|
+
// fall through to DDDD
|
246
|
+
case 'DDDD' :
|
247
|
+
inArray[2] = ~~input;
|
248
|
+
break;
|
249
|
+
// YEAR
|
250
|
+
case 'YY' :
|
251
|
+
input = ~~input;
|
252
|
+
inArray[0] = input + (input > 70 ? 1900 : 2000);
|
253
|
+
break;
|
254
|
+
case 'YYYY' :
|
255
|
+
inArray[0] = ~~Math.abs(input);
|
256
|
+
break;
|
257
|
+
// AM / PM
|
258
|
+
case 'a' :
|
259
|
+
// fall through to A
|
260
|
+
case 'A' :
|
261
|
+
isPm = (input.toLowerCase() === 'pm');
|
262
|
+
break;
|
263
|
+
// 24 HOUR
|
264
|
+
case 'H' :
|
265
|
+
// fall through to hh
|
266
|
+
case 'HH' :
|
267
|
+
// fall through to hh
|
268
|
+
case 'h' :
|
269
|
+
// fall through to hh
|
270
|
+
case 'hh' :
|
271
|
+
inArray[3] = ~~input;
|
272
|
+
break;
|
273
|
+
// MINUTE
|
274
|
+
case 'm' :
|
275
|
+
// fall through to mm
|
276
|
+
case 'mm' :
|
277
|
+
inArray[4] = ~~input;
|
278
|
+
break;
|
279
|
+
// SECOND
|
280
|
+
case 's' :
|
281
|
+
// fall through to ss
|
282
|
+
case 'ss' :
|
283
|
+
inArray[5] = ~~input;
|
284
|
+
break;
|
285
|
+
// TIMEZONE
|
286
|
+
case 'Z' :
|
287
|
+
// fall through to ZZ
|
288
|
+
case 'ZZ' :
|
289
|
+
isUsingUTC = true;
|
290
|
+
a = input.match(timezoneParseRegex);
|
291
|
+
if (a[1]) {
|
292
|
+
timezoneHours = ~~a[1];
|
293
|
+
}
|
294
|
+
if (a[2]) {
|
295
|
+
timezoneMinutes = ~~a[2];
|
296
|
+
}
|
297
|
+
// reverse offsets
|
298
|
+
if (a[0] === '-') {
|
299
|
+
timezoneHours = -timezoneHours;
|
300
|
+
timezoneMinutes = -timezoneMinutes;
|
301
|
+
}
|
302
|
+
break;
|
303
|
+
}
|
304
|
+
}
|
305
|
+
for (i = 0; i < formatParts.length; i++) {
|
306
|
+
addTime(formatParts[i], inputParts[i]);
|
307
|
+
}
|
308
|
+
// handle am pm
|
309
|
+
if (isPm && inArray[3] < 12) {
|
310
|
+
inArray[3] += 12;
|
311
|
+
}
|
312
|
+
// if is 12 am, change hours to 0
|
313
|
+
if (isPm === false && inArray[3] === 12) {
|
314
|
+
inArray[3] = 0;
|
315
|
+
}
|
316
|
+
// handle timezone
|
317
|
+
inArray[3] += timezoneHours;
|
318
|
+
inArray[4] += timezoneMinutes;
|
319
|
+
// return
|
320
|
+
return isUsingUTC ? new Date(Date.UTC.apply({}, inArray)) : dateFromArray(inArray);
|
321
|
+
}
|
322
|
+
|
323
|
+
// compare two arrays, return the number of differences
|
324
|
+
function compareArrays(array1, array2) {
|
325
|
+
var len = Math.min(array1.length, array2.length),
|
326
|
+
lengthDiff = Math.abs(array1.length - array2.length),
|
327
|
+
diffs = 0,
|
328
|
+
i;
|
329
|
+
for (i = 0; i < len; i++) {
|
330
|
+
if (~~array1[i] !== ~~array2[i]) {
|
331
|
+
diffs++;
|
332
|
+
}
|
333
|
+
}
|
334
|
+
return diffs + lengthDiff;
|
335
|
+
}
|
336
|
+
|
337
|
+
// date from string and array of format strings
|
338
|
+
function makeDateFromStringAndArray(string, formats) {
|
339
|
+
var output,
|
340
|
+
inputParts = string.match(inputCharacters),
|
341
|
+
scores = [],
|
342
|
+
scoreToBeat = 99,
|
343
|
+
i,
|
344
|
+
curDate,
|
345
|
+
curScore;
|
346
|
+
for (i = 0; i < formats.length; i++) {
|
347
|
+
curDate = makeDateFromStringAndFormat(string, formats[i]);
|
348
|
+
curScore = compareArrays(inputParts, formatDate(curDate, formats[i]).match(inputCharacters));
|
349
|
+
if (curScore < scoreToBeat) {
|
350
|
+
scoreToBeat = curScore;
|
351
|
+
output = curDate;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
return output;
|
355
|
+
}
|
356
|
+
|
357
|
+
moment = function (input, format) {
|
358
|
+
if (input === null) {
|
359
|
+
return null;
|
360
|
+
}
|
361
|
+
var date;
|
362
|
+
// parse UnderscoreDate object
|
363
|
+
if (input && input._d instanceof Date) {
|
364
|
+
date = new Date(+input._d);
|
365
|
+
// parse string and format
|
366
|
+
} else if (format) {
|
367
|
+
if (isArray(format)) {
|
368
|
+
date = makeDateFromStringAndArray(input, format);
|
369
|
+
} else {
|
370
|
+
date = makeDateFromStringAndFormat(input, format);
|
371
|
+
}
|
372
|
+
// parse everything else
|
373
|
+
} else {
|
374
|
+
date = input === undefined ? new Date() :
|
375
|
+
input instanceof Date ? input :
|
376
|
+
isArray(input) ? dateFromArray(input) :
|
377
|
+
new Date(input);
|
378
|
+
}
|
379
|
+
return new Moment(date);
|
380
|
+
};
|
381
|
+
|
382
|
+
// version number
|
383
|
+
moment.version = VERSION;
|
384
|
+
|
385
|
+
// language switching and caching
|
386
|
+
moment.lang = function (key, values) {
|
387
|
+
var i,
|
388
|
+
param,
|
389
|
+
req,
|
390
|
+
parse = [];
|
391
|
+
if (values) {
|
392
|
+
for (i = 0; i < 12; i++) {
|
393
|
+
parse[i] = new RegExp('^' + values.months[i] + '|^' + values.monthsShort[i].replace('.', ''), 'i');
|
394
|
+
}
|
395
|
+
values.monthsParse = values.monthsParse || parse;
|
396
|
+
languages[key] = values;
|
397
|
+
}
|
398
|
+
if (languages[key]) {
|
399
|
+
for (i = 0; i < paramsToParse.length; i++) {
|
400
|
+
param = paramsToParse[i];
|
401
|
+
moment[param] = languages[key][param] || moment[param];
|
402
|
+
}
|
403
|
+
} else {
|
404
|
+
if (hasModule) {
|
405
|
+
req = require('./lang/' + key);
|
406
|
+
moment.lang(key, req);
|
407
|
+
}
|
408
|
+
}
|
409
|
+
};
|
410
|
+
|
411
|
+
// set default language
|
412
|
+
moment.lang('en', {
|
413
|
+
months : "January_February_March_April_May_June_July_August_September_October_November_December".split("_"),
|
414
|
+
monthsShort : "Jan_Feb_Mar_Apr_May_Jun_Jul_Aug_Sep_Oct_Nov_Dec".split("_"),
|
415
|
+
weekdays : "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),
|
416
|
+
weekdaysShort : "Sun_Mon_Tue_Wed_Thu_Fri_Sat".split("_"),
|
417
|
+
longDateFormat : {
|
418
|
+
LT : "h:mm A",
|
419
|
+
L : "MM/DD/YYYY",
|
420
|
+
LL : "MMMM D YYYY",
|
421
|
+
LLL : "MMMM D YYYY LT",
|
422
|
+
LLLL : "dddd, MMMM D YYYY LT"
|
423
|
+
},
|
424
|
+
meridiem : {
|
425
|
+
AM : 'AM',
|
426
|
+
am : 'am',
|
427
|
+
PM : 'PM',
|
428
|
+
pm : 'pm'
|
429
|
+
},
|
430
|
+
calendar : {
|
431
|
+
sameDay : '[Today at] LT',
|
432
|
+
nextDay : '[Tomorrow at] LT',
|
433
|
+
nextWeek : 'dddd [at] LT',
|
434
|
+
lastDay : '[Yesterday at] LT',
|
435
|
+
lastWeek : '[last] dddd [at] LT',
|
436
|
+
sameElse : 'L'
|
437
|
+
},
|
438
|
+
relativeTime : {
|
439
|
+
future : "in %s",
|
440
|
+
past : "%s ago",
|
441
|
+
s : "a few seconds",
|
442
|
+
m : "a minute",
|
443
|
+
mm : "%d minutes",
|
444
|
+
h : "an hour",
|
445
|
+
hh : "%d hours",
|
446
|
+
d : "a day",
|
447
|
+
dd : "%d days",
|
448
|
+
M : "a month",
|
449
|
+
MM : "%d months",
|
450
|
+
y : "a year",
|
451
|
+
yy : "%d years"
|
452
|
+
},
|
453
|
+
ordinal : function (number) {
|
454
|
+
var b = number % 10;
|
455
|
+
return (~~ (number % 100 / 10) === 1) ? 'th' :
|
456
|
+
(b === 1) ? 'st' :
|
457
|
+
(b === 2) ? 'nd' :
|
458
|
+
(b === 3) ? 'rd' : 'th';
|
459
|
+
}
|
460
|
+
});
|
461
|
+
|
462
|
+
// helper function for _date.from() and _date.fromNow()
|
463
|
+
function substituteTimeAgo(string, number, withoutSuffix) {
|
464
|
+
var rt = moment.relativeTime[string];
|
465
|
+
return (typeof rt === 'function') ?
|
466
|
+
rt(number || 1, !!withoutSuffix, string) :
|
467
|
+
rt.replace(/%d/i, number || 1);
|
468
|
+
}
|
469
|
+
|
470
|
+
function relativeTime(milliseconds, withoutSuffix) {
|
471
|
+
var seconds = round(Math.abs(milliseconds) / 1000),
|
472
|
+
minutes = round(seconds / 60),
|
473
|
+
hours = round(minutes / 60),
|
474
|
+
days = round(hours / 24),
|
475
|
+
years = round(days / 365),
|
476
|
+
args = seconds < 45 && ['s', seconds] ||
|
477
|
+
minutes === 1 && ['m'] ||
|
478
|
+
minutes < 45 && ['mm', minutes] ||
|
479
|
+
hours === 1 && ['h'] ||
|
480
|
+
hours < 22 && ['hh', hours] ||
|
481
|
+
days === 1 && ['d'] ||
|
482
|
+
days <= 25 && ['dd', days] ||
|
483
|
+
days <= 45 && ['M'] ||
|
484
|
+
days < 345 && ['MM', round(days / 30)] ||
|
485
|
+
years === 1 && ['y'] || ['yy', years];
|
486
|
+
args[2] = withoutSuffix;
|
487
|
+
return substituteTimeAgo.apply({}, args);
|
488
|
+
}
|
489
|
+
|
490
|
+
// shortcut for prototype
|
491
|
+
moment.fn = Moment.prototype = {
|
492
|
+
|
493
|
+
clone : function () {
|
494
|
+
return moment(this);
|
495
|
+
},
|
496
|
+
|
497
|
+
valueOf : function () {
|
498
|
+
return +this._d;
|
499
|
+
},
|
500
|
+
|
501
|
+
'native' : function () {
|
502
|
+
return this._d;
|
503
|
+
},
|
504
|
+
|
505
|
+
toString : function () {
|
506
|
+
return this._d.toString();
|
507
|
+
},
|
508
|
+
|
509
|
+
toDate : function () {
|
510
|
+
return this._d;
|
511
|
+
},
|
512
|
+
|
513
|
+
format : function (inputString) {
|
514
|
+
return formatDate(this._d, inputString);
|
515
|
+
},
|
516
|
+
|
517
|
+
add : function (input, val) {
|
518
|
+
this._d = dateAddRemove(this._d, input, 1, val);
|
519
|
+
return this;
|
520
|
+
},
|
521
|
+
|
522
|
+
subtract : function (input, val) {
|
523
|
+
this._d = dateAddRemove(this._d, input, -1, val);
|
524
|
+
return this;
|
525
|
+
},
|
526
|
+
|
527
|
+
diff : function (input, val, asFloat) {
|
528
|
+
var inputMoment = moment(input),
|
529
|
+
diff = this._d - inputMoment._d,
|
530
|
+
year = this.year() - inputMoment.year(),
|
531
|
+
month = this.month() - inputMoment.month(),
|
532
|
+
day = this.day() - inputMoment.day(),
|
533
|
+
output;
|
534
|
+
if (val === 'months') {
|
535
|
+
output = year * 12 + month + day / 30;
|
536
|
+
} else if (val === 'years') {
|
537
|
+
output = year + month / 12;
|
538
|
+
} else {
|
539
|
+
output = val === 'seconds' ? diff / 1e3 : // 1000
|
540
|
+
val === 'minutes' ? diff / 6e4 : // 1000 * 60
|
541
|
+
val === 'hours' ? diff / 36e5 : // 1000 * 60 * 60
|
542
|
+
val === 'days' ? diff / 864e5 : // 1000 * 60 * 60 * 24
|
543
|
+
val === 'weeks' ? diff / 6048e5 : // 1000 * 60 * 60 * 24 * 7
|
544
|
+
val === 'days' ? diff / 3600 : diff;
|
545
|
+
}
|
546
|
+
return asFloat ? output : round(output);
|
547
|
+
},
|
548
|
+
|
549
|
+
from : function (time, withoutSuffix) {
|
550
|
+
var difference = this.diff(time),
|
551
|
+
rel = moment.relativeTime,
|
552
|
+
output = relativeTime(difference, withoutSuffix);
|
553
|
+
return withoutSuffix ? output : (difference <= 0 ? rel.past : rel.future).replace(/%s/i, output);
|
554
|
+
},
|
555
|
+
|
556
|
+
fromNow : function (withoutSuffix) {
|
557
|
+
return this.from(moment(), withoutSuffix);
|
558
|
+
},
|
559
|
+
|
560
|
+
calendar : function () {
|
561
|
+
var today = moment(),
|
562
|
+
todayAtZeroHour = moment([today.year(), today.month(), today.date()]),
|
563
|
+
diff = this.diff(todayAtZeroHour, 'days', true),
|
564
|
+
calendar = moment.calendar,
|
565
|
+
allElse = calendar.sameElse,
|
566
|
+
format = diff < -6 ? allElse :
|
567
|
+
diff < -1 ? calendar.lastWeek :
|
568
|
+
diff < 0 ? calendar.lastDay :
|
569
|
+
diff < 1 ? calendar.sameDay :
|
570
|
+
diff < 2 ? calendar.nextDay :
|
571
|
+
diff < 7 ? calendar.nextWeek : allElse;
|
572
|
+
return this.format(typeof format === 'function' ? format.apply(this) : format);
|
573
|
+
},
|
574
|
+
|
575
|
+
isLeapYear : function () {
|
576
|
+
var year = this.year();
|
577
|
+
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
|
578
|
+
},
|
579
|
+
|
580
|
+
isDST : function () {
|
581
|
+
return this.zone() !== moment([this.year()]).zone();
|
582
|
+
},
|
583
|
+
|
584
|
+
day : function (input) {
|
585
|
+
var day = this._d.getDay();
|
586
|
+
return input == null ? day :
|
587
|
+
this.add({ d : input - day });
|
588
|
+
}
|
589
|
+
};
|
590
|
+
|
591
|
+
// helper for adding shortcuts
|
592
|
+
function makeShortcut(name, key) {
|
593
|
+
moment.fn[name] = function (input) {
|
594
|
+
if (input != null) {
|
595
|
+
this._d['set' + key](input);
|
596
|
+
return this;
|
597
|
+
} else {
|
598
|
+
return this._d['get' + key]();
|
599
|
+
}
|
600
|
+
};
|
601
|
+
}
|
602
|
+
|
603
|
+
// loop through and add shortcuts (Month, Date, Hours, Minutes, Seconds, Milliseconds)
|
604
|
+
for (i = 0; i < shortcuts.length; i ++) {
|
605
|
+
makeShortcut(shortcuts[i].toLowerCase(), shortcuts[i]);
|
606
|
+
}
|
607
|
+
|
608
|
+
// add shortcut for year (uses different syntax than the getter/setter 'year' == 'FullYear')
|
609
|
+
makeShortcut('year', 'FullYear');
|
610
|
+
|
611
|
+
// add shortcut for timezone offset (no setter)
|
612
|
+
moment.fn.zone = function () {
|
613
|
+
return this._d.getTimezoneOffset();
|
614
|
+
};
|
615
|
+
|
616
|
+
// CommonJS module is defined
|
617
|
+
if (hasModule) {
|
618
|
+
module.exports = moment;
|
619
|
+
}
|
620
|
+
if (typeof window !== 'undefined') {
|
621
|
+
window.moment = moment;
|
622
|
+
}
|
623
|
+
|
624
|
+
})(Date);
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: momentjs-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.3.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Derek Prior
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: railties
|
16
|
+
requirement: &2168558080 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '3.1'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2168558080
|
25
|
+
description: ! " Moment.js is a lightweight javascript date library for parsing,
|
26
|
+
manipulating, and formatting dates.\n This gem allows for its easy inclusion
|
27
|
+
into the rails asset pipeline.\n"
|
28
|
+
email:
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/momentjs-rails.rb
|
34
|
+
- vendor/assets/javascripts/moment.js
|
35
|
+
- MIT-LICENSE
|
36
|
+
- README.md
|
37
|
+
homepage: https://github.com/derekprior/momentjs-rails
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.11
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: The Moment.js JavaScript library ready to play with Rails.
|
61
|
+
test_files: []
|