Skip to content

Commit 9b8f5c3

Browse files
committed
same as locutusjs#138 for var _pad
1 parent d1cfd93 commit 9b8f5c3

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

functions/datetime/date.js

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,23 @@ function date(format, timestamp) {
5555
// example 9: date('W Y-m-d', 1293974054); // 2011-01-02
5656
// returns 9: '52 2011-01-02'
5757

58-
var that = this,
59-
jsdate,
60-
f,
61-
// Keep this here (works, but for code commented-out
62-
// below for file size reasons)
63-
//, tal= [],
64-
txt_words = ['Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur', 'January', 'February', 'March', 'April',
65-
'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
66-
],
67-
// trailing backslash -> (dropped)
68-
// a backslash followed by any character (including backslash) -> the character
69-
// empty string -> empty string
70-
formatChr = /\\?(.?)/gi,
71-
formatChrCb = function(t, s) {
72-
return f[t] ? f[t]() : s;
73-
};
74-
_pad = function(n, c) {
58+
var that = this;
59+
var jsdate, f;
60+
// Keep this here (works, but for code commented-out below for file size reasons)
61+
// var tal= [];
62+
var txt_words = [
63+
'Sun', 'Mon', 'Tues', 'Wednes', 'Thurs', 'Fri', 'Satur',
64+
'January', 'February', 'March', 'April', 'May', 'June',
65+
'July', 'August', 'September', 'October', 'November', 'December'
66+
];
67+
// trailing backslash -> (dropped)
68+
// a backslash followed by any character (including backslash) -> the character
69+
// empty string -> empty string
70+
var formatChr = /\\?(.?)/gi;
71+
var formatChrCb = function(t, s) {
72+
return f[t] ? f[t]() : s;
73+
};
74+
var _pad = function(n, c) {
7575
n = String(n);
7676
while (n.length < c) {
7777
n = '0' + n;
@@ -97,8 +97,8 @@ function date(format, timestamp) {
9797
return f.w() || 7;
9898
},
9999
S: function() { // Ordinal suffix for day of month; st, nd, rd, th
100-
var j = f.j(),
101-
i = j % 10;
100+
var j = f.j();
101+
var i = j % 10;
102102
if (i <= 3 && parseInt((j % 100) / 10, 10) == 1) {
103103
i = 0;
104104
}
@@ -108,15 +108,15 @@ function date(format, timestamp) {
108108
return jsdate.getDay();
109109
},
110110
z: function() { // Day of year; 0..365
111-
var a = new Date(f.Y(), f.n() - 1, f.j()),
112-
b = new Date(f.Y(), 0, 1);
111+
var a = new Date(f.Y(), f.n() - 1, f.j());
112+
var b = new Date(f.Y(), 0, 1);
113113
return Math.round((a - b) / 864e5);
114114
},
115115

116116
// Week
117117
W: function() { // ISO-8601 week number
118-
var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3),
119-
b = new Date(a.getFullYear(), 0, 4);
118+
var a = new Date(f.Y(), f.n() - 1, f.j() - f.N() + 3);
119+
var b = new Date(a.getFullYear(), 0, 4);
120120
return _pad(1 + Math.round((a - b) / 864e5 / 7), 2);
121121
},
122122

@@ -145,9 +145,9 @@ function date(format, timestamp) {
145145
return j % 4 === 0 & j % 100 !== 0 | j % 400 === 0;
146146
},
147147
o: function() { // ISO-8601 year
148-
var n = f.n(),
149-
W = f.W(),
150-
Y = f.Y();
148+
var n = f.n();
149+
var W = f.W();
150+
var Y = f.Y();
151151
return Y + (n === 12 && W < 9 ? 1 : n === 1 && W > 9 ? -1 : 0);
152152
},
153153
Y: function() { // Full year; e.g. 1980...2010
@@ -168,11 +168,11 @@ function date(format, timestamp) {
168168
.toUpperCase();
169169
},
170170
B: function() { // Swatch Internet time; 000..999
171-
var H = jsdate.getUTCHours() * 36e2,
172-
// Hours
173-
i = jsdate.getUTCMinutes() * 60,
174-
// Minutes
175-
s = jsdate.getUTCSeconds(); // Seconds
171+
var H = jsdate.getUTCHours() * 36e2;
172+
// Hours
173+
var i = jsdate.getUTCMinutes() * 60;
174+
// Minutes
175+
var s = jsdate.getUTCSeconds(); // Seconds
176176
return _pad(Math.floor((H + i + s + 36e2) / 86.4) % 1e3, 3);
177177
},
178178
g: function() { // 12-Hours; 1..12
@@ -208,18 +208,18 @@ function date(format, timestamp) {
208208
I: function() { // DST observed?; 0 or 1
209209
// Compares Jan 1 minus Jan 1 UTC to Jul 1 minus Jul 1 UTC.
210210
// If they are not equal, then DST is observed.
211-
var a = new Date(f.Y(), 0),
212-
// Jan 1
213-
c = Date.UTC(f.Y(), 0),
214-
// Jan 1 UTC
215-
b = new Date(f.Y(), 6),
216-
// Jul 1
217-
d = Date.UTC(f.Y(), 6); // Jul 1 UTC
211+
var a = new Date(f.Y(), 0);
212+
// Jan 1
213+
var c = Date.UTC(f.Y(), 0);
214+
// Jan 1 UTC
215+
var b = new Date(f.Y(), 6);
216+
// Jul 1
217+
var d = Date.UTC(f.Y(), 6); // Jul 1 UTC
218218
return ((a - c) !== (b - d)) ? 1 : 0;
219219
},
220220
O: function() { // Difference to GMT in hour format; e.g. +0200
221-
var tzo = jsdate.getTimezoneOffset(),
222-
a = Math.abs(tzo);
221+
var tzo = jsdate.getTimezoneOffset();
222+
var a = Math.abs(tzo);
223223
return (tzo > 0 ? '-' : '+') + _pad(Math.floor(a / 60) * 100 + a % 60, 4);
224224
},
225225
P: function() { // Difference to GMT w/colon; e.g. +02:00
@@ -229,15 +229,15 @@ function date(format, timestamp) {
229229
T: function() { // Timezone abbreviation; e.g. EST, MDT, ...
230230
// The following works, but requires inclusion of the very
231231
// large timezone_abbreviations_list() function.
232-
/* var abbr = '', i = 0, os = 0, default = 0;
232+
/* var abbr, i, os, _default;
233233
if (!tal.length) {
234234
tal = that.timezone_abbreviations_list();
235235
}
236236
if (that.php_js && that.php_js.default_timezone) {
237-
default = that.php_js.default_timezone;
237+
_default = that.php_js.default_timezone;
238238
for (abbr in tal) {
239-
for (i=0; i < tal[abbr].length; i++) {
240-
if (tal[abbr][i].timezone_id === default) {
239+
for (i = 0; i < tal[abbr].length; i++) {
240+
if (tal[abbr][i].timezone_id === _default) {
241241
return abbr.toUpperCase();
242242
}
243243
}
@@ -273,8 +273,8 @@ function date(format, timestamp) {
273273
that = this;
274274
jsdate = (timestamp === undefined ? new Date() : // Not provided
275275
(timestamp instanceof Date) ? new Date(timestamp) : // JS Date()
276-
new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
277-
);
276+
new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
277+
);
278278
return format.replace(formatChr, formatChrCb);
279279
};
280280
return this.date(format, timestamp);

0 commit comments

Comments
 (0)