diff --git a/bower.json b/bower.json index cbe0c5f..6160f03 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "kairos", - "version": "2.0.1", + "version": "2.0.2", "description": "A non date-based time calculator", "homepage": "https://github.com/kairos", "repository": { diff --git a/build/kairos-debug.js b/build/kairos-debug.js index 78b8772..2bbc039 100644 --- a/build/kairos-debug.js +++ b/build/kairos-debug.js @@ -374,7 +374,7 @@ } var max = values.reduce(function (previous, current) { - return Kairos.new(previous, pattern).compareTo(current, pattern) > 0 ? previous : current; + return Kairos.compare(previous, current, pattern) > 0 ? previous : current; }); return Kairos.new(max, pattern); diff --git a/build/kairos-min.js b/build/kairos-min.js index 91c195d..d589174 100644 --- a/build/kairos-min.js +++ b/build/kairos-min.js @@ -5,6 +5,6 @@ * @link https://github.com/kairos * @license BSD-2-Clause */ -!function(){"use strict";var n={};n._pattern="#hh:mm:ss.SSS",n._validator=new RegExp(/^[+-]?\d\d:\d\d:\d\d\.\d\d\d/),n._autoParser=!1;var t,e="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this;null!==e&&(t=e.Kairos),n.noConflict=function(){return e.Kairos=t,n},n.setPattern=function(t){n._validator=n.Lexicon.getValidator(t),n._pattern=t},n.getPattern=function(){return n._pattern},n.setAutoParser=function(t){n._autoParser=!!t},n.getAutoParser=function(){return n._autoParser},n.validate=function(t,e){return n.Lexicon.validate(t,e)},n.new=function(t,e){return new n.Engine(t,e)},n.absolute=function(t,e){return n.new(t,e).toAbsolute()},n.plus=function(t,e,r){return n.new(t,r).plus(e,r)},n.minus=function(t,e,r){return n.new(t,r).minus(e,r)},n.multiply=function(t,e,r){return n.new(t,r).multiply(e)},n.divide=function(t,e,r){return n.new(t,r).divide(e)},n.getFraction=function(t,e,r,o){if(e>r)throw new Error("Improper fraction");return n.new(t,o).multiply(e).divide(r)},n.getInterval=function(t,e,r){return n.new(t,r).minus(e,r).toAbsolute()},n.toMilliseconds=function(t,e){return n.new(t,e).toMilliseconds()},n.toSeconds=function(t,e){return n.new(t,e).toSeconds()},n.toMinutes=function(t,e){return n.new(t,e).toMinutes()},n.toHours=function(t,e){return n.new(t,e).toHours()},n.compare=function(t,e,r){return n.new(t,r).compareTo(e,r)},n.min=function(t,e){t instanceof Array||(e=null,t=Array.prototype.slice.call(arguments));var r=t.reduce(function(t,r){return n.compare(t,r,e)<0?t:r});return n.new(r,e)},n.max=function(t,e){t instanceof Array||(e=null,t=Array.prototype.slice.call(arguments));var r=t.reduce(function(t,r){return n.new(t,e).compareTo(r,e)>0?t:r});return n.new(r,e)},"object"==typeof module&&module.exports?module.exports=n:"function"==typeof define&&define.amd?define([],function(){return n}):e.Kairos=n,Math.trunc=Math.trunc||function(n){return n<0?Math.ceil(n):Math.floor(n)}}(); +!function(){"use strict";var n={};n._pattern="#hh:mm:ss.SSS",n._validator=new RegExp(/^[+-]?\d\d:\d\d:\d\d\.\d\d\d/),n._autoParser=!1;var t,e="object"==typeof self&&self.self===self&&self||"object"==typeof global&&global.global===global&&global||this;null!==e&&(t=e.Kairos),n.noConflict=function(){return e.Kairos=t,n},n.setPattern=function(t){n._validator=n.Lexicon.getValidator(t),n._pattern=t},n.getPattern=function(){return n._pattern},n.setAutoParser=function(t){n._autoParser=!!t},n.getAutoParser=function(){return n._autoParser},n.validate=function(t,e){return n.Lexicon.validate(t,e)},n.new=function(t,e){return new n.Engine(t,e)},n.absolute=function(t,e){return n.new(t,e).toAbsolute()},n.plus=function(t,e,r){return n.new(t,r).plus(e,r)},n.minus=function(t,e,r){return n.new(t,r).minus(e,r)},n.multiply=function(t,e,r){return n.new(t,r).multiply(e)},n.divide=function(t,e,r){return n.new(t,r).divide(e)},n.getFraction=function(t,e,r,o){if(e>r)throw new Error("Improper fraction");return n.new(t,o).multiply(e).divide(r)},n.getInterval=function(t,e,r){return n.new(t,r).minus(e,r).toAbsolute()},n.toMilliseconds=function(t,e){return n.new(t,e).toMilliseconds()},n.toSeconds=function(t,e){return n.new(t,e).toSeconds()},n.toMinutes=function(t,e){return n.new(t,e).toMinutes()},n.toHours=function(t,e){return n.new(t,e).toHours()},n.compare=function(t,e,r){return n.new(t,r).compareTo(e,r)},n.min=function(t,e){t instanceof Array||(e=null,t=Array.prototype.slice.call(arguments));var r=t.reduce(function(t,r){return n.compare(t,r,e)<0?t:r});return n.new(r,e)},n.max=function(t,e){t instanceof Array||(e=null,t=Array.prototype.slice.call(arguments));var r=t.reduce(function(t,r){return n.compare(t,r,e)>0?t:r});return n.new(r,e)},"object"==typeof module&&module.exports?module.exports=n:"function"==typeof define&&define.amd?define([],function(){return n}):e.Kairos=n,Math.trunc=Math.trunc||function(n){return n<0?Math.ceil(n):Math.floor(n)}}(); !function(){"use strict";var e={SIGN:"#",HOURS:"h",MINUTES:"m",SECONDS:"s",MILLISECONDS:"S"};Kairos.Lexicon={},Kairos.Lexicon.getValidator=function(a){if("string"!=typeof a&&(a=Kairos._pattern),a===Kairos._pattern)return Kairos._validator;for(var r="",t=0,s=a.length;s>t;t++){var i=a[t];switch(i){case e.SIGN:r+="^[+-]?";break;case e.HOURS:case e.MINUTES:case e.SECONDS:case e.MILLISECONDS:r+="\\d";break;default:r+=i.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}}return new RegExp(r)},Kairos.Lexicon.validate=function(e,a){return Kairos.Lexicon.getValidator(a).test(e)},Kairos.Lexicon.parse=function(a,r){if(r||(r=Kairos._pattern),!Kairos.Lexicon.validate(a,r))throw new Error("Cannot parse expression. Time format doesn't match the current time pattern.");for(var t=!0,s="",i="",n="",c="",o=0,S=r.length;S>o;o++){var l=r[o];switch(l){case e.SIGN:var d=["+","-"].indexOf(a[o])!==-1;d?t="+"===a[o]:(r=r.slice(0,o)+r.slice(o+1),S--,o--);break;case e.HOURS:s+=a[o];break;case e.MINUTES:i+=a[o];break;case e.SECONDS:n+=a[o];break;case e.MILLISECONDS:c+=a[o]}}var g=Kairos.new().addHours(s?+s:0).addMinutes(i?+i:0).addSeconds(n?+n:0).addMilliseconds(c?+c:0);return t||(g.milliseconds=-g.milliseconds),g},Kairos.Lexicon.format=function(a,r,t){r||(r=Kairos._pattern);for(var s=a.milliseconds>=0,i=String(Math.abs(a.getHours())),n=String(Math.abs(a.getMinutes())),c=String(Math.abs(a.getSeconds())),o=String(Math.abs(a.getMilliseconds())),S="",l=i.length>(r.match(/h/g)||[]).length,d=r.length-1;d>=0;d--){var g=r[d];switch(g){case e.SIGN:S=(s?"+":"-")+S;break;case e.HOURS:if(l){t&&(S=i+S,t=!1);break}S=(i.slice(-1)||"0")+S,i.length>0&&(i=i.slice(0,i.length-1));break;case e.MINUTES:S=(n.slice(-1)||"0")+S,n.length>0&&(n=n.slice(0,n.length-1));break;case e.SECONDS:S=(c.slice(-1)||"0")+S,c.length>0&&(c=c.slice(0,c.length-1));break;case e.MILLISECONDS:S=(o.slice(-1)||"0")+S,o.length>0&&(o=o.slice(0,o.length-1));break;default:S=g+S}}return S},Kairos.Lexicon.findPattern=function(a){for(var r="",t=e.HOURS,s=0,i=a.length;i>s;s++){var n=a[s];if(["+","-"].indexOf(n)===-1)if(isNaN(n)){if(isNaN(n))switch(r+=n,t){case e.HOURS:t=e.MINUTES;break;case e.MINUTES:t=e.SECONDS;break;case e.SECONDS:t=e.MILLISECONDS;break;default:t=!1}}else r+=t||n;else r+=e.SIGN}return r}}(); !function(){"use strict";var i={SECOND:1e3,MINUTE:6e4,HOUR:36e5};Kairos.Engine=function(i,t){if(i){if(i instanceof Kairos.Engine)return i;if("number"==typeof i)return this.milliseconds=i,this;if("string"==typeof i&&i.length>0)return Kairos.getAutoParser()&&(t=Kairos.Lexicon.findPattern(i)),new Kairos.Lexicon.parse(i,t);throw new Error("Invalid arguments")}},Kairos.Engine.prototype._resolveStep=function(t,n){switch(t){case 1:this.removeMilliseconds(this.getMilliseconds());break;case i.SECOND:this.removeSeconds(this.getSeconds());break;case i.MINUTE:this.removeMinutes(this.getMinutes());break;case i.HOUR:this.removeHours(this.getHours())}return this.milliseconds+n*t},Kairos.Engine.prototype.milliseconds=0,Kairos.Engine.prototype.setHours=function(t){return this.milliseconds=this._resolveStep(i.HOUR,t),this},Kairos.Engine.prototype.getHours=function(){return Math.trunc(this.milliseconds/i.HOUR)},Kairos.Engine.prototype.setMinutes=function(t){return this.milliseconds=this._resolveStep(i.MINUTE,t),this},Kairos.Engine.prototype.getMinutes=function(){return Math.trunc(Math.trunc(this.milliseconds-Math.trunc(this.toHours())*i.HOUR)/i.MINUTE)},Kairos.Engine.prototype.setSeconds=function(t){return this.milliseconds=this._resolveStep(i.SECOND,t),this},Kairos.Engine.prototype.getSeconds=function(){return Math.trunc(Math.trunc(this.milliseconds-Math.trunc(this.toMinutes())*i.MINUTE)/i.SECOND)},Kairos.Engine.prototype.setMilliseconds=function(i){return this.milliseconds=this._resolveStep(1,i),this},Kairos.Engine.prototype.getMilliseconds=function(){return Math.trunc(this.milliseconds-Math.trunc(this.toSeconds())*i.SECOND)},Kairos.Engine.prototype.addHours=function(t){return this.milliseconds+=i.HOUR*t,this},Kairos.Engine.prototype.addMinutes=function(t){return this.milliseconds+=i.MINUTE*t,this},Kairos.Engine.prototype.addSeconds=function(t){return this.milliseconds+=i.SECOND*t,this},Kairos.Engine.prototype.addMilliseconds=function(i){return this.milliseconds+=i,this},Kairos.Engine.prototype.removeHours=function(t){return this.milliseconds-=i.HOUR*t,this},Kairos.Engine.prototype.removeMinutes=function(t){return this.milliseconds-=i.MINUTE*t,this},Kairos.Engine.prototype.removeSeconds=function(t){return this.milliseconds-=i.SECOND*t,this},Kairos.Engine.prototype.removeMilliseconds=function(i){return this.milliseconds-=i,this},Kairos.Engine.prototype.toHours=function(){return this.milliseconds/i.HOUR},Kairos.Engine.prototype.toMinutes=function(){return this.milliseconds/i.MINUTE},Kairos.Engine.prototype.toSeconds=function(){return this.milliseconds/i.SECOND},Kairos.Engine.prototype.toMilliseconds=function(){return this.milliseconds},Kairos.Engine.prototype.toAbsolute=function(){return this.milliseconds=Math.abs(this.milliseconds),this},Kairos.Engine.prototype.plus=function(i,t){return i=new Kairos.Engine(i,t),this.milliseconds+=i.toMilliseconds(),this},Kairos.Engine.prototype.minus=function(i,t){return i=new Kairos.Engine(i,t),this.milliseconds-=i.toMilliseconds(),this},Kairos.Engine.prototype.multiply=function(i){return this.milliseconds*=i,this},Kairos.Engine.prototype.divide=function(i){return this.milliseconds/=i,this},Kairos.Engine.prototype.compareTo=function(i,t){return i=new Kairos.Engine(i,t),this.millisecondsi.toMilliseconds()?1:void 0},Kairos.Engine.prototype.toString=function(i,t){return"boolean"==typeof i&&(t=i,i=null),Kairos.Lexicon.format(this,i,t)}}(); \ No newline at end of file diff --git a/build/kairos-node.js b/build/kairos-node.js index 63a568c..56330a3 100644 --- a/build/kairos-node.js +++ b/build/kairos-node.js @@ -374,7 +374,7 @@ } var max = values.reduce(function (previous, current) { - return Kairos.new(previous, pattern).compareTo(current, pattern) > 0 ? previous : current; + return Kairos.compare(previous, current, pattern) > 0 ? previous : current; }); return Kairos.new(max, pattern); diff --git a/build/kairos.js b/build/kairos.js index 78b8772..2bbc039 100644 --- a/build/kairos.js +++ b/build/kairos.js @@ -374,7 +374,7 @@ } var max = values.reduce(function (previous, current) { - return Kairos.new(previous, pattern).compareTo(current, pattern) > 0 ? previous : current; + return Kairos.compare(previous, current, pattern) > 0 ? previous : current; }); return Kairos.new(max, pattern); diff --git a/package.json b/package.json index 9d6f104..f2a904d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kairos", - "version": "2.0.1", + "version": "2.0.2", "description": "A non date-based time calculator", "license": "BSD-2-Clause", "repository": "kairos", @@ -23,36 +23,36 @@ "math" ], "devDependencies": { - "assert": "^1.3.0", + "assert": "^1.4.1", "codeclimate-test-reporter": "^0.4.0", - "del": "^2.2.0", + "del": "^2.2.2", "gulp": "^3.9.1", - "gulp-autoprefixer": "^3.1.0", + "gulp-autoprefixer": "^3.1.1", "gulp-bower": "0.0.13", "gulp-concat": "^2.6.0", "gulp-esformatter": "^6.0.0", - "gulp-header": "^1.7.1", - "gulp-include": "^2.1.0", + "gulp-header": "^1.8.8", + "gulp-include": "^2.3.1", "gulp-jsdoc3": "^1.0.0", - "gulp-jshint": "^2.0.0", - "gulp-load-plugins": "^1.2.0", + "gulp-jshint": "^2.0.1", + "gulp-load-plugins": "^1.3.0", "gulp-strip-debug": "^1.1.0", "gulp-uglify": "^2.0.0", "gulp-webserver": "^0.9.1", - "istanbul": "^0.4.2", - "jasmine-core": "^2.4.1", - "jshint": "^2.9.1", - "jshint-stylish": "^2.1.0", - "karma": "^1.2.0", + "istanbul": "^0.4.5", + "jasmine-core": "^2.5.2", + "jshint": "^2.9.3", + "jshint-stylish": "^2.2.1", + "karma": "^1.3.0", "karma-chrome-launcher": "^2.0.0", "karma-coverage": "^1.1.1", "karma-firefox-launcher": "^1.0.0", "karma-jasmine": "^1.0.2", - "karma-mocha": "^1.1.1", - "karma-phantomjs-launcher": "^1.0.0", - "mocha": "^3.0.2", - "phantom": "^2.0.10", - "phantomjs-prebuilt": "^2.1.7", - "run-sequence": "^1.1.5" + "karma-mocha": "^1.2.0", + "karma-phantomjs-launcher": "^1.0.2", + "mocha": "^3.1.2", + "phantom": "^2.1.21", + "phantomjs-prebuilt": "^2.1.13", + "run-sequence": "^1.2.2" } } diff --git a/src/kairos.js b/src/kairos.js index c08ba07..bfdd6c4 100644 --- a/src/kairos.js +++ b/src/kairos.js @@ -367,7 +367,7 @@ } var max = values.reduce(function (previous, current) { - return Kairos.new(previous, pattern).compareTo(current, pattern) > 0 ? previous : current; + return Kairos.compare(previous, current, pattern) > 0 ? previous : current; }); return Kairos.new(max, pattern);