Skip to content

Commit

Permalink
Adjusted documentation and some function names; exported more utility…
Browse files Browse the repository at this point in the history
… functions.
  • Loading branch information
Rogier Schouten committed Aug 20, 2014
1 parent 1216de8 commit ad1ac23
Show file tree
Hide file tree
Showing 19 changed files with 145 additions and 80 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ Timezonecomplete defines a number of utility functions.
```javascript
var tc = require("timezonecomplete");

// n-th day of the year, counting from 0
tc.dayOfYear(2014, 1, 1); // returns 0
tc.dayOfYear(2014, 2, 1); // returns 31

// number of days in a month, accounting for leap years
tc.daysInMonth(2004, 2); // returns 29
tc.daysInMonth(2014, 2); // returns 28
Expand All @@ -79,6 +75,9 @@ tc.daysInYear(2014); // returns 365
tc.isLeapYear(2004); // returns true
tc.isLeapYear(2014); // returns false

// first Monday of August in 2014
tc.firstWeekDayOfMonth(2014, 8, tc.WeekDay.Monday); // returns 4

// last Monday of August in 2014
tc.lastWeekDayOfMonth(2014, 8, tc.WeekDay.Monday); // returns 25

Expand All @@ -91,6 +90,16 @@ tc.weekDayOnOrBefore(2014, 8, 15, tc.WeekDay.Sunday); // returns 10
// Week number according to ISO 8601 (note this does NOT match American week numbers)
tc.weekNumber(2013, 12, 30); // 1

// Week of the month
tc.weekOfMonth(2013, 12, 30); // 1 (because it's part of the first week of January)

// n-th day of the year, counting from 0
tc.dayOfYear(2014, 1, 1); // returns 0
tc.dayOfYear(2014, 2, 1); // returns 31

// n-th second of the day, counting from 0
tc.secondOfDay(1, 0, 0); // returns 3600

```

### Duration
Expand Down Expand Up @@ -207,7 +216,9 @@ amsterdamDate.second(); // 59
amsterdamDate.millisecond(); // 0
amsterdamDate.weekDay(); // tc.WeekDay.Wednesday = 3
amsterdamDate.weekNumber(); // ISO week number 1-53 = 1
amsterdamDate.weekOfMonth(); // 1
amsterdamDate.dayOfYear(); // 0th day of year
amsterdamDate.secondOfDay(); // 50399

// UTC getters
amsterdamDate.utcYear(); // 2014
Expand All @@ -219,7 +230,9 @@ amsterdamDate.utcSecond(); // 59
amsterdamDate.utcMillisecond(); // 0
amsterdamDate.utcWeekDay(); // tc.WeekDay.Wednesday = 3
amsterdamDate.utcWeekNumber(); // ISO week number 1-53 = 1
amsterdamDate.utcWeekOfMonth(); // 1
amsterdamDate.utcDayOfYear(); // 0th day of year
amsterdamDate.utcSecondOfDay(); // 46799

// Unix millisecond timestamp getter
amsterdamDate.unixUtcMillis(); // milliseconds of UTC date since 1970-01-01
Expand Down Expand Up @@ -397,13 +410,17 @@ The version of the included IANA time zone database is 2014e.
* Leap second handling

### Next (already implemented, not published)
* Add format() function to DateTime to convert a DateTime to a string with a specified format.
* Add valueOf() method to DateTime and Duration
* Add dayOfYear() and utcDayOfYear() to DateTime returning the n-th day of the year, starting at 0
* Add weekNumber() utility function (ISO week number)
* Add weekNumber() and utcWeekNumber() methods to DateTime
* Add weekOfMonth() utility function (ISO week number)
* Add weekOfMonth() and utcWeekOfMonth() methods to DateTime
* Add secondOfDay() utility function (ISO week number)
* Add secondOfDay() and utcSecondOfDay() methods to DateTime
* Add abbreviationForUtc() to TimeZone
* Add zoneAbbreviation() to DateTime to get time zone abbreviation at the specified datetime.
* Add format() function to DateTime to convert a DateTime to a string with a specified format.

### 1.4.6 (2014-08-15)
* Bugfix TypeScript .d.ts file
Expand Down
23 changes: 16 additions & 7 deletions dist/timezonecomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,13 @@ function weekDayNoLeapSecs(unixMillis) {
}
exports.weekDayNoLeapSecs = weekDayNoLeapSecs;

function secondInDay(hour, minute, second) {
/**
* N-th second in the day, counting from 0
*/
function secondPfDay(hour, minute, second) {
return (((hour * 60) + minute) * 60) + second;
}
exports.secondInDay = secondInDay;
exports.secondPfDay = secondPfDay;

/**
* Basic representation of a date and time
Expand Down Expand Up @@ -998,7 +1001,7 @@ var DateTime = (function () {
* @return seconds [0-86399]
*/
DateTime.prototype.secondOfDay = function () {
return basics.secondInDay(this.hour(), this.minute(), this.second());
return basics.secondPfDay(this.hour(), this.minute(), this.second());
};

/**
Expand Down Expand Up @@ -1104,7 +1107,7 @@ var DateTime = (function () {
* @return seconds [0-86399]
*/
DateTime.prototype.utcSecondOfDay = function () {
return basics.secondInDay(this.utcHour(), this.utcMinute(), this.utcSecond());
return basics.secondPfDay(this.utcHour(), this.utcMinute(), this.utcSecond());
};

/**
Expand Down Expand Up @@ -1794,8 +1797,8 @@ var daysInMonth = basics.daysInMonth;
exports.daysInMonth = daysInMonth;
var daysInYear = basics.daysInYear;
exports.daysInYear = daysInYear;
var dayOfYear = basics.dayOfYear;
exports.dayOfYear = dayOfYear;
var firstWeekDayOfMonth = basics.firstWeekDayOfMonth;
exports.firstWeekDayOfMonth = firstWeekDayOfMonth;
var lastWeekDayOfMonth = basics.lastWeekDayOfMonth;
exports.lastWeekDayOfMonth = lastWeekDayOfMonth;
var weekDayOnOrAfter = basics.weekDayOnOrAfter;
Expand All @@ -1804,6 +1807,12 @@ var weekDayOnOrBefore = basics.weekDayOnOrBefore;
exports.weekDayOnOrBefore = weekDayOnOrBefore;
var weekNumber = basics.weekNumber;
exports.weekNumber = weekNumber;
var weekOfMonth = basics.weekOfMonth;
exports.weekOfMonth = weekOfMonth;
var dayOfYear = basics.dayOfYear;
exports.dayOfYear = dayOfYear;
var secondPfDay = basics.secondPfDay;
exports.secondPfDay = secondPfDay;

var datetime = require("./datetime");
datetime;
Expand Down Expand Up @@ -2187,7 +2196,7 @@ function _formatSecond(dateTime, token) {
fractionString = strings.padRight(fractionString, token.length, "0");
return fractionString.slice(0, token.length);
case "A":
return strings.padLeft(basics.secondInDay(dateTime.hour, dateTime.minute, dateTime.second).toString(), token.length, "0");
return strings.padLeft(basics.secondPfDay(dateTime.hour, dateTime.minute, dateTime.second).toString(), token.length, "0");

default:
/* istanbul ignore if */
Expand Down
2 changes: 1 addition & 1 deletion doc/assets/js/search.js

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions doc/classes/_basics_.timestruct.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ <h3>constructor</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:585</li>
<li>Defined in basics.ts:588</li>
</ul>
</aside>
<p>Constructor</p>
Expand Down Expand Up @@ -157,7 +157,7 @@ <h3>day</h3>
<div class="tsd-signature tsd-kind-icon">day<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:599</li>
<li>Defined in basics.ts:602</li>
</ul>
</aside>
<p>Day of month, 1-31</p>
Expand All @@ -168,7 +168,7 @@ <h3>hour</h3>
<div class="tsd-signature tsd-kind-icon">hour<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:604</li>
<li>Defined in basics.ts:607</li>
</ul>
</aside>
<p>Hour 0-23</p>
Expand All @@ -179,7 +179,7 @@ <h3>milli</h3>
<div class="tsd-signature tsd-kind-icon">milli<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:619</li>
<li>Defined in basics.ts:622</li>
</ul>
</aside>
<p>Milliseconds 0-999</p>
Expand All @@ -190,7 +190,7 @@ <h3>minute</h3>
<div class="tsd-signature tsd-kind-icon">minute<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:609</li>
<li>Defined in basics.ts:612</li>
</ul>
</aside>
<p>Minute 0-59</p>
Expand All @@ -201,7 +201,7 @@ <h3>month</h3>
<div class="tsd-signature tsd-kind-icon">month<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:594</li>
<li>Defined in basics.ts:597</li>
</ul>
</aside>
<p>Month 1-12</p>
Expand All @@ -212,7 +212,7 @@ <h3>second</h3>
<div class="tsd-signature tsd-kind-icon">second<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:614</li>
<li>Defined in basics.ts:617</li>
</ul>
</aside>
<p>Seconds, 0-59</p>
Expand All @@ -223,7 +223,7 @@ <h3>year</h3>
<div class="tsd-signature tsd-kind-icon">year<span class="tsd-signature-symbols">:</span> <span class="tsd-signature-type">number</span></div>
<aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:589</li>
<li>Defined in basics.ts:592</li>
</ul>
</aside>
<p>Year, 1970-...</p>
Expand All @@ -240,7 +240,7 @@ <h3>clone</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:677</li>
<li>Defined in basics.ts:680</li>
</ul>
</aside>
<h4>Returns
Expand All @@ -258,7 +258,7 @@ <h3>equals</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:660</li>
<li>Defined in basics.ts:663</li>
</ul>
</aside>
<p>Deep equals</p>
Expand All @@ -283,7 +283,7 @@ <h3><span class="tsd-flag ts-flagstatic">static</span> from<wbr>Date</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:446</li>
<li>Defined in basics.ts:449</li>
</ul>
</aside>
<p>Create a TimeStruct from a JavaScript date</p>
Expand Down Expand Up @@ -313,7 +313,7 @@ <h3><span class="tsd-flag ts-flagstatic">static</span> from<wbr>String</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:459</li>
<li>Defined in basics.ts:462</li>
</ul>
</aside>
<p>Returns a TimeStruct from an ISO 8601 string WITHOUT time zone</p>
Expand All @@ -338,7 +338,7 @@ <h3><span class="tsd-flag ts-flagstatic">static</span> from<wbr>Unix</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:436</li>
<li>Defined in basics.ts:439</li>
</ul>
</aside>
<p>Create a TimeStruct from a number of unix milliseconds</p>
Expand All @@ -363,7 +363,7 @@ <h3>inspect</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:698</li>
<li>Defined in basics.ts:701</li>
</ul>
</aside>
<h4>Returns
Expand All @@ -381,7 +381,7 @@ <h3>less<wbr>Than</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:673</li>
<li>Defined in basics.ts:676</li>
</ul>
</aside>
<p>&lt; operator</p>
Expand All @@ -406,7 +406,7 @@ <h3>to<wbr>String</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:688</li>
<li>Defined in basics.ts:691</li>
</ul>
</aside>
<p>ISO 8601 string YYYY-MM-DDThh:mm:ss.nnn</p>
Expand All @@ -425,7 +425,7 @@ <h3>to<wbr>Unix<wbr>NoLeap<wbr>Secs</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:652</li>
<li>Defined in basics.ts:655</li>
</ul>
</aside>
<p>Returns this time as a unix millisecond timestamp
Expand All @@ -445,7 +445,7 @@ <h3>validate</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:627</li>
<li>Defined in basics.ts:630</li>
</ul>
</aside>
<p>Validate a TimeStruct, returns false if invalid.</p>
Expand All @@ -464,7 +464,7 @@ <h3>value<wbr>Of</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:681</li>
<li>Defined in basics.ts:684</li>
</ul>
</aside>
<h4>Returns
Expand All @@ -482,7 +482,7 @@ <h3>year<wbr>Day</h3>
<ul class="tsd-descriptions">
<li class="tsd-description"><aside class="tsd-sources">
<ul>
<li>Defined in basics.ts:643</li>
<li>Defined in basics.ts:646</li>
</ul>
</aside>
<p>The day-of-year 0-365</p>
Expand Down Expand Up @@ -639,7 +639,7 @@ <h4>Returns
<a href="../modules/_basics_.html#lastweekdayofmonth" class="tsd-kind-icon">last<wbr>Week<wbr>Day<wbr>OfMonth</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#secondinday" class="tsd-kind-icon">second<wbr>InDay</a>
<a href="../modules/_basics_.html#secondpfday" class="tsd-kind-icon">second<wbr>PfDay</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#timetounixnoleapsecs" class="tsd-kind-icon">time<wbr>ToUnix<wbr>NoLeap<wbr>Secs</a>
Expand Down
2 changes: 1 addition & 1 deletion doc/enums/_basics_.timeunit.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ <h3>Year</h3>
<a href="../modules/_basics_.html#lastweekdayofmonth" class="tsd-kind-icon">last<wbr>Week<wbr>Day<wbr>OfMonth</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#secondinday" class="tsd-kind-icon">second<wbr>InDay</a>
<a href="../modules/_basics_.html#secondpfday" class="tsd-kind-icon">second<wbr>PfDay</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#timetounixnoleapsecs" class="tsd-kind-icon">time<wbr>ToUnix<wbr>NoLeap<wbr>Secs</a>
Expand Down
2 changes: 1 addition & 1 deletion doc/enums/_basics_.weekday.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ <h3>Wednesday</h3>
<a href="../modules/_basics_.html#lastweekdayofmonth" class="tsd-kind-icon">last<wbr>Week<wbr>Day<wbr>OfMonth</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#secondinday" class="tsd-kind-icon">second<wbr>InDay</a>
<a href="../modules/_basics_.html#secondpfday" class="tsd-kind-icon">second<wbr>PfDay</a>
</li>
<li class=" tsd-kind-function tsd-parent-kind-dynamic-module">
<a href="../modules/_basics_.html#timetounixnoleapsecs" class="tsd-kind-icon">time<wbr>ToUnix<wbr>NoLeap<wbr>Secs</a>
Expand Down
Loading

0 comments on commit ad1ac23

Please sign in to comment.