timetable-fns
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -1,1 +0,1 @@ | ||
!function(t,n){"object"==typeof exports&&"object"==typeof module?module.exports=n(require("moment-timezone")):"function"==typeof define&&define.amd?define(["moment-timezone"],n):"object"==typeof exports?exports["timetable-fns"]=n(require("moment-timezone")):t["timetable-fns"]=n(t.moment)}("undefined"!=typeof self?self:this,function(t){return function(t){var n={};function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{enumerable:!0,get:r})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,n){if(1&n&&(t=e(t)),8&n)return t;if(4&n&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(e.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&n&&"string"!=typeof t)for(var o in t)e.d(r,o,function(n){return t[n]}.bind(null,o));return r},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,n){return Object.prototype.hasOwnProperty.call(t,n)},e.p="",e(e.s=1)}([function(n,e){n.exports=t},function(t,n,e){"use strict";e.r(n),e.d(n,"coerce",function(){return d}),e.d(n,"coerceTime",function(){return s}),e.d(n,"format",function(){return p}),e.d(n,"diff",function(){return m}),e.d(n,"plus",function(){return M}),e.d(n,"minus",function(){return y}),e.d(n,"today",function(){return b}),e.d(n,"valid",function(){return h}),e.d(n,"validTime",function(){return v});var r=e(0),o=e.n(r);const u=/^(\d{4})-(\d{2})-(\d{2})$/,f=/^(\d{2}):(\d{2})$/,i="Invalid";function c(t){const n=function(t){if(t&&"string"==typeof t){const n=u.exec(t);if(n)return[parseInt(n[1]),parseInt(n[2]),parseInt(n[3])]}return null}(t);if(!n||n.includes(NaN))return NaN;let[e,r,o]=n;return r=(r+9)%12,365*(e-=Math.floor(r/10))+Math.floor(e/4)-Math.floor(e/100)+Math.floor(e/400)+Math.floor((306*r+5)/10)+(o-1)}function a(t){if(Number.isNaN(t))return i;let n=Math.floor((1e4*t+14780)/3652425),e=t-(365*n+Math.floor(n/4)-Math.floor(n/100)+Math.floor(n/400));e<0&&(e=t-(365*(n-=1)+Math.floor(n/4)-Math.floor(n/100)+Math.floor(n/400)));let r=Math.floor((100*e+52)/3060),o=(r+2)%12+1;return l(n+=Math.floor((r+2)/12),o,e-Math.floor((306*r+5)/10)+1)}function l(t,n,e){return t.toString().padStart(4,"0")+"-"+n.toString().padStart(2,"0")+"-"+e.toString().padStart(2,"0")}function d(t){return o.a.isMoment(t)?t.format("YYYY-MM-DD"):t}function s(t){return o.a.isMoment(t)?t.format("HH:mm"):t}function p(t){return o()(t,"YYYY-MM-DD",!0).format("L")}function m(t,n){return c(n)-c(t)}function M(t,n){return a(c(t)+n)}function y(t,n){return a(c(t)-n)}function b(){const t=o()();return l(t.year(),t.month()+1,t.date())}function h(t){return t!==i&&t===a(c(t))}function v(t){if(t&&"string"==typeof t){const n=f.exec(t);if(n){const t=parseInt(n[1]),e=parseInt(n[2]);return t>=0&&t<=23&&e>=0&&e<=59}}return!1}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("moment-timezone")):"function"==typeof define&&define.amd?define(["moment-timezone"],e):"object"==typeof exports?exports["timetable-fns"]=e(require("moment-timezone")):t["timetable-fns"]=e(t.moment)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=1)}([function(e,n){e.exports=t},function(t,e,n){"use strict";n.r(e);var r=n(0),o=n.n(r);const f=/^(\d{4})-(\d{2})-(\d{2})$/,u=/^(\d{2}):(\d{2})$/,i="Invalid";function a(t){const e=function(t){if(t&&"string"==typeof t){const e=f.exec(t);if(e)return[parseInt(e[1]),parseInt(e[2]),parseInt(e[3])]}return null}(t);if(!e||e.includes(NaN))return NaN;let[n,r,o]=e;return r=(r+9)%12,365*(n-=Math.floor(r/10))+Math.floor(n/4)-Math.floor(n/100)+Math.floor(n/400)+Math.floor((306*r+5)/10)+(o-1)}function c(t){if(Number.isNaN(t))return i;let e=Math.floor((1e4*t+14780)/3652425),n=t-(365*e+Math.floor(e/4)-Math.floor(e/100)+Math.floor(e/400));n<0&&(n=t-(365*(e-=1)+Math.floor(e/4)-Math.floor(e/100)+Math.floor(e/400)));let r=Math.floor((100*n+52)/3060),o=(r+2)%12+1;return l(e+=Math.floor((r+2)/12),o,n-Math.floor((306*r+5)/10)+1)}function l(t,e,n){return t.toString().padStart(4,"0")+"-"+e.toString().padStart(2,"0")+"-"+n.toString().padStart(2,"0")}e.default={coerce:function(t){return o.a.isMoment(t)?t.format("YYYY-MM-DD"):t},coerceTime:function(t){return o.a.isMoment(t)?t.format("HH:mm"):t},format:function(t){return o()(t,"YYYY-MM-DD",!0).format("L")},diff:function(t,e){return a(e)-a(t)},plus:function(t,e){return c(a(t)+e)},minus:function(t,e){return c(a(t)-e)},today:function(){const t=o()();return l(t.year(),t.month()+1,t.date())},valid:function(t){return t!==i&&t===c(a(t))},validTime:function(t){if(t&&"string"==typeof t){const e=u.exec(t);if(e){const t=parseInt(e[1]),n=parseInt(e[2]);return t>=0&&t<=23&&n>=0&&n<=59}}return!1}}}])}); |
{ | ||
"name": "timetable-fns", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Useful date and time utility functions for working with timetables.", | ||
@@ -5,0 +5,0 @@ "main": "dist/timetable-fns.js", |
@@ -63,27 +63,27 @@ import moment from 'moment-timezone' | ||
export function coerce (dt) { | ||
function coerce (dt) { | ||
return moment.isMoment(dt) ? dt.format('YYYY-MM-DD') : dt | ||
} | ||
export function coerceTime (dt) { | ||
function coerceTime (dt) { | ||
return moment.isMoment(dt) ? dt.format('HH:mm') : dt | ||
} | ||
export function format (dt) { | ||
function format (dt) { | ||
return moment(dt, 'YYYY-MM-DD', true).format('L') | ||
} | ||
export function diff (a, b) { | ||
function diff (a, b) { | ||
return _g(b) - _g(a) | ||
} | ||
export function plus (dt, days) { | ||
function plus (dt, days) { | ||
return _d(_g(dt) + days) | ||
} | ||
export function minus (dt, days) { | ||
function minus (dt, days) { | ||
return _d(_g(dt) - days) | ||
} | ||
export function today () { | ||
function today () { | ||
const m = moment() | ||
@@ -93,7 +93,7 @@ return _str(m.year(), m.month() + 1, m.date()) | ||
export function valid (dt) { | ||
function valid (dt) { | ||
return dt !== INVALID && dt === _d(_g(dt)) | ||
} | ||
export function validTime (dt) { | ||
function validTime (dt) { | ||
if (dt && typeof dt === 'string') { | ||
@@ -109,1 +109,13 @@ const r = reTime.exec(dt) | ||
} | ||
export default { | ||
coerce, | ||
coerceTime, | ||
format, | ||
diff, | ||
plus, | ||
minus, | ||
today, | ||
valid, | ||
validTime | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128
135332