Skip to content

Commit

Permalink
Version 1.14.0: add Duration.abs() and tc.abs() functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rogier Schouten committed Mar 12, 2015
1 parent 9338d80 commit cc64456
Show file tree
Hide file tree
Showing 17 changed files with 319 additions and 110 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ var duration5;
duration5 = duration3.max(duration4); // 6 seconds
duration5 = duration3.min(duration4); // 3 seconds

// absolute value
var negativeDuration = tc.seconds(-1);
negativeDuration.abs(); // 1 second
tc.abs(negativeDuration); // 1 second


// getters
// Note Duration has two sets of getters: singular and plural:
// - wholeHours(), minute(), second(), millisecond(): these get the hour part, minute part 0-59, second part 0-59 etc.
Expand Down Expand Up @@ -541,6 +547,9 @@ The version of the included IANA time zone database is 2015a.

## Changelog

### 1.14.0 (2015-03-12)
* Add Duration.abs() function and global abs() function

### 1.13.2 (2015-03-11)
* Allow "without DST" suffix in time zone name.

Expand Down
1 change: 0 additions & 1 deletion RELEASING.TXT
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ MODULE PUBLISH
* Adjust package.json and adjust version number
* Run:
gulp clean && gulp release && npm test
* Correct a bug in dts-bundle. The lib/timezonecomplete.d.ts file is missing a reference to timesource (near line 286), you can see this by diffing with the version stored in DefinitelyTyped. Add it back.
* Commit changes and Sync with GitHub
* In GitHub, create a release tag
* Ensure .npmrc points to the world NPM repository, not the spirit repository
Expand Down
20 changes: 20 additions & 0 deletions dist/timezonecomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,17 @@ var Duration = (function () {
Duration.prototype.sub = function (value) {
return new Duration(this.milliseconds() - value.milliseconds());
};
/**
* Return the absolute value of the duration i.e. remove the sign.
*/
Duration.prototype.abs = function () {
if (this._sign >= 0) {
return this.clone();
}
else {
return this.multiply(-1);
}
};
/**
* String in [-]hh:mm:ss.nnn notation. All fields are
* always present except the sign.
Expand Down Expand Up @@ -2379,6 +2390,15 @@ function max(d1, d2) {
return d1.max(d2);
}
exports.max = max;
/**
* Returns the absolute value of a Duration
*/
function abs(d) {
assert(d, "first argument is null");
assert(d instanceof Duration, "first argument is not a Duration");
return d.abs();
}
exports.abs = abs;


},{"./datetime":2,"./duration":3,"assert":18}],"Focm2+":[function(require,module,exports){
Expand Down
2 changes: 1 addition & 1 deletion doc/assets/js/search.js

Large diffs are not rendered by default.

205 changes: 116 additions & 89 deletions doc/classes/_duration_.duration.html

Large diffs are not rendered by default.

16 changes: 13 additions & 3 deletions doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ <h3 id="duration">Duration</h3>
duration5 = duration3.max(duration4); <span class="hljs-comment">// 6 seconds</span>
duration5 = duration3.min(duration4); <span class="hljs-comment">// 3 seconds</span>

<span class="hljs-comment">// absolute value</span>
<span class="hljs-keyword">var</span> negativeDuration = tc.seconds(-<span class="hljs-number">1</span>);
negativeDuration.abs(); <span class="hljs-comment">// 1 second</span>
tc.abs(negativeDuration); <span class="hljs-comment">// 1 second</span>


<span class="hljs-comment">// getters</span>
<span class="hljs-comment">// Note Duration has two sets of getters: singular and plural:</span>
<span class="hljs-comment">// - wholeHours(), minute(), second(), millisecond(): these get the hour part, minute part 0-59, second part 0-59 etc.</span>
Expand Down Expand Up @@ -543,6 +549,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 2015a.</p>
<h2 id="changelog">Changelog</h2>
<h3 id="1-14-0-2015-03-12-">1.14.0 (2015-03-12)</h3>
<ul>
<li>Add Duration.abs() function and global abs() function</li>
</ul>
<h3 id="1-13-2-2015-03-11-">1.13.2 (2015-03-11)</h3>
<ul>
<li>Allow &quot;without DST&quot; suffix in time zone name.</li>
Expand Down Expand Up @@ -754,9 +764,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="&#109;&#97;&#x69;&#x6c;&#116;&#111;&#58;&#x72;&#x2e;&#x73;&#99;&#x68;&#x6f;&#x75;&#x74;&#x65;&#110;&#x40;&#x73;&#112;&#x69;&#114;&#x69;&#116;&#105;&#x74;&#46;&#99;&#x6f;&#x6d;">&#x72;&#x2e;&#x73;&#99;&#x68;&#x6f;&#x75;&#x74;&#x65;&#110;&#x40;&#x73;&#112;&#x69;&#114;&#x69;&#116;&#105;&#x74;&#46;&#99;&#x6f;&#x6d;</a></li>
<li>Daan Wissing <a href="&#109;&#97;&#105;&#108;&#x74;&#x6f;&#x3a;&#x64;&#46;&#x77;&#x69;&#115;&#115;&#x69;&#110;&#103;&#64;&#x73;&#x70;&#105;&#x72;&#105;&#x74;&#105;&#116;&#x2e;&#99;&#111;&#109;">&#x64;&#46;&#x77;&#x69;&#115;&#115;&#x69;&#110;&#103;&#64;&#x73;&#x70;&#105;&#x72;&#105;&#x74;&#105;&#116;&#x2e;&#99;&#111;&#109;</a></li>
<li>Peter Kooijmans <a href="&#109;&#97;&#x69;&#108;&#x74;&#x6f;&#58;&#112;&#46;&#107;&#111;&#x6f;&#x69;&#x6a;&#109;&#x61;&#110;&#x73;&#x40;&#x73;&#x70;&#x69;&#114;&#x69;&#x74;&#x69;&#x74;&#x2e;&#x63;&#x6f;&#x6d;">&#112;&#46;&#107;&#111;&#x6f;&#x69;&#x6a;&#109;&#x61;&#110;&#x73;&#x40;&#x73;&#x70;&#x69;&#114;&#x69;&#x74;&#x69;&#x74;&#x2e;&#x63;&#x6f;&#x6d;</a></li>
<li>Rogier Schouten <a href="&#x6d;&#x61;&#105;&#x6c;&#116;&#111;&#58;&#114;&#46;&#x73;&#x63;&#104;&#111;&#x75;&#116;&#101;&#x6e;&#x40;&#115;&#x70;&#105;&#114;&#x69;&#x74;&#105;&#x74;&#46;&#x63;&#111;&#x6d;">&#114;&#46;&#x73;&#x63;&#104;&#111;&#x75;&#116;&#101;&#x6e;&#x40;&#115;&#x70;&#105;&#114;&#x69;&#x74;&#105;&#x74;&#46;&#x63;&#111;&#x6d;</a></li>
<li>Daan Wissing <a href="&#109;&#97;&#105;&#x6c;&#116;&#x6f;&#58;&#x64;&#46;&#x77;&#x69;&#x73;&#x73;&#105;&#x6e;&#x67;&#x40;&#115;&#112;&#x69;&#x72;&#105;&#x74;&#x69;&#116;&#x2e;&#x63;&#111;&#109;">&#x64;&#46;&#x77;&#x69;&#x73;&#x73;&#105;&#x6e;&#x67;&#x40;&#115;&#112;&#x69;&#x72;&#105;&#x74;&#x69;&#116;&#x2e;&#x63;&#111;&#109;</a></li>
<li>Peter Kooijmans <a href="&#x6d;&#97;&#105;&#x6c;&#116;&#111;&#x3a;&#112;&#x2e;&#107;&#x6f;&#111;&#105;&#x6a;&#109;&#x61;&#110;&#115;&#64;&#x73;&#112;&#x69;&#x72;&#105;&#116;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;">&#112;&#x2e;&#107;&#x6f;&#111;&#105;&#x6a;&#109;&#x61;&#110;&#115;&#64;&#x73;&#112;&#x69;&#x72;&#105;&#116;&#x69;&#x74;&#x2e;&#99;&#x6f;&#109;</a></li>
</ul>
<h2 id="license">License</h2>
<p>MIT</p>
Expand Down
55 changes: 44 additions & 11 deletions doc/modules/_globals_.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ <h2>Index</h2>
<section class="tsd-index-section ">
<h3>Functions</h3>
<ul class="tsd-index-list">
<li class="tsd-kind-function tsd-parent-kind-dynamic-module"><a href="_globals_.html#abs" class="tsd-kind-icon">abs</a></li>
<li class="tsd-kind-function tsd-parent-kind-dynamic-module"><a href="_globals_.html#max" class="tsd-kind-icon">max</a></li>
<li class="tsd-kind-function tsd-parent-kind-dynamic-module"><a href="_globals_.html#min" class="tsd-kind-icon">min</a></li>
</ul>
Expand All @@ -83,6 +84,35 @@ <h3>Functions</h3>
</section>
<section class="tsd-panel-group tsd-member-group ">
<h2>Functions</h2>
<section class="tsd-panel tsd-member tsd-kind-function tsd-parent-kind-dynamic-module">
<a name="abs" class="anchor"></a>
<h3>abs</h3>
<ul class="tsd-signatures tsd-kind-function tsd-parent-kind-dynamic-module">
<li class="tsd-signature tsd-kind-icon">abs<span class="tsd-signature-symbol">(</span>d<span class="tsd-signature-symbol">: </span><a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in globals.ts:62</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns the absolute value of a Duration</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>d: <a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns
<a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a>
</h4>
</li>
</ul>
</section>
<section class="tsd-panel tsd-member tsd-kind-function tsd-parent-kind-dynamic-module">
<a name="max" class="anchor"></a>
<h3>max</h3>
Expand Down Expand Up @@ -167,54 +197,54 @@ <h4 class="tsd-returns-title">Returns
<a name="min" class="anchor"></a>
<h3>min</h3>
<ul class="tsd-signatures tsd-kind-function tsd-parent-kind-dynamic-module">
<li class="tsd-signature tsd-kind-icon">min<span class="tsd-signature-symbol">(</span>d1<span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a>, d2<span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></li>
<li class="tsd-signature tsd-kind-icon">min<span class="tsd-signature-symbol">(</span>d1<span class="tsd-signature-symbol">: </span><a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a>, d2<span class="tsd-signature-symbol">: </span><a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></li>
<li class="tsd-signature tsd-kind-icon">min<span class="tsd-signature-symbol">(</span>d1<span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a>, d2<span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></li>
</ul>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in globals.ts:22</li>
<li>Defined in globals.ts:26</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns the minimum of two DateTimes</p>
<p>Returns the minimum of two Durations</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>d1: <a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></h5>
<h5>d1: <a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></h5>
</li>
<li>
<h5>d2: <a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></h5>
<h5>d2: <a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns
<a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a>
<a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a>
</h4>
</li>
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in globals.ts:26</li>
<li>Defined in globals.ts:22</li>
</ul>
</aside>
<div class="tsd-comment tsd-typography">
<div class="lead">
<p>Returns the minimum of two Durations</p>
<p>Returns the minimum of two DateTimes</p>
</div>
</div>
<h4 class="tsd-parameters-title">Parameters</h4>
<ul class="tsd-parameters">
<li>
<h5>d1: <a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></h5>
<h5>d1: <a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></h5>
</li>
<li>
<h5>d2: <a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a></h5>
<h5>d2: <a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a></h5>
</li>
</ul>
<h4 class="tsd-returns-title">Returns
<a href="../classes/_duration_.duration.html" class="tsd-signature-type">Duration</a>
<a href="../classes/_datetime_.datetime.html" class="tsd-signature-type">DateTime</a>
</h4>
</li>
</ul>
Expand Down Expand Up @@ -273,6 +303,9 @@ <h4 class="tsd-returns-title">Returns
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="_globals_.html#abs" class="tsd-kind-icon">abs</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="_globals_.html#max" class="tsd-kind-icon">max</a>
</li>
Expand Down
Loading

0 comments on commit cc64456

Please sign in to comment.