-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseAnyDate.min.js
1 lines (1 loc) · 1.17 KB
/
parseAnyDate.min.js
1
function parseAnyDate(e,r){"use strict";if(!e||"string"!=typeof e)return!t instanceof Date?!r&&new Date:e;if(8===e.length&&!isNaN(e)){var t=new Date(e.substr(0,4),e.substr(4,2)-1,e.substr(6,2));if(t)return t}var a=Date.parse(e);if(!isNaN(a))return new Date(a);e&&!isNaN(e)&&(e+="");var s=["jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"],i=["th","st","rd","nd"],n=!1,d="",t={h:0,mi:0,s:0},m=function(e,r,a){if(e||"0"===e){if(isNaN(e)){n=!1;var d=s.indexOf(e.substr(0,3).toLowerCase());if(d>-1)return void(t.m=d+1+"");var m=i.indexOf(e.replace(/[^a-z]/gi,"").toLowerCase());if(e=e.replace(/[^0-9]/g,""),m>-1)return void(t.d=e)}else n=!0;if(t.y&&t.m&&t.d)t.h?t.mi?t.s||(t.s=e):t.mi=e:t.h=e;else{if(!t.d&&(t.m||t.y))return void(t.d=e);t.y||(4===e.length&&n?t.y=e:t.m&&t.d&&(t.y=e)),t.m||(t.m=e)}}};e.split(/[^A-Za-z0-9]/).forEach(m),t.d<10&&(t.d="0"+1*t.d),t.m<10&&(t.m="0"+1*t.m),d=t.y+"-"+t.m+"-"+t.d,(t.h||t.mi||t.s)&&(t.h<10&&(t.h="0"+1*t.h),t.mi<10&&(t.mi="0"+1*t.mi),t.s<10&&(t.s="0"+1*t.s),d+="T "+t.h+":"+t.mi+":"+t.s);var a=Date.parse(d);return isNaN(a)?!r&&new Date:new Date(a)}"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=parseAnyDate);