Skip to content

Commit

Permalink
Merge pull request #247 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Nov 26, 2020
2 parents 0502b83 + a4503a5 commit 49bce7f
Show file tree
Hide file tree
Showing 18 changed files with 1,067 additions and 50 deletions.
2 changes: 1 addition & 1 deletion _version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '6.10.1'
module.exports = '6.11.0'
25 changes: 16 additions & 9 deletions builds/spacetime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* spencermountain/spacetime 6.10.1 Apache 2.0 */
/* spencermountain/spacetime 6.11.0 Apache 2.0 */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
Expand Down Expand Up @@ -189,8 +189,8 @@
"-8|n|03/08:02->11/01:02": "1/anchorage,1/juneau,1/metlakatla,1/nome,1/sitka,1/yakutat",
"-8|n": "11/pitcairn",
"-7|n|03/08:02->11/01:02": "1/ensenada,1/los_angeles,1/santa_isabel,1/tijuana,1/vancouver,6/pacific,10/bajanorte",
"-7|n|03/08:02->11/01:01": "6/yukon",
"-7|n": "1/creston,1/dawson,1/dawson_creek,1/fort_nelson,1/hermosillo,1/phoenix,1/whitehorse",
"-7|n|03/08:02->11/01:01": "1/dawson,1/whitehorse,6/yukon",
"-7|n": "1/creston,1/dawson_creek,1/fort_nelson,1/hermosillo,1/phoenix",
"-6|s|04/04:22->09/05:22": "7/easterisland,11/easter",
"-6|n|04/05:02->10/25:02": "1/chihuahua,1/mazatlan,10/bajasur",
"-6|n|03/08:02->11/01:02": "1/boise,1/cambridge_bay,1/denver,1/edmonton,1/inuvik,1/ojinaga,1/shiprock,1/yellowknife,6/mountain",
Expand Down Expand Up @@ -684,7 +684,7 @@
} //this is a fancy-move


if (offset === 'Z') {
if (offset === 'Z' || offset === 'z') {
offset = '+0000';
} // according to ISO8601, tz could be hh:mm, hhmm or hh
// so need few more steps before the calculation.
Expand Down Expand Up @@ -759,6 +759,11 @@
return s.startOf('day');
}

if (arr[4] > 999) {
// fix overflow issue with milliseconds, if input is longer than standard (e.g. 2017-08-06T09:00:00.123456Z)
arr[4] = parseInt("".concat(arr[4]).substring(0, 3), 10);
}

s = s.hour(h);
s = s.minute(m);
s = s.seconds(arr[3] || 0);
Expand Down Expand Up @@ -988,7 +993,7 @@

var strFmt = [//iso-this 1998-05-30T22:00:00:000Z, iso-that 2017-04-03T08:00:00-0700
{
reg: /^(\-?0?0?[0-9]{3,4})-([0-9]{1,2})-([0-9]{1,2})[T| ]([0-9.:]+)(Z|[0-9\-\+:]+)?$/,
reg: /^(\-?0?0?[0-9]{3,4})-([0-9]{1,2})-([0-9]{1,2})[T| ]([0-9.:]+)(Z|[0-9\-\+:]+)?$/i,
parse: function parse(s, arr, givenTz, options) {
var month = parseInt(arr[2], 10) - 1;
var obj = {
Expand Down Expand Up @@ -3365,9 +3370,11 @@
s = s.month(0);
s = s.date(1);
s = s.day('monday');
s = clearMinutes(s); //don't go into last-year
s = clearMinutes(s); //first week starts first Thurs in Jan
// so mon dec 28th is 1st week
// so mon dec 29th is not the week

if (s.monthName() === 'december') {
if (s.monthName() === 'december' && s.date() >= 28) {
s = s.add(1, 'week');
}

Expand All @@ -3384,7 +3391,7 @@
tmp = clearMinutes(tmp);
tmp = tmp.day('monday'); //don't go into last-year

if (tmp.monthName() === 'december') {
if (tmp.monthName() === 'december' && tmp.date() >= 28) {
tmp = tmp.add(1, 'week');
} // is first monday the 1st?

Expand Down Expand Up @@ -4171,7 +4178,7 @@

var whereIts_1 = whereIts;

var _version = '6.10.1';
var _version = '6.11.0';

var main$1 = function main(input, tz, options) {
return new spacetime(input, tz, options);
Expand Down
2 changes: 1 addition & 1 deletion builds/spacetime.min.js

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions builds/spacetime.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* spencermountain/spacetime 6.10.1 Apache 2.0 */
/* spencermountain/spacetime 6.11.0 Apache 2.0 */
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
Expand Down Expand Up @@ -183,8 +183,8 @@ var _build = {
"-8|n|03/08:02->11/01:02": "1/anchorage,1/juneau,1/metlakatla,1/nome,1/sitka,1/yakutat",
"-8|n": "11/pitcairn",
"-7|n|03/08:02->11/01:02": "1/ensenada,1/los_angeles,1/santa_isabel,1/tijuana,1/vancouver,6/pacific,10/bajanorte",
"-7|n|03/08:02->11/01:01": "6/yukon",
"-7|n": "1/creston,1/dawson,1/dawson_creek,1/fort_nelson,1/hermosillo,1/phoenix,1/whitehorse",
"-7|n|03/08:02->11/01:01": "1/dawson,1/whitehorse,6/yukon",
"-7|n": "1/creston,1/dawson_creek,1/fort_nelson,1/hermosillo,1/phoenix",
"-6|s|04/04:22->09/05:22": "7/easterisland,11/easter",
"-6|n|04/05:02->10/25:02": "1/chihuahua,1/mazatlan,10/bajasur",
"-6|n|03/08:02->11/01:02": "1/boise,1/cambridge_bay,1/denver,1/edmonton,1/inuvik,1/ojinaga,1/shiprock,1/yellowknife,6/mountain",
Expand Down Expand Up @@ -678,7 +678,7 @@ var parseOffset$1 = function parseOffset(s, offset) {
} //this is a fancy-move


if (offset === 'Z') {
if (offset === 'Z' || offset === 'z') {
offset = '+0000';
} // according to ISO8601, tz could be hh:mm, hhmm or hh
// so need few more steps before the calculation.
Expand Down Expand Up @@ -753,6 +753,11 @@ var parseTime = function parseTime(s) {
return s.startOf('day');
}

if (arr[4] > 999) {
// fix overflow issue with milliseconds, if input is longer than standard (e.g. 2017-08-06T09:00:00.123456Z)
arr[4] = parseInt("".concat(arr[4]).substring(0, 3), 10);
}

s = s.hour(h);
s = s.minute(m);
s = s.seconds(arr[3] || 0);
Expand Down Expand Up @@ -982,7 +987,7 @@ var parseYear = function parseYear() {

var strFmt = [//iso-this 1998-05-30T22:00:00:000Z, iso-that 2017-04-03T08:00:00-0700
{
reg: /^(\-?0?0?[0-9]{3,4})-([0-9]{1,2})-([0-9]{1,2})[T| ]([0-9.:]+)(Z|[0-9\-\+:]+)?$/,
reg: /^(\-?0?0?[0-9]{3,4})-([0-9]{1,2})-([0-9]{1,2})[T| ]([0-9.:]+)(Z|[0-9\-\+:]+)?$/i,
parse: function parse(s, arr, givenTz, options) {
var month = parseInt(arr[2], 10) - 1;
var obj = {
Expand Down Expand Up @@ -3359,9 +3364,11 @@ var methods$3 = {
s = s.month(0);
s = s.date(1);
s = s.day('monday');
s = clearMinutes(s); //don't go into last-year
s = clearMinutes(s); //first week starts first Thurs in Jan
// so mon dec 28th is 1st week
// so mon dec 29th is not the week

if (s.monthName() === 'december') {
if (s.monthName() === 'december' && s.date() >= 28) {
s = s.add(1, 'week');
}

Expand All @@ -3378,7 +3385,7 @@ var methods$3 = {
tmp = clearMinutes(tmp);
tmp = tmp.day('monday'); //don't go into last-year

if (tmp.monthName() === 'december') {
if (tmp.monthName() === 'december' && tmp.date() >= 28) {
tmp = tmp.add(1, 'week');
} // is first monday the 1st?

Expand Down Expand Up @@ -4165,7 +4172,7 @@ var whereIts = function whereIts(a, b) {

var whereIts_1 = whereIts;

var _version = '6.10.1';
var _version = '6.11.0';

var main$1 = function main(input, tz, options) {
return new spacetime(input, tz, options);
Expand Down
6 changes: 6 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ This project follows semVer, where:
<!-- [unreleased]
-->

### v6.11.0
- **[change]** - support 6-digit millisecond, and lowercase iso
- **[change]** - first week of year must start > dec 29th
- **[fix]** - typescript fixes
- update deps

### v6.10.1
- **[fix]** - keep yukon dst changes (for now!) #243
- **[fix]** - support new-zealand time in '13h' format #242
Expand Down
27 changes: 22 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spacetime",
"version": "6.10.1",
"version": "6.11.0",
"description": "figure-out dates across timezones",
"main": "builds/spacetime.js",
"unpkg": "builds/spacetime.min.js",
Expand Down Expand Up @@ -39,7 +39,7 @@
},
"dependencies": {},
"devDependencies": {
"@babel/core": "7.12.7",
"@babel/core": "7.12.9",
"@babel/preset-env": "7.12.7",
"amble": "1.1.0",
"codecov": "3.8.1",
Expand Down
58 changes: 58 additions & 0 deletions plugins/week-math/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<div align="center">

<div>calculate the nth day of a month</div>
<div><img src="https://cloud.githubusercontent.com/assets/399657/23590290/ede73772-01aa-11e7-8915-181ef21027bc.png" /></div>

<div align="center">
<a href="https://npmjs.org/package/spacetime-week-math">
<img src="https://img.shields.io/npm/v/spacetime-week-math.svg?style=flat-square" />
</a>
<!-- <a href="https://codecov.io/gh/spencermountain/spacetime-week-math">
<img src="https://codecov.io/gh/spencermountain/spacetime-week-math/branch/master/graph/badge.svg" />
</a> -->
<a href="https://unpkg.com/spacetime-week-math/builds/spacetime-week-math.min.js">
<img src="https://badge-size.herokuapp.com/spencermountain/spacetime-week-math/master/builds/spacetime-week-math.min.js" />
</a>
</div>
<div align="center">
<code>spacetime-week-math</code>
</div>
<sub>
by
<a href="https://spencermountain.github.io/">Spencer Kelly</a>
</sub>
</div>
<p></p>


a spacetime plugin to calculate the nth day of a month.

like `.week()` which is based on the year, `.monthWeek()` works as a getter+setter, based on the input param:
```js

// Oct 2020 starts on a thursday
let s = spacetime('saturday oct 10th 2020')
s.monthWeek()
// 2

s = s.monthWeek(1)
// Mon Sep 28th

```
the week numbers start at 1.

**Note:**
the getter/setter can produce different results:
```js
let s = spacetime('saturday oct 10th 2020')
s = s.monthWeek(1)
// Mon Sep 28th
s.monthWeek()
// 5
```
Sep 28th is considered the 5th week of September.


work-in-progress.

MIT
Loading

0 comments on commit 49bce7f

Please sign in to comment.