1 var formatDate
= (function() {
3 Modified version of date.format.js
4 https://github.com/jacwright/date.format
6 var locale_init
= false, // Once the loales have been loaded, this is set to true
7 shortMonths
, longMonths
, shortDays
, longDays
;
12 d: function() { return (this.getDate() < 10 ? '0' : '') + this.getDate(); },
13 D: function() { return Date
.shortDays
[this.getDay()]; },
14 j: function() { return this.getDate(); },
15 l: function() { return Date
.longDays
[this.getDay()]; },
16 N: function() { return this.getDay() + 1; },
17 S: function() { return (this.getDate() % 10 == 1 && this.getDate() != 11 ? 'st' : (this.getDate() % 10 == 2 && this.getDate() != 12 ? 'nd' : (this.getDate() % 10 == 3 && this.getDate() != 13 ? 'rd' : 'th'))); },
18 w: function() { return this.getDay(); },
19 z: function() { var d
= new Date(this.getFullYear(),0,1); return Math
.ceil((this - d
) / 86400000); }, // Fixed now
21 W: function() { var d
= new Date(this.getFullYear(), 0, 1); return Math
.ceil((((this - d
) / 86400000) + d
.getDay() + 1) / 7); }, // Fixed now
23 F: function() { return Date
.longMonths
[this.getMonth()]; },
24 m: function() { return (this.getMonth() < 9 ? '0' : '') + (this.getMonth() + 1); },
25 M: function() { return Date
.shortMonths
[this.getMonth()]; },
26 n: function() { return this.getMonth() + 1; },
27 t: function() { var d
= new Date(); return new Date(d
.getFullYear(), d
.getMonth(), 0).getDate(); }, // Fixed now, gets #days of date
29 L: function() { var year
= this.getFullYear(); return (year
% 400 == 0 || (year
% 100 != 0 && year
% 4 == 0)); }, // Fixed now
30 o: function() { var d
= new Date(this.valueOf()); d
.setDate(d
.getDate() - ((this.getDay() + 6) % 7) + 3); return d
.getFullYear();}, //Fixed now
31 Y: function() { return this.getFullYear(); },
32 y: function() { return ('' + this.getFullYear()).substr(2); },
34 a: function() { return this.getHours() < 12 ? 'am' : 'pm'; },
35 A: function() { return this.getHours() < 12 ? 'AM' : 'PM'; },
36 B: function() { return Math
.floor((((this.getUTCHours() + 1) % 24) + this.getUTCMinutes() / 60 + this.getUTCSeconds() / 3600) * 1000 / 24); }, // Fixed now
37 g: function() { return this.getHours() % 12 || 12; },
38 G: function() { return this.getHours(); },
39 h: function() { return ((this.getHours() % 12 || 12) < 10 ? '0' : '') + (this.getHours() % 12 || 12); },
40 H: function() { return (this.getHours() < 10 ? '0' : '') + this.getHours(); },
41 i: function() { return (this.getMinutes() < 10 ? '0' : '') + this.getMinutes(); },
42 s: function() { return (this.getSeconds() < 10 ? '0' : '') + this.getSeconds(); },
43 u: function() { var m
= this.getMilliseconds(); return (m
< 10 ? '00' : (m
< 100 ? '0' : '')) + m
; },
45 e: function() { return "Not Yet Supported"; },
48 for (var i
= 0; i
< 12; ++i
) {
49 var d
= new Date(this.getFullYear(), i
, 1);
50 var offset
= d
.getTimezoneOffset();
52 if (DST
=== null) DST
= offset
;
53 else if (offset
< DST
) { DST
= offset
; break; }
54 else if (offset
> DST
) break;
56 return (this.getTimezoneOffset() == DST
) | 0;
58 O: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math
.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math
.abs(this.getTimezoneOffset() / 60)) + '00'; },
59 P: function() { return (-this.getTimezoneOffset() < 0 ? '-' : '+') + (Math
.abs(this.getTimezoneOffset() / 60) < 10 ? '0' : '') + (Math
.abs(this.getTimezoneOffset() / 60)) + ':00'; }, // Fixed now
60 T: function() { var m
= this.getMonth(); this.setMonth(0); var result
= this.toTimeString().replace(/^.+ \(?([^\)]+)\)?$/, '$1'); this.setMonth(m
); return result
;},
61 Z: function() { return -this.getTimezoneOffset() * 60; },
63 c: function() { return this.format("Y-m-d\\TH:i:sP"); }, // Fixed now
64 r: function() { return this.toString(); },
65 U: function() { return this.getTime() / 1000; }
69 var initLocaleFormats = function() {
71 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.january').fetch(),
72 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.february').fetch(),
73 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.march').fetch(),
74 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.april').fetch(),
75 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.may').fetch(),
76 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.june').fetch(),
77 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.july').fetch(),
78 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.august').fetch(),
79 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.september').fetch(),
80 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.october').fetch(),
81 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.november').fetch(),
82 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_months.december').fetch()
85 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.january').fetch(),
86 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.february').fetch(),
87 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.march').fetch(),
88 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.april').fetch(),
89 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.may').fetch(),
90 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.june').fetch(),
91 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.july').fetch(),
92 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.august').fetch(),
93 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.september').fetch(),
94 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.october').fetch(),
95 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.november').fetch(),
96 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_months.december').fetch()
99 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.monday').fetch(),
100 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.tuesday').fetch(),
101 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.wednesday').fetch(),
102 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.thursday').fetch(),
103 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.friday').fetch(),
104 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.saturday').fetch(),
105 _kiwi
.global
.i18n
.translate('client.libs.date_format.short_days.sunday').fetch()
108 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.monday').fetch(),
109 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.tuesday').fetch(),
110 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.wednesday').fetch(),
111 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.thursday').fetch(),
112 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.friday').fetch(),
113 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.saturday').fetch(),
114 _kiwi
.global
.i18n
.translate('client.libs.date_format.long_days.sunday').fetch()
119 /* End of date.format */
122 // Finally.. the actuall formatDate function
123 return function(working_date
, format
) {
127 working_date
= working_date
|| new Date();
128 format
= format
|| _kiwi
.global
.i18n
.translate('client_date_format').fetch();
130 return format
.replace(/(\\?)(.)/g, function(_
, esc
, chr
) {
131 return (esc
=== '' && replaceChars
[chr
]) ? replaceChars
[chr
].call(working_date
) : chr
;