forked from moment/moment
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunderscore.date.min.js
executable file
·1 lines (1 loc) · 4.22 KB
/
underscore.date.min.js
1
(function(a){function m(a){var b=Math.abs(a)/1e3,d=b/60,e=d/60,f=e/24,g=f/365;return b<45&&k("s",c(b))||c(d)===1&&k("m")||d<45&&k("mm",c(d))||c(e)===1&&k("h")||e<22&&k("hh",c(e))||c(f)===1&&k("d")||f<25&&k("dd",c(f))||f<45&&k("M")||f<345&&k("MM",c(f/30))||c(g)===1&&k("y")||k("yy",c(g))}function l(a,b){return j(a)-j(b)}function k(a,c){return b.relativeTime[a].replace(/%d/i,c||1)}function j(a){return isNaN(a)?(new i(a)).date.getTime():a}function i(b,c){b&&b.date instanceof Date?this.date=b.date:c?this.date=h(b,c):this.date=b===a?new Date:b instanceof Date?b:f(b)?g(b):new Date(b)}function h(a,b){function j(a,b){switch(a){case"M":case"MM":c[1]=~~b-1;break;case"D":case"DD":case"DDD":case"DDDD":c[2]=~~b;break;case"YY":b=~~b,c[0]=b+(b>70?1900:2e3);break;case"YYYY":c[0]=~~b;break;case"a":case"A":i=b.toLowerCase()==="pm";break;case"H":case"HH":case"h":case"hh":c[3]=~~b;break;case"m":case"mm":c[4]=~~b;break;case"s":case"ss":c[5]=~~b}}var c=[0],d=/[0-9a-zA-Z]+/g,e=a.match(d),f=b.match(d),h,i;for(h=0;h<f.length;h++)j(f[h],e[h]);i&&c[3]<12&&(c[3]+=12);return g(c)}function g(a){return new Date(a[0],a[1]||0,a[2]||1,a[3]||0,a[4]||0,a[5]||0,a[6]||0)}function f(a){return Object.prototype.toString.call(a)==="[object Array]"}function e(a,b,c){var d=(b.ms||0)+(b.s||0)*1e3+(b.m||0)*6e4+(b.h||0)*36e5+(b.d||0)*864e5+(b.w||0)*6048e5,e=(b.M||0)+(b.y||0)*12,f;d&&a.setMilliseconds(a.getMilliseconds()+d*c),e&&(f=a.getDate(),a.setDate(1),a.setMonth(a.getMonth()+e*c),a.setDate(Math.min((new Date(a.getFullYear(),a.getMonth()+1,0)).getDate(),f)));return a}function d(a,b){var c=a+"";while(c.length<b)c="0"+c;return c}var b,c=Math.round;b=function(a,b){return new i(a,b)},b.months=["January","February","March","April","May","June","July","August","September","October","November","December"],b.monthsShort=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],b.weekdays=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],b.weekdaysShort=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],b.relativeTime={future:"in %s",past:"%s ago",s:"seconds",m:"a minute",mm:"%d minutes",h:"an hour",hh:"%d hours",d:"a day",dd:"%d days",M:"a month",MM:"%d months",y:"a year",yy:"%d years"},b.ordinal=function(a){var b=a%10;return~~(a%100/10)===1?"th":b===1?"st":b===2?"nd":b===3?"rd":"th"},i.prototype={valueOf:function(){return this.date.getTime()},format:function(a){function o(a){var c,m;switch(a){case"M":return e+1;case"Mo":return e+1+b.ordinal(e+1);case"MM":return d(e+1,2);case"MMM":return b.monthsShort[e];case"MMMM":return b.months[e];case"D":return f;case"Do":return f+b.ordinal(f);case"DD":return d(f,2);case"DDD":c=new Date(g,e,f),m=new Date(g,0,1);return~~((c-m)/864e5+1.5);case"DDDo":c=o("DDD");return c+b.ordinal(c);case"DDDD":return d(o("DDD"),3);case"d":return h;case"do":return h+b.ordinal(h);case"ddd":return b.weekdaysShort[h];case"dddd":return b.weekdays[h];case"w":c=new Date(g,e,f-h+5),m=new Date(c.getFullYear(),0,4);return~~((c-m)/864e5/7+1.5);case"wo":c=o("w");return c+b.ordinal(c);case"ww":return d(o("w"),2);case"YY":return(g+"").slice(-2);case"YYYY":return g;case"a":return i>11?"pm":"am";case"A":return i>11?"PM":"AM";case"H":return i;case"HH":return d(i,2);case"h":return i%12||12;case"hh":return d(i%12||12,2);case"m":return j;case"mm":return d(j,2);case"s":return k;case"ss":return d(k,2);case"z":return o("zz").replace(n,"");case"zz":c=l.indexOf("(");if(c>-1)return l.slice(c+1,l.indexOf(")"));return l.slice(l.indexOf(":")).replace(n,"");default:return a.replace("\\","")}}var c=this.date,e=c.getMonth(),f=c.getDate(),g=c.getFullYear(),h=c.getDay(),i=c.getHours(),j=c.getMinutes(),k=c.getSeconds(),l=c.toString(),m=/(\\)?(Mo|MM?M?M?|Do|DDDo|DD?D?D?|dddd?|do?|w[o|w]?|YYYY|YY|a|A|hh?|HH?|mm?|ss?|zz?)/g,n=/[^A-Z]/g;return a.replace(m,o)},add:function(a){this.date=e(this.date,a,1);return this},subtract:function(a){this.date=e(this.date,a,-1);return this},from:function(a,c,d){var e=l(this.date,a),f=e<0?b.relativeTime.past:b.relativeTime.future;return d?e:c?m(e):f.replace(/%s/i,m(e))},fromNow:function(a,b){return this.from(new i,a,b)},isLeapYear:function(){var a=this.date.getFullYear();return a%4===0&&a%100!==0||a%400===0}},typeof window=="undefined"&&typeof module!="undefined"?module.exports=b:(this._!==a&&this._.mixin!==a&&this._.mixin({date:b}),this._date=b)})()