diff --git a/humandate.js b/humandate.js index 332f189..8fc96d7 100644 --- a/humandate.js +++ b/humandate.js @@ -50,16 +50,16 @@ if (!options) { options = {}; } - if (!options.futureSuffix) { + if (!('futureSuffix' in options)) { options.futureSuffix = 'from now'; } - if (!options.pastSuffix) { + if (!('pastSuffix' in options)) { options.pastSuffix = 'ago'; } - if (!options.presentText) { + if (!('presentText' in options)) { options.presentText = 'now'; } - if (!options.returnObject) { + if (!('returnObject' in options)) { options.returnObject = false; } isPast = seconds < 0 ? true : false; @@ -101,7 +101,7 @@ if (time.seconds) { append(time.seconds, 'second'); } - return output.join(', ') + ' ' + suffix; + return output.join(', ') + (suffix ? (' ' + suffix) : ''); }, prettyPrint: function prettyPrint(input, options) { var date, hdate, day, humanDate, year, month, tstr, hours, minutes, ampm; diff --git a/humandate.min.js b/humandate.min.js index 934dfba..21e7f3f 100644 --- a/humandate.min.js +++ b/humandate.min.js @@ -1 +1 @@ -!function(){var e={months:["January","February","March","April","May","June","July","August","September","October","November","December"],toUTC:function(e){var t=e?new Date(e):new Date;return t=new Date(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds())},monthName:function(t){var n,r;return"number"==typeof t?n=t:(r=new Date(t),n=r.getMonth()+1),e.months[n-1]},relativeTime:function(e,t){function n(e,n){m&&(m=t.allUnits,h.push(e+" "+n+(e>1?"s":"")))}var r,o,u,a,s,f,i,m,h=[];return"number"==typeof e?r=e:(s=new Date(e),a=s.getTime(),f=(new Date).getTime(),r=(f-a)/1e3*-1),t||(t={}),t.futureSuffix||(t.futureSuffix="from now"),t.pastSuffix||(t.pastSuffix="ago"),t.presentText||(t.presentText="now"),t.returnObject||(t.returnObject=!1),i=0>r?!0:!1,r=Math.abs(r),o={seconds:Math.floor(r%31536e3%86400%3600%60),minutes:Math.floor(r%31536e3%86400%3600/60),hours:Math.floor(r%31536e3%86400/3600),days:Math.floor(r%31536e3/86400),years:Math.floor(r/31536e3),past:i},t.returnObject?o:0===r?t.presentText:(u=o.past?t.pastSuffix:t.futureSuffix,m=!0,o.years&&n(o.years,"year"),o.days&&n(o.days,"day"),o.hours&&n(o.hours,"hour"),o.minutes&&n(o.minutes,"minute"),o.seconds&&n(o.seconds,"second"),h.join(", ")+" "+u)},prettyPrint:function(e,t){var n,r,o,u,a,s,f,i,m,h;return e?"number"==typeof e&&(e=(new Date).setSeconds(e)):e=new Date,t||(t={}),t.showTime||(t.showTime=!1),n=new Date(e),o=n.getDate(),u=o>3&&21>o?o+"th":o%10===1?o+"st":o%10===2?o+"nd":o%10===3?o+"rd":o+"th",a=n.getFullYear(),s=this.monthName(n.getMonth()+1),r=s+" "+u+", "+a,i=n.getHours(),m=n.getMinutes(),h=i>=12?"pm":"am",i=i%12?i%12:12,m=10>m?"0"+m:m,f=i+":"+m+" "+h,t.showTime?r+" at "+f:r}};if("undefined"!=typeof module&&module.exports)module.exports=e;else{if("function"==typeof define&&define.amd)return define([],function(){return e});this.humandate=e}}(); \ No newline at end of file +!function(){var t={months:["January","February","March","April","May","June","July","August","September","October","November","December"],toUTC:function(e){e=e?new Date(e):new Date;return e=new Date(e.getUTCFullYear(),e.getUTCMonth(),e.getUTCDate(),e.getUTCHours(),e.getUTCMinutes(),e.getUTCSeconds())},monthName:function(e){e="number"==typeof e?e:new Date(e).getMonth()+1;return t.months[e-1]},relativeTime:function(e,n){var t,r,o=[],e="number"==typeof e?e:(e=new Date(e).getTime(),((new Date).getTime()-e)/1e3*-1);return"futureSuffix"in(n=n||{})||(n.futureSuffix="from now"),"pastSuffix"in n||(n.pastSuffix="ago"),"presentText"in n||(n.presentText="now"),"returnObject"in n||(n.returnObject=!1),t=e<0,e=Math.abs(e),t={seconds:Math.floor(e%31536e3%86400%3600%60),minutes:Math.floor(e%31536e3%86400%3600/60),hours:Math.floor(e%31536e3%86400/3600),days:Math.floor(e%31536e3/86400),years:Math.floor(e/31536e3),past:t},n.returnObject?t:0===e?n.presentText:(e=t.past?n.pastSuffix:n.futureSuffix,r=!0,t.years&&u(t.years,"year"),t.days&&u(t.days,"day"),t.hours&&u(t.hours,"hour"),t.minutes&&u(t.minutes,"minute"),t.seconds&&u(t.seconds,"second"),o.join(", ")+(e?" "+e:""));function u(e,t){r&&(r=n.allUnits,o.push(e+" "+t+(1