timestring/dist/timestring.min.js

2 lines
8.3 KiB
JavaScript
Raw Normal View History

2015-04-30 12:37:57 +02:00
(function(){"use strict";var t=function(t){var s={hoursPerDay:24,daysPerWeek:7,weeksPerMonth:4,monthsPerYear:12};t=t||{},this.settings=s;for(var e in t)this.settings[e]=t[e];this.units={s:["s","sec","secs","second","seconds"],m:["m","min","mins","minute","minutes"],h:["h","hr","hrs","hour","hours"],d:["d","day","days"],w:["w","week","weeks"],mth:["mth","mths","month","months"],y:["y","yr","yrs","year","years"]},this.unitValues={s:1,m:60,h:3600},this.unitValues.d=this.settings.hoursPerDay*this.unitValues.h,this.unitValues.w=this.settings.daysPerWeek*this.unitValues.d,this.unitValues.mth=this.settings.weeksPerMonth*this.unitValues.w,this.unitValues.y=this.settings.monthsPerYear*this.unitValues.mth};t.prototype.parse=function(t,s){function e(t){for(var s in r.units)for(var e in r.units[s])if(t===r.units[s][e])return s;throw new Error("The unit ["+t+"] is not supported by timestring")}function i(t,s){var i=r.unitValues[e(s)];return t/i}function n(t,s){var i=r.unitValues[e(s)];return t*i}var r=this,u=0,h=t.toLowerCase().replace(/[^\.\w+-]+/g,"").match(/[-+]?[0-9]+[a-z]+/g);if(null!==h)for(var a=0;a<h.length;a++){var o=h[a],m=o.match(/[0-9]+/g)[0],l=o.match(/[a-z]+/g)[0];u+=n(m,l)}return s?i(u,s):u},String.prototype.parseTime=function(s,e){return new t(e).parse(this,s)},"undefined"!=typeof module&&module.exports?module.exports=t:this.Timestring=t}).call(this);
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInRpbWVzdHJpbmcuanMiXSwibmFtZXMiOlsiVGltZXN0cmluZyIsInNldHRpbmdzIiwiZGVmYXVsdHMiLCJob3Vyc1BlckRheSIsImRheXNQZXJXZWVrIiwid2Vla3NQZXJNb250aCIsIm1vbnRoc1BlclllYXIiLCJ0aGlzIiwicyIsInVuaXRzIiwibSIsImgiLCJkIiwidyIsIm10aCIsInkiLC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