strftime-rails 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e82c15e58b693d52f0a635d6d3ca506e85559fe
4
+ data.tar.gz: 3a322648025af32dad56f6c03e05dc284e479db7
5
+ SHA512:
6
+ metadata.gz: 169e6ca1769462694653e930349756643df9c01d94556f7cf4a8fc545a76c5ffbfbddd6360f8e7b33bc6747f3341412fe63fa1dff4527d4d443670d509bf8244
7
+ data.tar.gz: a11bf9e042669ca3e74a517ea38629846c9e07769366e5d766e04514dad85f0761d7fc609d8ef4e88e90f9c914869961d92572df8970c267e87a1b4b83ccf55e
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Cressman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,37 @@
1
+ strftime-rails
2
+ ================================================================================
3
+
4
+ [strftime](https://github.com/samsonjs/strftime) for JavaScript, packaged for
5
+ the Rails asset pipeline.
6
+
7
+
8
+ Usage
9
+ --------------------------------------------------------------------------------
10
+
11
+ Add the gem to your Gemfile:
12
+
13
+ gem 'strftime-rails'
14
+
15
+ Load the library within an asset manifest such as `application.js`:
16
+
17
+ //= require strftime-rails/strftime
18
+
19
+ If you've included the gem in your Gemfile, Bundler will generally take care of
20
+ `require`ing the necessary files, but if for some reason you need to manually
21
+ `require` the gem:
22
+
23
+ require 'strftime/rails'
24
+
25
+
26
+ Versioning
27
+ --------------------------------------------------------------------------------
28
+
29
+ The version number of the gem mirrors the version number of strftime. For
30
+ example:
31
+
32
+ gem 'strftime-rails', '1.1.1'
33
+
34
+ will add strftime version 1.1.1 to the asset pipeline.
35
+
36
+ Should a bug be discovered in the gem only, a fourth version identifier will be
37
+ added and incremented.
@@ -0,0 +1,2 @@
1
+ require 'strftime/rails/engine'
2
+ require 'strftime/rails/version'
@@ -0,0 +1,6 @@
1
+ module Strftime
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Strftime
2
+ module Rails
3
+ VERSION = '0.9.2'
4
+ end
5
+ end
@@ -0,0 +1,12 @@
1
+ (function(){function k(b,a){s[b]||(typeof console!=="undefined"&&typeof console.warn=="function"&&console.warn("[WARNING] "+b+" is deprecated and will be removed in version 1.0. Instead, use `"+a+"`."),s[b]=!0)}function t(b){b.localize=i.localize.bind(i);b.timezone=i.timezone.bind(i);b.utc=i.utc.bind(i)}function r(b,a,e){a&&a.days&&(e=a,a=void 0);e&&k("`"+g+"(format, [date], [locale])`","var s = "+g+".localize(locale); s(format, [date])");return(e?i.localize(e):i)(b,a)}function u(b,a,e){e?k("`"+g+
2
+ ".strftime(format, [date], [locale])`","var s = "+g+".localize(locale); s(format, [date])"):k("`"+g+".strftime(format, [date])`",g+"(format, [date])");return(e?i.localize(e):i)(b,a)}function p(b,a,e){function g(b,c,h,a){for(var d="",f=null,e=!1,i=b.length,j=!1,o=0;o<i;o++){var n=b.charCodeAt(o);if(e===!0)if(n===45)f="";else if(n===95)f=" ";else if(n===48)f="0";else if(n===58)j&&typeof console!=="undefined"&&typeof console.warn=="function"&&console.warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime"),
3
+ j=!0;else{switch(n){case 65:d+=h.days[c.getDay()];break;case 66:d+=h.months[c.getMonth()];break;case 67:d+=l(Math.floor(c.getFullYear()/100),f);break;case 68:d+=g(h.formats.D,c,h,a);break;case 70:d+=g(h.formats.F,c,h,a);break;case 72:d+=l(c.getHours(),f);break;case 73:d+=l(v(c.getHours()),f);break;case 76:d+=Math.floor(a%1E3)>99?Math.floor(a%1E3):Math.floor(a%1E3)>9?"0"+Math.floor(a%1E3):"00"+Math.floor(a%1E3);break;case 77:d+=l(c.getMinutes(),f);break;case 80:d+=c.getHours()<12?h.am:h.pm;break;case 82:d+=
4
+ g(h.formats.R,c,h,a);break;case 83:d+=l(c.getSeconds(),f);break;case 84:d+=g(h.formats.T,c,h,a);break;case 85:d+=l(w(c,"sunday"),f);break;case 87:d+=l(w(c,"monday"),f);break;case 88:d+=g(h.formats.X,c,h,a);break;case 89:d+=c.getFullYear();break;case 90:k&&m===0?d+="GMT":(f=c.toString().match(/\(([\w\s]+)\)/),d+=f&&f[1]||"");break;case 97:d+=h.shortDays[c.getDay()];break;case 98:d+=h.shortMonths[c.getMonth()];break;case 99:d+=g(h.formats.c,c,h,a);break;case 100:d+=l(c.getDate(),f);break;case 101:d+=
5
+ l(c.getDate(),f==null?" ":f);break;case 104:d+=h.shortMonths[c.getMonth()];break;case 106:f=new Date(c.getFullYear(),0,1);f=Math.ceil((c.getTime()-f.getTime())/864E5);d+=f>99?f:f>9?"0"+f:"00"+f;break;case 107:d+=l(c.getHours(),f==null?" ":f);break;case 108:d+=l(v(c.getHours()),f==null?" ":f);break;case 109:d+=l(c.getMonth()+1,f);break;case 110:d+="\n";break;case 111:d+=String(c.getDate())+A(c.getDate());break;case 112:d+=c.getHours()<12?h.AM:h.PM;break;case 114:d+=g(h.formats.r,c,h,a);break;case 115:d+=
6
+ Math.floor(a/1E3);break;case 116:d+="\t";break;case 117:f=c.getDay();d+=f===0?7:f;break;case 118:d+=g(h.formats.v,c,h,a);break;case 119:d+=c.getDay();break;case 120:d+=g(h.formats.x,c,h,a);break;case 121:d+=(""+c.getFullYear()).slice(2);break;case 122:k&&m===0?d+=j?"+00:00":"+0000":(f=m!==0?m/6E4:-c.getTimezoneOffset(),e=j?":":"",n=Math.abs(f%60),d+=(f<0?"-":"+")+l(Math.floor(Math.abs(f/60)))+e+l(n));break;default:d+=b[o]}f=null;e=!1}else n===37?e=!0:d+=b[o]}return d}var i=b||x,m=a||0,k=e||!1,j=0,
7
+ q,b=function(b,c){var a;c?(a=c.getTime(),k&&(c=new Date(c.getTime()+(c.getTimezoneOffset()||0)*6E4+m))):(a=Date.now(),a>j?(j=a,q=new Date(j),a=j,k&&(q=new Date(j+(q.getTimezoneOffset()||0)*6E4+m))):a=j,c=q);return g(b,c,i,a)};b.localize=function(a){return new p(a||i,m,k)};b.timezone=function(a){var c=m,b=k,e=typeof a;if(e==="number"||e==="string")b=!0,e==="string"?(c=a[0]==="-"?-1:1,e=parseInt(a.slice(1,3),10),a=parseInt(a.slice(3,5),10),c=c*(60*e+a)*6E4):e==="number"&&(c=a*6E4);return new p(i,c,
8
+ b)};b.utc=function(){return new p(i,m,!0)};return b}function l(b,a){if(a===""||b>9)return b;a==null&&(a="0");return a+b}function v(b){if(b===0)return 12;else if(b>12)return b-12;return b}function w(b,a){var a=a||"sunday",e=b.getDay();a==="monday"&&(e===0?e=6:e--);var g=Date.UTC(b.getFullYear(),0,1),i=Date.UTC(b.getFullYear(),b.getMonth(),b.getDate());return Math.floor((Math.floor((i-g)/864E5)+7-e)/7)}function A(b){var a=b%10;b%=100;if(b>=11&&b<=13||a===0||a>=4)return"th";switch(a){case 1:return"st";
9
+ case 2:return"nd";case 3:return"rd"}}var x={days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October","November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{D:"%m/%d/%y",F:"%Y-%m-%d",R:"%H:%M",T:"%H:%M:%S",X:"%T",c:"%a %b %d %X %Y",r:"%I:%M:%S %p",
10
+ v:"%e-%b-%Y",x:"%D"}},i=new p(x,0,!1),y=typeof module!=="undefined",j;y?(j=module.exports=r,j.strftime=u):(j=function(){return this||(0,eval)("this")}(),j.strftime=r);var g=y?"require('strftime')":"strftime",s={};j.strftimeTZ=function(b,a,e,j){if((typeof e=="number"||typeof e=="string")&&j==null)j=e,e=void 0;e?k("`"+g+".strftimeTZ(format, date, locale, tz)`","var s = "+g+".localize(locale).timezone(tz); s(format, [date])` or `var s = "+g+".localize(locale); s.timezone(tz)(format, [date])"):k("`"+
11
+ g+".strftimeTZ(format, date, tz)`","var s = "+g+".timezone(tz); s(format, [date])` or `"+g+".timezone(tz)(format, [date])");return(e?i.localize(e):i).timezone(j)(b,a)};j.strftimeUTC=function(b,a,e){e?k("`"+g+".strftimeUTC(format, date, locale)`","var s = "+g+".localize(locale).utc(); s(format, [date])"):k("`"+g+".strftimeUTC(format, [date])`","var s = "+g+".utc(); s(format, [date])");return(e?z.localize(e):z)(b,a)};j.localizedStrftime=function(b){k("`"+g+".localizedStrftime(locale)`",g+".localize(locale)");
12
+ return i.localize(b)};t(r);t(u);var z=i.utc();if(typeof Date.now!=="function")Date.now=function(){return+new Date}})();
@@ -0,0 +1,629 @@
1
+ //
2
+ // strftime
3
+ // github.com/samsonjs/strftime
4
+ // @_sjs
5
+ //
6
+ // Copyright 2010 - 2015 Sami Samhuri <sami@samhuri.net>
7
+ //
8
+ // MIT License
9
+ // http://sjs.mit-license.org
10
+ //
11
+
12
+ ;(function() {
13
+
14
+ var DefaultLocale = {
15
+ days: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
16
+ shortDays: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
17
+ months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
18
+ shortMonths: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
19
+ AM: 'AM',
20
+ PM: 'PM',
21
+ am: 'am',
22
+ pm: 'pm',
23
+ formats: {
24
+ D: '%m/%d/%y',
25
+ F: '%Y-%m-%d',
26
+ R: '%H:%M',
27
+ T: '%H:%M:%S',
28
+ X: '%T',
29
+ c: '%a %b %d %X %Y',
30
+ r: '%I:%M:%S %p',
31
+ v: '%e-%b-%Y',
32
+ x: '%D'
33
+ }
34
+ },
35
+ defaultStrftime = new Strftime(DefaultLocale, 0, false),
36
+ isCommonJS = typeof module !== 'undefined',
37
+ namespace;
38
+
39
+ // CommonJS / Node module
40
+ if (isCommonJS) {
41
+ namespace = module.exports = adaptedStrftime;
42
+ namespace.strftime = deprecatedStrftime;
43
+ }
44
+ // Browsers and other environments
45
+ else {
46
+ // Get the global object. Works in ES3, ES5, and ES5 strict mode.
47
+ namespace = (function() { return this || (1,eval)('this'); }());
48
+ namespace.strftime = adaptedStrftime;
49
+ }
50
+
51
+ // Deprecated API, to be removed in v1.0
52
+ var _require = isCommonJS ? "require('strftime')" : "strftime";
53
+ var _deprecationWarnings = {};
54
+ function deprecationWarning(name, instead) {
55
+ if (!_deprecationWarnings[name]) {
56
+ if (typeof console !== 'undefined' && typeof console.warn == 'function') {
57
+ console.warn("[WARNING] " + name + " is deprecated and will be removed in version 1.0. Instead, use `" + instead + "`.");
58
+ }
59
+ _deprecationWarnings[name] = true;
60
+ }
61
+ }
62
+
63
+ namespace.strftimeTZ = deprecatedStrftimeTZ;
64
+ namespace.strftimeUTC = deprecatedStrftimeUTC;
65
+ namespace.localizedStrftime = deprecatedStrftimeLocalized;
66
+
67
+ // Adapt the old API while preserving the new API.
68
+ function adaptForwards(fn) {
69
+ fn.localize = defaultStrftime.localize.bind(defaultStrftime);
70
+ fn.timezone = defaultStrftime.timezone.bind(defaultStrftime);
71
+ fn.utc = defaultStrftime.utc.bind(defaultStrftime);
72
+ }
73
+
74
+ adaptForwards(adaptedStrftime);
75
+ function adaptedStrftime(fmt, d, locale) {
76
+ // d and locale are optional, check if this is (format, locale)
77
+ if (d && d.days) {
78
+ locale = d;
79
+ d = undefined;
80
+ }
81
+ if (locale) {
82
+ deprecationWarning("`" + _require + "(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
83
+ }
84
+ var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
85
+ return strftime(fmt, d);
86
+ }
87
+
88
+ adaptForwards(deprecatedStrftime);
89
+ function deprecatedStrftime(fmt, d, locale) {
90
+ if (locale) {
91
+ deprecationWarning("`" + _require + ".strftime(format, [date], [locale])`", "var s = " + _require + ".localize(locale); s(format, [date])");
92
+ }
93
+ else {
94
+ deprecationWarning("`" + _require + ".strftime(format, [date])`", _require + "(format, [date])");
95
+ }
96
+ var strftime = locale ? defaultStrftime.localize(locale) : defaultStrftime;
97
+ return strftime(fmt, d);
98
+ }
99
+
100
+ function deprecatedStrftimeTZ(fmt, d, locale, timezone) {
101
+ // locale is optional, check if this is (format, date, timezone)
102
+ if ((typeof locale == 'number' || typeof locale == 'string') && timezone == null) {
103
+ timezone = locale;
104
+ locale = undefined;
105
+ }
106
+
107
+ if (locale) {
108
+ deprecationWarning("`" + _require + ".strftimeTZ(format, date, locale, tz)`", "var s = " + _require + ".localize(locale).timezone(tz); s(format, [date])` or `var s = " + _require + ".localize(locale); s.timezone(tz)(format, [date])");
109
+ }
110
+ else {
111
+ deprecationWarning("`" + _require + ".strftimeTZ(format, date, tz)`", "var s = " + _require + ".timezone(tz); s(format, [date])` or `" + _require + ".timezone(tz)(format, [date])");
112
+ }
113
+
114
+ var strftime = (locale ? defaultStrftime.localize(locale) : defaultStrftime).timezone(timezone);
115
+ return strftime(fmt, d);
116
+ }
117
+
118
+ var utcStrftime = defaultStrftime.utc();
119
+ function deprecatedStrftimeUTC(fmt, d, locale) {
120
+ if (locale) {
121
+ deprecationWarning("`" + _require + ".strftimeUTC(format, date, locale)`", "var s = " + _require + ".localize(locale).utc(); s(format, [date])");
122
+ }
123
+ else {
124
+ deprecationWarning("`" + _require + ".strftimeUTC(format, [date])`", "var s = " + _require + ".utc(); s(format, [date])");
125
+ }
126
+ var strftime = locale ? utcStrftime.localize(locale) : utcStrftime;
127
+ return strftime(fmt, d);
128
+ }
129
+
130
+ function deprecatedStrftimeLocalized(locale) {
131
+ deprecationWarning("`" + _require + ".localizedStrftime(locale)`", _require + ".localize(locale)");
132
+ return defaultStrftime.localize(locale);
133
+ }
134
+ // End of deprecated API
135
+
136
+ // Polyfill Date.now for old browsers.
137
+ if (typeof Date.now !== 'function') {
138
+ Date.now = function() {
139
+ return +new Date();
140
+ };
141
+ }
142
+
143
+ function Strftime(locale, customTimezoneOffset, useUtcTimezone) {
144
+ var _locale = locale || DefaultLocale,
145
+ _customTimezoneOffset = customTimezoneOffset || 0,
146
+ _useUtcBasedDate = useUtcTimezone || false,
147
+
148
+ // we store unix timestamp value here to not create new Date() each iteration (each millisecond)
149
+ // Date.now() is 2 times faster than new Date()
150
+ // while millisecond precise is enough here
151
+ // this could be very helpful when strftime triggered a lot of times one by one
152
+ _cachedDateTimestamp = 0,
153
+ _cachedDate;
154
+
155
+ function _strftime(format, date) {
156
+ var timestamp;
157
+
158
+ if (!date) {
159
+ var currentTimestamp = Date.now();
160
+ if (currentTimestamp > _cachedDateTimestamp) {
161
+ _cachedDateTimestamp = currentTimestamp;
162
+ _cachedDate = new Date(_cachedDateTimestamp);
163
+
164
+ timestamp = _cachedDateTimestamp;
165
+
166
+ if (_useUtcBasedDate) {
167
+ // how to avoid duplication of date instantiation for utc here?
168
+ // we tied to getTimezoneOffset of the current date
169
+ _cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
170
+ }
171
+ }
172
+ else {
173
+ timestamp = _cachedDateTimestamp;
174
+ }
175
+ date = _cachedDate;
176
+ }
177
+ else {
178
+ timestamp = date.getTime();
179
+
180
+ if (_useUtcBasedDate) {
181
+ date = new Date(date.getTime() + getTimestampToUtcOffsetFor(date) + _customTimezoneOffset);
182
+ }
183
+ }
184
+
185
+ return _processFormat(format, date, _locale, timestamp);
186
+ }
187
+
188
+ function _processFormat(format, date, locale, timestamp) {
189
+ var resultString = '',
190
+ padding = null,
191
+ isInScope = false,
192
+ length = format.length,
193
+ extendedTZ = false;
194
+
195
+ for (var i = 0; i < length; i++) {
196
+
197
+ var currentCharCode = format.charCodeAt(i);
198
+
199
+ if (isInScope === true) {
200
+ // '-'
201
+ if (currentCharCode === 45) {
202
+ padding = '';
203
+ continue;
204
+ }
205
+ // '_'
206
+ else if (currentCharCode === 95) {
207
+ padding = ' ';
208
+ continue;
209
+ }
210
+ // '0'
211
+ else if (currentCharCode === 48) {
212
+ padding = '0';
213
+ continue;
214
+ }
215
+ // ':'
216
+ else if (currentCharCode === 58) {
217
+ if (extendedTZ) {
218
+ if (typeof console !== 'undefined' && typeof console.warn == 'function') {
219
+ console.warn("[WARNING] detected use of unsupported %:: or %::: modifiers to strftime");
220
+ }
221
+ }
222
+ extendedTZ = true;
223
+ continue;
224
+ }
225
+
226
+ switch (currentCharCode) {
227
+
228
+ // Examples for new Date(0) in GMT
229
+
230
+ // 'Thursday'
231
+ // case 'A':
232
+ case 65:
233
+ resultString += locale.days[date.getDay()];
234
+ break;
235
+
236
+ // 'January'
237
+ // case 'B':
238
+ case 66:
239
+ resultString += locale.months[date.getMonth()];
240
+ break;
241
+
242
+ // '19'
243
+ // case 'C':
244
+ case 67:
245
+ resultString += padTill2(Math.floor(date.getFullYear() / 100), padding);
246
+ break;
247
+
248
+ // '01/01/70'
249
+ // case 'D':
250
+ case 68:
251
+ resultString += _processFormat(locale.formats.D, date, locale, timestamp);
252
+ break;
253
+
254
+ // '1970-01-01'
255
+ // case 'F':
256
+ case 70:
257
+ resultString += _processFormat(locale.formats.F, date, locale, timestamp);
258
+ break;
259
+
260
+ // '00'
261
+ // case 'H':
262
+ case 72:
263
+ resultString += padTill2(date.getHours(), padding);
264
+ break;
265
+
266
+ // '12'
267
+ // case 'I':
268
+ case 73:
269
+ resultString += padTill2(hours12(date.getHours()), padding);
270
+ break;
271
+
272
+ // '000'
273
+ // case 'L':
274
+ case 76:
275
+ resultString += padTill3(Math.floor(timestamp % 1000));
276
+ break;
277
+
278
+ // '00'
279
+ // case 'M':
280
+ case 77:
281
+ resultString += padTill2(date.getMinutes(), padding);
282
+ break;
283
+
284
+ // 'am'
285
+ // case 'P':
286
+ case 80:
287
+ resultString += date.getHours() < 12 ? locale.am : locale.pm;
288
+ break;
289
+
290
+ // '00:00'
291
+ // case 'R':
292
+ case 82:
293
+ resultString += _processFormat(locale.formats.R, date, locale, timestamp);
294
+ break;
295
+
296
+ // '00'
297
+ // case 'S':
298
+ case 83:
299
+ resultString += padTill2(date.getSeconds(), padding);
300
+ break;
301
+
302
+ // '00:00:00'
303
+ // case 'T':
304
+ case 84:
305
+ resultString += _processFormat(locale.formats.T, date, locale, timestamp);
306
+ break;
307
+
308
+ // '00'
309
+ // case 'U':
310
+ case 85:
311
+ resultString += padTill2(weekNumber(date, 'sunday'), padding);
312
+ break;
313
+
314
+ // '00'
315
+ // case 'W':
316
+ case 87:
317
+ resultString += padTill2(weekNumber(date, 'monday'), padding);
318
+ break;
319
+
320
+ // '16:00:00'
321
+ // case 'X':
322
+ case 88:
323
+ resultString += _processFormat(locale.formats.X, date, locale, timestamp);
324
+ break;
325
+
326
+ // '1970'
327
+ // case 'Y':
328
+ case 89:
329
+ resultString += date.getFullYear();
330
+ break;
331
+
332
+ // 'GMT'
333
+ // case 'Z':
334
+ case 90:
335
+ if (_useUtcBasedDate && _customTimezoneOffset === 0) {
336
+ resultString += "GMT";
337
+ }
338
+ else {
339
+ // fixme optimize
340
+ var tzString = date.toString().match(/\(([\w\s]+)\)/);
341
+ resultString += tzString && tzString[1] || '';
342
+ }
343
+ break;
344
+
345
+ // 'Thu'
346
+ // case 'a':
347
+ case 97:
348
+ resultString += locale.shortDays[date.getDay()];
349
+ break;
350
+
351
+ // 'Jan'
352
+ // case 'b':
353
+ case 98:
354
+ resultString += locale.shortMonths[date.getMonth()];
355
+ break;
356
+
357
+ // ''
358
+ // case 'c':
359
+ case 99:
360
+ resultString += _processFormat(locale.formats.c, date, locale, timestamp);
361
+ break;
362
+
363
+ // '01'
364
+ // case 'd':
365
+ case 100:
366
+ resultString += padTill2(date.getDate(), padding);
367
+ break;
368
+
369
+ // ' 1'
370
+ // case 'e':
371
+ case 101:
372
+ resultString += padTill2(date.getDate(), padding == null ? ' ' : padding);
373
+ break;
374
+
375
+ // 'Jan'
376
+ // case 'h':
377
+ case 104:
378
+ resultString += locale.shortMonths[date.getMonth()];
379
+ break;
380
+
381
+ // '000'
382
+ // case 'j':
383
+ case 106:
384
+ var y = new Date(date.getFullYear(), 0, 1);
385
+ var day = Math.ceil((date.getTime() - y.getTime()) / (1000 * 60 * 60 * 24));
386
+ resultString += padTill3(day);
387
+ break;
388
+
389
+ // ' 0'
390
+ // case 'k':
391
+ case 107:
392
+ resultString += padTill2(date.getHours(), padding == null ? ' ' : padding);
393
+ break;
394
+
395
+ // '12'
396
+ // case 'l':
397
+ case 108:
398
+ resultString += padTill2(hours12(date.getHours()), padding == null ? ' ' : padding);
399
+ break;
400
+
401
+ // '01'
402
+ // case 'm':
403
+ case 109:
404
+ resultString += padTill2(date.getMonth() + 1, padding);
405
+ break;
406
+
407
+ // '\n'
408
+ // case 'n':
409
+ case 110:
410
+ resultString += '\n';
411
+ break;
412
+
413
+ // '1st'
414
+ // case 'o':
415
+ case 111:
416
+ resultString += String(date.getDate()) + ordinal(date.getDate());
417
+ break;
418
+
419
+ // 'AM'
420
+ // case 'p':
421
+ case 112:
422
+ resultString += date.getHours() < 12 ? locale.AM : locale.PM;
423
+ break;
424
+
425
+ // '12:00:00 AM'
426
+ // case 'r':
427
+ case 114:
428
+ resultString += _processFormat(locale.formats.r, date, locale, timestamp);
429
+ break;
430
+
431
+ // '0'
432
+ // case 's':
433
+ case 115:
434
+ resultString += Math.floor(timestamp / 1000);
435
+ break;
436
+
437
+ // '\t'
438
+ // case 't':
439
+ case 116:
440
+ resultString += '\t';
441
+ break;
442
+
443
+ // '4'
444
+ // case 'u':
445
+ case 117:
446
+ var day = date.getDay();
447
+ resultString += day === 0 ? 7 : day;
448
+ break; // 1 - 7, Monday is first day of the week
449
+
450
+ // ' 1-Jan-1970'
451
+ // case 'v':
452
+ case 118:
453
+ resultString += _processFormat(locale.formats.v, date, locale, timestamp);
454
+ break;
455
+
456
+ // '4'
457
+ // case 'w':
458
+ case 119:
459
+ resultString += date.getDay();
460
+ break; // 0 - 6, Sunday is first day of the week
461
+
462
+ // '12/31/69'
463
+ // case 'x':
464
+ case 120:
465
+ resultString += _processFormat(locale.formats.x, date, locale, timestamp);
466
+ break;
467
+
468
+ // '70'
469
+ // case 'y':
470
+ case 121:
471
+ resultString += ('' + date.getFullYear()).slice(2);
472
+ break;
473
+
474
+ // '+0000'
475
+ // case 'z':
476
+ case 122:
477
+ if (_useUtcBasedDate && _customTimezoneOffset === 0) {
478
+ resultString += extendedTZ ? "+00:00" : "+0000";
479
+ }
480
+ else {
481
+ var off;
482
+ if (_customTimezoneOffset !== 0) {
483
+ off = _customTimezoneOffset / (60 * 1000);
484
+ }
485
+ else {
486
+ off = -date.getTimezoneOffset();
487
+ }
488
+ var sign = off < 0 ? '-' : '+';
489
+ var sep = extendedTZ ? ':' : '';
490
+ var hours = Math.floor(Math.abs(off / 60));
491
+ var mins = Math.abs(off % 60);
492
+ resultString += sign + padTill2(hours) + sep + padTill2(mins);
493
+ }
494
+ break;
495
+
496
+ default:
497
+ resultString += format[i];
498
+ break;
499
+ }
500
+
501
+ padding = null;
502
+ isInScope = false;
503
+ continue;
504
+ }
505
+
506
+ // '%'
507
+ if (currentCharCode === 37) {
508
+ isInScope = true;
509
+ continue;
510
+ }
511
+
512
+ resultString += format[i];
513
+ }
514
+
515
+ return resultString;
516
+ }
517
+
518
+ var strftime = _strftime;
519
+
520
+ strftime.localize = function(locale) {
521
+ return new Strftime(locale || _locale, _customTimezoneOffset, _useUtcBasedDate);
522
+ };
523
+
524
+ strftime.timezone = function(timezone) {
525
+ var customTimezoneOffset = _customTimezoneOffset;
526
+ var useUtcBasedDate = _useUtcBasedDate;
527
+
528
+ var timezoneType = typeof timezone;
529
+ if (timezoneType === 'number' || timezoneType === 'string') {
530
+ useUtcBasedDate = true;
531
+
532
+ // ISO 8601 format timezone string, [-+]HHMM
533
+ if (timezoneType === 'string') {
534
+ var sign = timezone[0] === '-' ? -1 : 1,
535
+ hours = parseInt(timezone.slice(1, 3), 10),
536
+ minutes = parseInt(timezone.slice(3, 5), 10);
537
+
538
+ customTimezoneOffset = sign * ((60 * hours) + minutes) * 60 * 1000;
539
+ // in minutes: 420
540
+ }
541
+ else if (timezoneType === 'number') {
542
+ customTimezoneOffset = timezone * 60 * 1000;
543
+ }
544
+ }
545
+
546
+ return new Strftime(_locale, customTimezoneOffset, useUtcBasedDate);
547
+ };
548
+
549
+ strftime.utc = function() {
550
+ return new Strftime(_locale, _customTimezoneOffset, true);
551
+ };
552
+
553
+ return strftime;
554
+ }
555
+
556
+ function padTill2(numberToPad, paddingChar) {
557
+ if (paddingChar === '' || numberToPad > 9) {
558
+ return numberToPad;
559
+ }
560
+ if (paddingChar == null) {
561
+ paddingChar = '0';
562
+ }
563
+ return paddingChar + numberToPad;
564
+ }
565
+
566
+ function padTill3(numberToPad) {
567
+ if (numberToPad > 99) {
568
+ return numberToPad;
569
+ }
570
+ if (numberToPad > 9) {
571
+ return '0' + numberToPad;
572
+ }
573
+ return '00' + numberToPad;
574
+ }
575
+
576
+ function hours12(hour) {
577
+ if (hour === 0) {
578
+ return 12;
579
+ }
580
+ else if (hour > 12) {
581
+ return hour - 12;
582
+ }
583
+ return hour;
584
+ }
585
+
586
+ // firstWeekday: 'sunday' or 'monday', default is 'sunday'
587
+ //
588
+ // Pilfered & ported from Ruby's strftime implementation.
589
+ function weekNumber(date, firstWeekday) {
590
+ firstWeekday = firstWeekday || 'sunday';
591
+
592
+ // This works by shifting the weekday back by one day if we
593
+ // are treating Monday as the first day of the week.
594
+ var weekday = date.getDay();
595
+ if (firstWeekday === 'monday') {
596
+ if (weekday === 0) // Sunday
597
+ weekday = 6;
598
+ else
599
+ weekday--;
600
+ }
601
+
602
+ var firstDayOfYearUtc = Date.UTC(date.getFullYear(), 0, 1),
603
+ dateUtc = Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()),
604
+ yday = Math.floor((dateUtc - firstDayOfYearUtc) / 86400000),
605
+ weekNum = (yday + 7 - weekday) / 7;
606
+
607
+ return Math.floor(weekNum);
608
+ }
609
+
610
+ // Get the ordinal suffix for a number: st, nd, rd, or th
611
+ function ordinal(number) {
612
+ var i = number % 10;
613
+ var ii = number % 100;
614
+
615
+ if ((ii >= 11 && ii <= 13) || i === 0 || i >= 4) {
616
+ return 'th';
617
+ }
618
+ switch (i) {
619
+ case 1: return 'st';
620
+ case 2: return 'nd';
621
+ case 3: return 'rd';
622
+ }
623
+ }
624
+
625
+ function getTimestampToUtcOffsetFor(date) {
626
+ return (date.getTimezoneOffset() || 0) * 60000;
627
+ }
628
+
629
+ }());
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: strftime-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Chris Cressman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: 'strftime for JavaScript, packaged for the Rails asset '
14
+ email:
15
+ - ccressman@weblinc.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE
21
+ - README.md
22
+ - lib/strftime/rails.rb
23
+ - lib/strftime/rails/engine.rb
24
+ - lib/strftime/rails/version.rb
25
+ - vendor/assets/javascripts/strftime-rails/strftime-min.js
26
+ - vendor/assets/javascripts/strftime-rails/strftime.js
27
+ homepage: http://github.com/chriscressman/strftime-rails
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.4.8
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: strftime for JavaScript, packaged for the Rails asset
51
+ test_files: []