Skip to content

Commit bce5f25

Browse files
committed
Fixed regression of TER constructors when a time element is given as argument
1 parent 431dd2f commit bce5f25

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

LICENSE

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
Copyright 2008-2017 Wakaba <wakaba@suikawiki.org>. All rights reserved.
1+
Copyright 2008-2019 Wakaba <wakaba@suikawiki.org>. All rights reserved.
2+
23
Copyright 2017 Hatena <http://hatenacorp.jp/>. All rights reserved.
34

45
This program is free software; you can redistribute it and/or

src/time.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,16 @@ TER.globalDateAndTimeStringPattern = /^([0-9]{4,})-([0-9]{2})-([0-9]{2})(?:[\u00
1111
TER.dateStringPattern = /^([0-9]{4,})-([0-9]{2})-([0-9]{2})$/;
1212

1313
TER.prototype._initialize = function () {
14-
var els = this.container.getElementsByTagName ('time');
15-
var elsL = els.length;
16-
for (var i = 0; i < elsL; i++) {
17-
var el = els[i];
18-
if (!el) break; /* If <time> is nested */
19-
this._initTimeElement (el);
14+
if (this.container.localName === 'time') {
15+
this._initTimeElement (this.container);
16+
} else {
17+
var els = this.container.getElementsByTagName ('time');
18+
var elsL = els.length;
19+
for (var i = 0; i < elsL; i++) {
20+
var el = els[i];
21+
if (!el) break; /* If <time> is nested */
22+
this._initTimeElement (el);
23+
}
2024
}
2125
}; // TER.prototype._initialize
2226

@@ -321,7 +325,7 @@ is a willful violation to the current HTML Living Standard.
321325

322326
/* ***** BEGIN LICENSE BLOCK *****
323327
*
324-
* Copyright 2008-2018 Wakaba <wakaba@suikawiki.org>. All rights reserved.
328+
* Copyright 2008-2019 Wakaba <wakaba@suikawiki.org>. All rights reserved.
325329
*
326330
* Copyright 2017 Hatena <http://hatenacorp.jp/>. All rights reserved.
327331
*

t/ter-constructor.html

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Test</title>
6+
<script src="http://sinonjs.org/releases/sinon-2.1.0.js"></script>
7+
</head>
8+
<body>
9+
<test-code name="constructor with time element (TER)">
10+
var e = document.createElement ('time');
11+
e.setAttribute ('datetime', '2012-05-01T00:12:51Z');
12+
e.setAttribute ('data-tzoffset', '2342');
13+
new TER (e);
14+
await this.wait ();
15+
16+
this.assert.equal (e.textContent, {
17+
"UTC:en-US": "5/1/2012, 0:51:53 AM",
18+
"UTC:ja-JP": "2012/5/1 0:51:53",
19+
"Asia/Tokyo:en-US": "5/1/2012, 0:51:53 AM",
20+
"Asia/Tokyo:ja-JP": "2012/5/1 0:51:53",
21+
"America/Los_Angeles:en-US": "5/1/2012, 0:51:53 AM",
22+
"America/Los_Angeles:ja-JP": "2012/5/1 0:51:53",
23+
}[this.env]);
24+
</test-code>
25+
26+
<test-code name="constructor with time element (TER.Delta)">
27+
var clock = sinon.useFakeTimers(Date.parse("2016-01-02T00:00:00Z"));
28+
var e = document.createElement ('time');
29+
e.setAttribute ('datetime', '2015-09-24T00:00:01Z');
30+
new TER.Delta (e);
31+
32+
this.assert.equal (e.textContent, {
33+
"UTC:en-US": "99 days 23 hours ago",
34+
"UTC:ja-JP": "99日23時間前",
35+
"Asia/Tokyo:en-US": "99 days 23 hours ago",
36+
"Asia/Tokyo:ja-JP": "99日23時間前",
37+
"America/Los_Angeles:en-US": "99 days 23 hours ago",
38+
"America/Los_Angeles:ja-JP": "99日23時間前",
39+
}[this.env]);
40+
</test-code>
41+
42+
<script src=runtests.js></script>
43+
</body>
44+
</html>
45+
<!--
46+
47+
Per CC0 <https://creativecommons.org/publicdomain/zero/1.0/>, to the
48+
extent possible under law, the author has waived all copyright and
49+
related or neighboring rights to this work.
50+
51+
-->

0 commit comments

Comments
 (0)