Skip to content

Commit

Permalink
v1.21.0: add method to get next DST change moment
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier Schouten committed Jul 21, 2015
1 parent 102fb9f commit 1f1abff
Show file tree
Hide file tree
Showing 13 changed files with 234 additions and 35 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,9 @@ var duration = db.maxDst(); // maximum DST offet in the database
var bool1 = db.hasDst("Europe/Amsterdam"); // true
var bool2 = db.hasDst("UTC"); // false

// Next daylight saving time change in unix utc milliseconds
var unixUtcMillis = db.nextDstChange("Europe/Amsterdam", 1427590799999); // 1427590800000

// For more features, see the docs.

```
Expand Down Expand Up @@ -644,6 +647,9 @@ The version of the included IANA time zone database is 2015e.

## Changelog

### 1.21.0 (2015-07-21)
* Add a method to TzDatabase to get the next DST transition moment after a given date

### 1.20.0 (2015-07-20)
* Make a TzDatabase class available with general info on all time zones

Expand Down
42 changes: 42 additions & 0 deletions dist/timezonecomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -4993,6 +4993,48 @@ var TzDatabase = (function () {
TzDatabase.prototype.hasDst = function (zoneName) {
return (this.maxDstSave(zoneName).milliseconds() !== 0);
};
/**
* First DST change moment AFTER the given UTC date in UTC milliseconds, within one year
*/
TzDatabase.prototype.nextDstChange = function (zoneName, utcMillis) {
var tm = basics.unixToTimeNoLeapSecs(utcMillis);
var zoneInfo;
var i;
// get all zone infos for [date, date+1year)
var allZoneInfos = this.getZoneInfos(zoneName);
var relevantZoneInfos = [];
var rangeStart = utcMillis;
var rangeEnd = utcMillis + 365 * 24 * 3600 * 1000;
var prevEnd = null;
for (i = 0; i < allZoneInfos.length; ++i) {
zoneInfo = allZoneInfos[i];
if ((prevEnd === null || prevEnd < rangeEnd) && (zoneInfo.until === null || zoneInfo.until > rangeStart)) {
relevantZoneInfos.push(zoneInfo);
}
prevEnd = zoneInfo.until;
}
// collect all transitions in the zones for the year
var transitions = [];
for (i = 0; i < relevantZoneInfos.length; ++i) {
zoneInfo = relevantZoneInfos[i];
// find applicable transition moments
transitions = transitions.concat(this.getTransitionsDstOffsets(zoneInfo.ruleName, tm.year - 1, tm.year + 1, zoneInfo.gmtoff));
}
transitions.sort(function (a, b) {
return a.at - b.at;
});
// find the first after the given date that has a different offset
var prevSave = null;
for (i = 0; i < transitions.length; ++i) {
var transition = transitions[i];
if (!prevSave || !prevSave.equals(transition.offset)) {
if (transition.at > utcMillis) {
return transition.at;
}
}
prevSave = transition.offset;
}
};
/**
* Returns true iff the given zone name eventually links to
* "Etc/UTC", "Etc/GMT" or "Etc/UCT" in the TZ database. This is true e.g. for
Expand Down
2 changes: 1 addition & 1 deletion doc/assets/js/search.js

Large diffs are not rendered by default.

81 changes: 58 additions & 23 deletions doc/classes/_tz_database_.tzdatabase.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ <h3>Methods</h3>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#letterforrule" class="tsd-kind-icon">letter<wbr>For<wbr>Rule</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#maxdstsave" class="tsd-kind-icon">max<wbr>Dst<wbr>Save</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#mindstsave" class="tsd-kind-icon">min<wbr>Dst<wbr>Save</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#nextdstchange" class="tsd-kind-icon">next<wbr>Dst<wbr>Change</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#normalizelocal" class="tsd-kind-icon">normalize<wbr>Local</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#parseattype" class="tsd-kind-icon">parse<wbr>AtType</a></li>
<li class="tsd-kind-method tsd-parent-kind-class"><a href="_tz_database_.tzdatabase.html#parseonday" class="tsd-kind-icon">parse<wbr>OnDay</a></li>
Expand Down Expand Up @@ -199,7 +200,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> _rule<wbr>Info<wbr>Cach
<div class="tsd-signature tsd-kind-icon">_rule<wbr>Info<wbr>Cache<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">object</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1148</li>
<li>Defined in tz-database.ts:1194</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand All @@ -222,7 +223,7 @@ <h3><span class="tsd-flag ts-flagPrivate">Private</span> _zone<wbr>Info<wbr>Cach
<div class="tsd-signature tsd-kind-icon">_zone<wbr>Info<wbr>Cache<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">object</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1069</li>
<li>Defined in tz-database.ts:1115</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -267,7 +268,7 @@ <h3>abbreviation</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:744</li>
<li>Defined in tz-database.ts:790</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -313,7 +314,7 @@ <h3>dst<wbr>Offset<wbr>For<wbr>Rule</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:858</li>
<li>Defined in tz-database.ts:904</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -380,7 +381,7 @@ <h3>get<wbr>Rule<wbr>Infos</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1157</li>
<li>Defined in tz-database.ts:1203</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -413,7 +414,7 @@ <h3>get<wbr>Transitions<wbr>Dst<wbr>Offsets</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:924</li>
<li>Defined in tz-database.ts:970</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -463,7 +464,7 @@ <h3>get<wbr>Transitions<wbr>Total<wbr>Offsets</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:958</li>
<li>Defined in tz-database.ts:1004</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -507,7 +508,7 @@ <h3>get<wbr>Zone<wbr>Info</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1051</li>
<li>Defined in tz-database.ts:1097</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -545,7 +546,7 @@ <h3>get<wbr>Zone<wbr>Infos</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1078</li>
<li>Defined in tz-database.ts:1124</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -606,7 +607,7 @@ <h3>letter<wbr>For<wbr>Rule</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:890</li>
<li>Defined in tz-database.ts:936</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -706,6 +707,37 @@ <h4 class="tsd-returns-title">Returns <a href="_duration_.duration.html" class="
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="nextdstchange" class="tsd-anchor"></a>
<h3>next<wbr>Dst<wbr>Change</h3>
<ul class="tsd-signatures tsd-kind-method tsd-parent-kind-class">
<li class="tsd-signature tsd-kind-icon">next<wbr>Dst<wbr>Change<span class="tsd-signature-symbol">(</span>zoneName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, utcMillis<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:605</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>First DST change moment AFTER the given UTC date in UTC milliseconds, within one year</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>zoneName: <span class="tsd-signature-type">string</span></h5>
</li>
<li>
<h5>utcMillis: <span class="tsd-signature-type">number</span></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class">
<a name="normalizelocal" class="tsd-anchor"></a>
<h3>normalize<wbr>Local</h3>
Expand All @@ -717,7 +749,7 @@ <h3>normalize<wbr>Local</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:638</li>
<li>Defined in tz-database.ts:684</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -756,7 +788,7 @@ <h4 class="tsd-returns-title">Returns <a href="_basics_.timestruct.html" class="
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:639</li>
<li>Defined in tz-database.ts:685</li>
</ul>
</aside>
<h4 class="tsd-parameters-title">Parameters</h4>
Expand Down Expand Up @@ -785,7 +817,7 @@ <h3>parse<wbr>AtType</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1305</li>
<li>Defined in tz-database.ts:1351</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -814,7 +846,7 @@ <h3>parse<wbr>OnDay</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1270</li>
<li>Defined in tz-database.ts:1316</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -845,7 +877,7 @@ <h3>parse<wbr>OnType</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1254</li>
<li>Defined in tz-database.ts:1300</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -874,7 +906,7 @@ <h3>parse<wbr>OnWeek<wbr>Day</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1288</li>
<li>Defined in tz-database.ts:1334</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -902,7 +934,7 @@ <h3>parse<wbr>Rule<wbr>Type</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1220</li>
<li>Defined in tz-database.ts:1266</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -931,7 +963,7 @@ <h3>parse<wbr>ToType</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:1234</li>
<li>Defined in tz-database.ts:1280</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -960,7 +992,7 @@ <h3>standard<wbr>Offset</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:702</li>
<li>Defined in tz-database.ts:748</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -998,7 +1030,7 @@ <h3>standard<wbr>Offset<wbr>Local</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:776</li>
<li>Defined in tz-database.ts:822</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -1039,7 +1071,7 @@ <h3>total<wbr>Offset</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:715</li>
<li>Defined in tz-database.ts:761</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -1078,7 +1110,7 @@ <h3>total<wbr>Offset<wbr>Local</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:801</li>
<li>Defined in tz-database.ts:847</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -1119,7 +1151,7 @@ <h3>zone<wbr>IsUtc</h3>
<li class="tsd-description">
<aside class="tsd-sources">
<ul>
<li>Defined in tz-database.ts:609</li>
<li>Defined in tz-database.ts:655</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
Expand Down Expand Up @@ -1332,6 +1364,9 @@ <h4 class="tsd-returns-title">Returns <a href="_tz_database_.tzdatabase.html" cl
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="_tz_database_.tzdatabase.html#mindstsave" class="tsd-kind-icon">min<wbr>Dst<wbr>Save</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="_tz_database_.tzdatabase.html#nextdstchange" class="tsd-kind-icon">next<wbr>Dst<wbr>Change</a>
</li>
<li class=" tsd-kind-method tsd-parent-kind-class">
<a href="_tz_database_.tzdatabase.html#normalizelocal" class="tsd-kind-icon">normalize<wbr>Local</a>
</li>
Expand Down
13 changes: 10 additions & 3 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ <h3 id="timezone">TimeZone</h3>
<span class="hljs-keyword">var</span> bool1 = db.hasDst(<span class="hljs-string">"Europe/Amsterdam"</span>); <span class="hljs-comment">// true</span>
<span class="hljs-keyword">var</span> bool2 = db.hasDst(<span class="hljs-string">"UTC"</span>); <span class="hljs-comment">// false</span>

<span class="hljs-comment">// Next daylight saving time change in unix utc milliseconds</span>
<span class="hljs-keyword">var</span> unixUtcMillis = db.nextDstChange(<span class="hljs-string">"Europe/Amsterdam"</span>, <span class="hljs-number">1427590799999</span>); <span class="hljs-comment">// 1427590800000</span>

<span class="hljs-comment">// For more features, see the docs.</span>
</code></pre>
<h3 id="datetime">DateTime</h3>
Expand Down Expand Up @@ -648,6 +651,10 @@ <h3 id="does-timezonecomplete-handle-leap-seconds-">Does timezonecomplete handle
<h2 id="current-tz-database-version-">Current TZ database version:</h2>
<p>The version of the included IANA time zone database is 2015e.</p>
<h2 id="changelog">Changelog</h2>
<h3 id="1-21-0-2015-07-21-">1.21.0 (2015-07-21)</h3>
<ul>
<li>Add a method to TzDatabase to get the next DST transition moment after a given date</li>
</ul>
<h3 id="1-20-0-2015-07-20-">1.20.0 (2015-07-20)</h3>
<ul>
<li>Make a TzDatabase class available with general info on all time zones</li>
Expand Down Expand Up @@ -927,9 +934,9 @@ <h3 id="1-0-0-2014-06-26-">1.0.0 (2014-06-26)</h3>
</ul>
<h2 id="contributors">Contributors</h2>
<ul>
<li>Rogier Schouten <a href="&#x6d;&#x61;&#x69;&#108;&#x74;&#111;&#x3a;&#114;&#x2e;&#115;&#x63;&#x68;&#111;&#x75;&#x74;&#101;&#110;&#64;&#x73;&#x70;&#105;&#114;&#x69;&#x74;&#x69;&#116;&#x2e;&#x63;&#x6f;&#x6d;">&#114;&#x2e;&#115;&#x63;&#x68;&#111;&#x75;&#x74;&#101;&#110;&#64;&#x73;&#x70;&#105;&#114;&#x69;&#x74;&#x69;&#116;&#x2e;&#x63;&#x6f;&#x6d;</a></li>
<li>Daan Wissing <a href="&#109;&#x61;&#105;&#108;&#116;&#111;&#x3a;&#100;&#x2e;&#119;&#x69;&#x73;&#115;&#105;&#x6e;&#x67;&#x40;&#115;&#112;&#105;&#114;&#105;&#x74;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;">&#100;&#x2e;&#119;&#x69;&#x73;&#115;&#105;&#x6e;&#x67;&#x40;&#115;&#112;&#105;&#114;&#105;&#x74;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;</a></li>
<li>Peter Kooijmans <a href="&#x6d;&#x61;&#105;&#x6c;&#x74;&#111;&#58;&#x70;&#x2e;&#107;&#111;&#111;&#x69;&#x6a;&#109;&#97;&#110;&#x73;&#x40;&#x73;&#112;&#105;&#x72;&#x69;&#116;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;">&#x70;&#x2e;&#107;&#111;&#111;&#x69;&#x6a;&#109;&#97;&#110;&#x73;&#x40;&#x73;&#112;&#105;&#x72;&#x69;&#116;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;</a></li>
<li>Rogier Schouten <a href="&#109;&#x61;&#x69;&#108;&#x74;&#x6f;&#x3a;&#x72;&#x2e;&#115;&#x63;&#x68;&#x6f;&#x75;&#116;&#101;&#x6e;&#64;&#115;&#x70;&#105;&#x72;&#105;&#x74;&#105;&#x74;&#46;&#x63;&#111;&#109;">&#x72;&#x2e;&#115;&#x63;&#x68;&#x6f;&#x75;&#116;&#101;&#x6e;&#64;&#115;&#x70;&#105;&#x72;&#105;&#x74;&#105;&#x74;&#46;&#x63;&#111;&#109;</a></li>
<li>Daan Wissing <a href="&#x6d;&#x61;&#x69;&#x6c;&#116;&#111;&#x3a;&#100;&#x2e;&#x77;&#105;&#115;&#x73;&#x69;&#110;&#103;&#x40;&#115;&#112;&#x69;&#x72;&#x69;&#x74;&#105;&#x74;&#46;&#99;&#x6f;&#109;">&#100;&#x2e;&#x77;&#105;&#115;&#x73;&#x69;&#110;&#103;&#x40;&#115;&#112;&#x69;&#x72;&#x69;&#x74;&#105;&#x74;&#46;&#99;&#x6f;&#109;</a></li>
<li>Peter Kooijmans <a href="&#x6d;&#x61;&#105;&#108;&#116;&#x6f;&#58;&#x70;&#46;&#107;&#111;&#111;&#105;&#106;&#109;&#97;&#x6e;&#x73;&#64;&#x73;&#112;&#x69;&#x72;&#x69;&#116;&#105;&#x74;&#x2e;&#x63;&#x6f;&#109;">&#x70;&#46;&#107;&#111;&#111;&#105;&#106;&#109;&#97;&#x6e;&#x73;&#64;&#x73;&#112;&#x69;&#x72;&#x69;&#116;&#105;&#x74;&#x2e;&#x63;&#x6f;&#109;</a></li>
</ul>
<h2 id="license">License</h2>
<p>MIT</p>
Expand Down
Loading

0 comments on commit 1f1abff

Please sign in to comment.