Debian Codegraph @

rhino/testsrc/doctests/date.toisostring.doctest

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 js> load('testsrc/doctests/util.js');
6
7 js> Date.prototype.toISOString;
8 function toISOString() { [native code for Date.toISOString, arity=0] }
9
10 js> expectError(function() {
11 > new Date(Infinity).toISOString()
12 > }, RangeError);
13
14 js> new Date(0).toISOString()
15 1970-01-01T00:00:00.000Z
16
17 js> var isoFormat = /(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d).(\d\d\d)Z/;
18 js> var now = new Date();
19
20 js> var matches = isoFormat.exec(now.toISOString());
21 js> matches[0] === now.toISOString()
22 true
23 js> matches[1] == now.getUTCFullYear()
24 true
25 js> matches[2] == now.getUTCMonth()+1
26 true
27 js> matches[3] == now.getUTCDate()
28 true
29 js> matches[4] == now.getUTCHours()
30 true
31 js> matches[5] == now.getUTCMinutes()
32 true
33 js> matches[6] == now.getUTCSeconds()
34 true
35 js> matches[7] == now.getUTCMilliseconds()
36 true