Skip to content

Commit

Permalink
Merge pull request #224 from spencermountain/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
spencermountain authored Aug 28, 2020
2 parents bf23ffd + c3208c5 commit af32453
Show file tree
Hide file tree
Showing 12 changed files with 199 additions and 148 deletions.
2 changes: 1 addition & 1 deletion _version.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = '6.6.2'
module.exports = '6.6.3'
57 changes: 38 additions & 19 deletions builds/spacetime.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* spencermountain/spacetime 6.6.2 Apache 2.0 */
/* spencermountain/spacetime 6.6.3 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 @@ -1170,40 +1170,50 @@
}];
var strParse = strFmt;

// pull in 'today' data for the baseline moment
var getNow = function getNow(s) {
s.epoch = Date.now();
Object.keys(s._today || {}).forEach(function (k) {
if (typeof s[k] === 'function') {
s = s[k](s._today[k]);
}
});
return s;
};

var dates = {
now: function now(s) {
s.epoch = Date.now();
return s;
},
tonight: function tonight(s) {
s.epoch = Date.now();
s = s.hour(18);
return s;
return getNow(s);
},
today: function today(s) {
s.epoch = Date.now();
return getNow(s);
},
tonight: function tonight(s) {
s = getNow(s);
s = s.hour(18); //6pm

return s;
},
tomorrow: function tomorrow(s) {
s.epoch = Date.now();
s = getNow(s);
s = s.add(1, 'day');
s = s.startOf('day');
return s;
},
yesterday: function yesterday(s) {
s.epoch = Date.now();
s = getNow(s);
s = s.subtract(1, 'day');
s = s.startOf('day');
return s;
},
christmas: function christmas(s) {
var year = new Date().getFullYear();
var year = getNow(s).year();
s = s.set([year, 11, 25, 18, 0, 0]); // Dec 25

return s;
},
'new years': function newYears(s) {
var year = new Date().getFullYear();
var year = getNow(s).year();
s = s.set([year, 11, 31, 18, 0, 0]); // Dec 31

return s;
Expand Down Expand Up @@ -1282,9 +1292,18 @@
} //set tmp time


s.epoch = Date.now();
s.epoch = Date.now(); // overwrite tmp time with 'today' value, if exists

if (s._today && fns.isObject(s._today) && Object.keys(s._today).length > 0) {
var res = handleObject(s, today, defaults);

if (res.isValid()) {
s.epoch = res.epoch;
}
} // null input means 'now'


if (input === null || input === undefined) {
if (input === null || input === undefined || input === '') {
return s; //k, we're good.
} //support input of Date() object

Expand Down Expand Up @@ -1333,10 +1352,10 @@
var m = input.match(strParse[i].reg);

if (m) {
var res = strParse[i].parse(s, m, givenTz);
var _res = strParse[i].parse(s, m, givenTz);

if (res !== null) {
return res;
if (_res !== null) {
return _res;
}
}
}
Expand Down Expand Up @@ -4053,7 +4072,7 @@

var whereIts_1 = whereIts;

var _version = '6.6.2';
var _version = '6.6.3';

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.

57 changes: 38 additions & 19 deletions builds/spacetime.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* spencermountain/spacetime 6.6.2 Apache 2.0 */
/* spencermountain/spacetime 6.6.3 Apache 2.0 */
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
Expand Down Expand Up @@ -1164,40 +1164,50 @@ var strFmt = [//iso-this 1998-05-30T22:00:00:000Z, iso-that 2017-04-03T08:00:00-
}];
var strParse = strFmt;

// pull in 'today' data for the baseline moment
var getNow = function getNow(s) {
s.epoch = Date.now();
Object.keys(s._today || {}).forEach(function (k) {
if (typeof s[k] === 'function') {
s = s[k](s._today[k]);
}
});
return s;
};

var dates = {
now: function now(s) {
s.epoch = Date.now();
return s;
},
tonight: function tonight(s) {
s.epoch = Date.now();
s = s.hour(18);
return s;
return getNow(s);
},
today: function today(s) {
s.epoch = Date.now();
return getNow(s);
},
tonight: function tonight(s) {
s = getNow(s);
s = s.hour(18); //6pm

return s;
},
tomorrow: function tomorrow(s) {
s.epoch = Date.now();
s = getNow(s);
s = s.add(1, 'day');
s = s.startOf('day');
return s;
},
yesterday: function yesterday(s) {
s.epoch = Date.now();
s = getNow(s);
s = s.subtract(1, 'day');
s = s.startOf('day');
return s;
},
christmas: function christmas(s) {
var year = new Date().getFullYear();
var year = getNow(s).year();
s = s.set([year, 11, 25, 18, 0, 0]); // Dec 25

return s;
},
'new years': function newYears(s) {
var year = new Date().getFullYear();
var year = getNow(s).year();
s = s.set([year, 11, 31, 18, 0, 0]); // Dec 31

return s;
Expand Down Expand Up @@ -1276,9 +1286,18 @@ var parseInput = function parseInput(s, input, givenTz) {
} //set tmp time


s.epoch = Date.now();
s.epoch = Date.now(); // overwrite tmp time with 'today' value, if exists

if (s._today && fns.isObject(s._today) && Object.keys(s._today).length > 0) {
var res = handleObject(s, today, defaults);

if (res.isValid()) {
s.epoch = res.epoch;
}
} // null input means 'now'


if (input === null || input === undefined) {
if (input === null || input === undefined || input === '') {
return s; //k, we're good.
} //support input of Date() object

Expand Down Expand Up @@ -1327,10 +1346,10 @@ var parseInput = function parseInput(s, input, givenTz) {
var m = input.match(strParse[i].reg);

if (m) {
var res = strParse[i].parse(s, m, givenTz);
var _res = strParse[i].parse(s, m, givenTz);

if (res !== null) {
return res;
if (_res !== null) {
return _res;
}
}
}
Expand Down Expand Up @@ -4047,7 +4066,7 @@ var whereIts = function whereIts(a, b) {

var whereIts_1 = whereIts;

var _version = '6.6.2';
var _version = '6.6.3';

var main$1 = function main(input, tz, options) {
return new spacetime(input, tz, options);
Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ This project follows semVer, where:
* don't reverse dates for .every() method
-->

### v6.6.3

- support for 'today' param with null inputs
- support for 'today' param with 'today/tonight' inputs
- interpret empty-string input like null input (as 'now')
- typescript fixes (#220 #222)
-

### v6.6.2

- [fix] for formatting when the output is 0 😓
Expand Down
Loading

0 comments on commit af32453

Please sign in to comment.