Skip to content

Commit c15b4bc

Browse files
author
Martin Braun
committed
Add Date method toISOString()
1 parent 1d4a557 commit c15b4bc

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

Date/toISOString.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
3+
*/
4+
if (!Date.prototype.toISOString) {
5+
(function() {
6+
7+
function pad(number) {
8+
if (number < 10) {
9+
return '0' + number;
10+
}
11+
return number;
12+
}
13+
14+
Date.prototype.toISOString = function() {
15+
return this.getUTCFullYear() +
16+
'-' + pad(this.getUTCMonth() + 1) +
17+
'-' + pad(this.getUTCDate()) +
18+
'T' + pad(this.getUTCHours()) +
19+
':' + pad(this.getUTCMinutes()) +
20+
':' + pad(this.getUTCSeconds()) +
21+
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
22+
'Z';
23+
};
24+
25+
}());
26+
}

index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -845,3 +845,30 @@ if (!String.prototype.trim) {
845845
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
846846
};
847847
}
848+
//toISOString.js
849+
/*
850+
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toISOString
851+
*/
852+
if (!Date.prototype.toISOString) {
853+
(function() {
854+
855+
function pad(number) {
856+
if (number < 10) {
857+
return '0' + number;
858+
}
859+
return number;
860+
}
861+
862+
Date.prototype.toISOString = function() {
863+
return this.getUTCFullYear() +
864+
'-' + pad(this.getUTCMonth() + 1) +
865+
'-' + pad(this.getUTCDate()) +
866+
'T' + pad(this.getUTCHours()) +
867+
':' + pad(this.getUTCMinutes()) +
868+
':' + pad(this.getUTCSeconds()) +
869+
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice(2, 5) +
870+
'Z';
871+
};
872+
873+
}());
874+
}

0 commit comments

Comments
 (0)