This repository has been archived by the owner on Sep 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
js-date-format.min.js
1 lines (1 loc) · 4.49 KB
/
js-date-format.min.js
1
!function(){"use strict";Date.locales={en:{month_names:["January","February","March","April","May","June","July","August","September","October","November","December"],month_names_short:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],day_names:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],day_names_short:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],date_suffix:function(t){var e=~~(t%100/10),n=t%10;return 1===e?"th":1===n?"st":2===n?"nd":3===n?"rd":"th"},meridiem:function(t,e,n,a){var i=t<12?"AM":"PM";return i=n?i.toLowerCase():i,i=a?i[0]:i}}},Date.prototype.setLocale=function(t){t&&t in Date.locales&&(this.locale=t)},Date.setLocale=function(t){Date.prototype.setLocale(t)},Date.prototype.getLocale=function(){return this.locale||"en"},Date.getLocale=function(){Date.prototype.getLocale()},Date.prototype.getMonthName=function(t){var e="en";return t&&t in Date.locales?e=t:this.locale&&this.locale in Date.locales&&(e=this.locale),Date.locales[e].month_names[this.getMonth()]},Date.prototype.getMonthNameShort=function(t){var e="en";return t&&t in Date.locales?e=t:this.locale&&this.locale in Date.locales&&(e=this.locale),Date.locales[e].month_names_short[this.getMonth()]},Date.prototype.getDayName=function(t){var e="en";return t&&t in Date.locales?e=t:this.locale&&this.locale in Date.locales&&(e=this.locale),Date.locales[e].day_names[this.getDay()]},Date.prototype.getDayNameShort=function(t){var e="en";return t&&t in Date.locales?e=t:this.locale&&this.locale in Date.locales&&(e=this.locale),Date.locales[e].day_names_short[this.getDay()]},Date.prototype.getDateSuffix=function(t){var e="en";return t&&t in Date.locales?e=t:this.locale&&this.locale in Date.locales&&(e=this.locale),Date.locales[e].date_suffix(this.getDate())},Date.prototype.getMeridiem=function(t,e,n){var a="en";return n&&n in Date.locales?a=n:this.locale&&this.locale in Date.locales&&(a=this.locale),Date.locales[a].meridiem(this.getHours(),this.getMinutes(),t,e)},Date.prototype.getLastDate=function(){return new Date(this.getFullYear(),this.getMonth()+1,0).getDate()},Date.prototype.format=function(t){for(var e=function(t,e){for(var n=t<0?"-":"",a="0",i=2;i<e;i++)a+="0";return n+(a+Math.abs(t).toString()).slice(-e)},n={date:this,YYYY:function(){return this.date.getFullYear()},YY:function(){return this.date.getFullYear()%100},MMMM:function(){return this.date.getMonthName()},MMM:function(){return this.date.getMonthNameShort()},MM:function(){return e(this.date.getMonth()+1,2)},M:function(){return this.date.getMonth()+1},DDDD:function(){return this.date.getDayName()},DDD:function(){return this.date.getDayNameShort()},DD:function(){return e(this.date.getDate(),2)},D:function(){return this.date.getDate()},S:function(){return this.date.getDateSuffix()},HH:function(){return e(this.date.getHours(),2)},H:function(){return this.date.getHours()},hh:function(){var t=this.date.getHours();return t>12?t-=12:t<1&&(t=12),e(t,2)},h:function(){var t=this.date.getHours();return t>12?t-=12:t<1&&(t=12),t},mm:function(){return e(this.date.getMinutes(),2)},m:function(){return this.date.getMinutes()},ss:function(){return e(this.date.getSeconds(),2)},s:function(){return this.date.getSeconds()},fff:function(){return e(this.date.getMilliseconds(),3)},ff:function(){return e(Math.floor(this.date.getMilliseconds()/10),2)},f:function(){return Math.floor(this.date.getMilliseconds()/100)},zzzz:function(){return e(Math.floor(-this.date.getTimezoneOffset()/60),2)+":"+e(-this.date.getTimezoneOffset()%60,2)},zzz:function(){return Math.floor(-this.date.getTimezoneOffset()/60)+":"+e(-this.date.getTimezoneOffset()%60,2)},zz:function(){return e(Math.floor(-this.date.getTimezoneOffset()/60),2)},z:function(){return Math.floor(-this.date.getTimezoneOffset()/60)},tt:function(){return this.date.getMeridiem(!0,!1)},t:function(){return this.date.getMeridiem(!0,!0)},TT:function(){return this.date.getMeridiem(!1,!1)},T:function(){return this.date.getMeridiem(!1,!0)}},a=new Array;t.length>0;)if('"'===t[0]){var i=/"[^"]*"/m.exec(t);null===i?(a.push(t.substring(1)),t=""):(i=i[0].substring(1,i[0].length-1),a.push(i),t=t.substring(i.length+2))}else if("'"===t[0]){var i=/'[^']*'/m.exec(t);null===i?(a.push(t.substring(1)),t=""):(i=i[0].substring(1,i[0].length-1),a.push(i),t=t.substring(i.length+2))}else if("\\"===t[0])t.length>1?(a.push(t.substring(1,2)),t=t.substring(2)):(a.push("\\"),t="");else{for(var o=!1,r=t.length;r>0;r--)if(t.substring(0,r)in n){a.push(n[t.substring(0,r)]()),t=t.substring(r),o=!0;break}o||(a.push(t[0]),t=t.substring(1))}return a.join("")}}();