mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
11 lines
5.2 KiB
JavaScript
11 lines
5.2 KiB
JavaScript
(function(){function k(a,e){s[a]||(typeof console!=="undefined"&&typeof console.warn=="function"&&console.warn("[WARNING] "+a+" is deprecated and will be removed in version 1.0. Instead, use `"+e+"`."),s[a]=!0)}function t(a){a.localize=g.localize.bind(g);a.timezone=g.timezone.bind(g);a.utc=g.utc.bind(g)}function r(a,e,c){c&&k("`"+i+"(format, date, locale)`",i+".localize(locale)(format, [date])");return(c?g.localize(c):g)(a,e)}function u(a,e,c){c?k("`"+i+".strftime(format, date, locale)`",i+".localize(locale)(format, [date])"):
|
|
k("`"+i+".strftime(format, [date])`",i+"(format, [date])");return(c?g.localize(c):g)(a,e)}function p(a,e,c){function m(a,b,h,c){for(var d="",f=null,e=!1,i=a.length,j=!1,o=0;o<i;o++){var n=a.charCodeAt(o);if(e===!0)if(n===45)f="";else if(n===95)f=" ";else if(n===48)f="0";else if(n===58)j=!0;else{switch(n){case 65:d+=h.days[b.getDay()];break;case 66:d+=h.months[b.getMonth()];break;case 67:d+=l(Math.floor(b.getFullYear()/100),f);break;case 68:d+=m(h.formats.D,b,h,c);break;case 70:d+=m(h.formats.F,b,
|
|
h,c);break;case 72:d+=l(b.getHours(),f);break;case 73:d+=l(v(b.getHours()),f);break;case 76:d+=Math.floor(c%1E3)>99?Math.floor(c%1E3):Math.floor(c%1E3)>9?"0"+Math.floor(c%1E3):"00"+Math.floor(c%1E3);break;case 77:d+=l(b.getMinutes(),f);break;case 80:d+=b.getHours()<12?h.am:h.pm;break;case 82:d+=m(h.formats.R,b,h,c);break;case 83:d+=l(b.getSeconds(),f);break;case 84:d+=m(h.formats.T,b,h,c);break;case 85:d+=l(w(b,"sunday"),f);break;case 87:d+=l(w(b,"monday"),f);break;case 88:d+=m(h.formats.X,b,h,c);
|
|
break;case 89:d+=b.getFullYear();break;case 90:k&&g===0?d+="GMT":(f=b.toString().match(/\((\w+)\)/),d+=f&&f[1]||"");break;case 97:d+=h.shortDays[b.getDay()];break;case 98:d+=h.shortMonths[b.getMonth()];break;case 99:d+=m(h.formats.c,b,h,c);break;case 100:d+=l(b.getDate(),f);break;case 101:d+=l(b.getDate(),f==null?" ":f);break;case 104:d+=h.shortMonths[b.getMonth()];break;case 106:f=new Date(b.getFullYear(),0,1);f=Math.ceil((b.getTime()-f.getTime())/864E5);d+=f>99?f:f>9?"0"+f:"00"+f;break;case 107:d+=
|
|
l(b.getHours(),f==null?" ":f);break;case 108:d+=l(v(b.getHours()),f==null?" ":f);break;case 109:d+=l(b.getMonth()+1,f);break;case 110:d+="\n";break;case 111:d+=String(b.getDate())+z(b.getDate());break;case 112:d+=b.getHours()<12?h.AM:h.PM;break;case 114:d+=m(h.formats.r,b,h,c);break;case 115:d+=Math.floor(c/1E3);break;case 116:d+="\t";break;case 117:f=b.getDay();d+=f===0?7:f;break;case 118:d+=m(h.formats.v,b,h,c);break;case 119:d+=b.getDay();break;case 120:d+=m(h.formats.x,b,h,c);break;case 121:d+=
|
|
(""+b.getFullYear()).slice(2);break;case 122:k&&g===0?d+=j?"+00:00":"+0000":(f=g!==0?g/6E4:-b.getTimezoneOffset(),e=j?":":"",n=Math.abs(f%60),d+=(f<0?"-":"+")+l(Math.floor(Math.abs(f/60)))+e+l(n));break;default:d+=a[o]}f=null;e=!1}else n===37?e=!0:d+=a[o]}return d}var i=a||x,g=e||0,k=c||!1,j=0,q,a=function(a,b){var c;if(b)c=b.getTime(),k&&(b=new Date(b.getTime()+(b.getTimezoneOffset()||0)*6E4+g));else{var e=Date.now();e>j&&(j=e,q=new Date(j),c=j,k&&(q=new Date(j+(q.getTimezoneOffset()||0)*6E4+g)));
|
|
b=q}return m(a,b,i,c)};a.localize=function(a){return new p(a||i,g,k)};a.timezone=function(a){var b=g,c=k,e=typeof a;if(e==="number"||e==="string")c=!0,e==="string"?(b=a[0]==="-"?-1:1,e=parseInt(a.slice(1,3),10),a=parseInt(a.slice(3,5),10),b=b*(60*e+a)*6E4):e==="number"&&(b=a*6E4);return new p(i,b,c)};a.utc=function(){return new p(i,g,!0)};return a}function l(a,e){if(e===""||a>9)return a;e==null&&(e="0");return e+a}function v(a){if(a===0)return 12;else if(a>12)return a-12;return a}function w(a,e){var e=
|
|
e||"sunday",c=a.getDay();e==="monday"&&(c===0?c=6:c--);var g=new Date(a.getFullYear(),0,1);return Math.floor(((a-g)/864E5+7-c)/7)}function z(a){var e=a%10;a%=100;if(a>=11&&a<=13||e===0||e>=4)return"th";switch(e){case 1:return"st";case 2:return"nd";case 3:return"rd"}}var x={days:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],shortDays:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],months:["January","February","March","April","May","June","July","August","September","October",
|
|
"November","December"],shortMonths:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],AM:"AM",PM:"PM",am:"am",pm:"pm",formats:{D:"%m/%d/%y",F:"%Y-%m-%d",R:"%H:%M",T:"%H:%M:%S",X:"%T",c:"%a %b %d %X %Y",r:"%I:%M:%S %p",v:"%e-%b-%Y",x:"%D"}},g=new p(x,0,!1),y=typeof module!=="undefined",j;y?(j=module.exports=r,j.strftime=u):(j=function(){return this||(0,eval)("this")}(),j.strftime=r);var i=y?"require('strftime')":"strftime",s={};j.strftimeTZ=function(a,e,c,j){if((typeof c=="number"||
|
|
typeof c=="string")&&j==null)j=c,c=void 0;c?k("`"+i+".strftimeTZ(format, date, locale, tz)`",i+".timezone(tz).localize(locale)(format, [date])"):k("`"+i+".strftimeTZ(format, date, tz)`",i+".timezone(tz)(format, [date])");return(c?g.timezone(j).localize(c):g).timezone(j)(a,e)};j.strftimeUTC=function(a,e,c){c?k("`"+i+".strftimeUTC(format, date, locale)`",i+".localize(locale).utc()(format, [date])"):k("`"+i+".strftimeUTC(format, [date])`",i+".utc()(format, [date])");return(c?g.utc().localize(c):g).utc()(a,
|
|
e)};j.localizedStrftime=function(a){k("`"+i+".localizedStrftime(locale)`",i+".localize(locale)");return g.localize(a)};t(r);t(u);if(typeof Date.now!=="function")Date.now=function(){return+new Date}})();
|