| 1 |
- function e(e=`system`){let t=e===`system`?a():e;switch(t){case`us`:return`MM/DD/YYYY`;case`eu`:return`DD/MM/YYYY`;case`iso`:return`YYYY-MM-DD`;default:return t}}function t(e=`system`){switch(e){case`12h`:return`HH:MM AM/PM`;case`24h`:return`HH:MM`;default:{let e=new Date(2e3,0,1,14,30).toLocaleTimeString();return e.includes(`PM`)||e.includes(`AM`)?`HH:MM AM/PM`:`HH:MM`}}}function n(e,t=`system`){let n=String(e.getDate()).padStart(2,`0`),r=String(e.getMonth()+1).padStart(2,`0`),i=e.getFullYear();switch(t){case`us`:return`${r}/${n}/${i}`;case`eu`:return`${n}/${r}/${i}`;case`iso`:return`${i}-${r}-${n}`;default:return e.toLocaleDateString()}}function r(e,t=`system`){let n=e.getHours(),r=String(e.getMinutes()).padStart(2,`0`);switch(t){case`12h`:return`${n%12||12}:${r} ${n<12?`AM`:`PM`}`;case`24h`:return`${String(n).padStart(2,`0`)}:${r}`;default:return e.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}}function i(e){for(let t of[`/`,`.`,`-`]){let n=e.split(t);if(n.length===3)return n}return null}function a(){let e=new Date(2e3,11,31).toLocaleDateString();return e.startsWith(`12`)?`us`:e.startsWith(`31`)?`eu`:`iso`}function o(e,t=`system`){if(!e)return null;let n=i(e);if(!n)return null;let r=t===`system`?a():t,o,s,c;switch(r){case`us`:s=parseInt(n[0],10),o=parseInt(n[1],10),c=parseInt(n[2],10);break;case`eu`:o=parseInt(n[0],10),s=parseInt(n[1],10),c=parseInt(n[2],10);break;case`iso`:c=parseInt(n[0],10),s=parseInt(n[1],10),o=parseInt(n[2],10);break}return isNaN(o)||isNaN(s)||isNaN(c)||s<1||s>12||o<1||o>31||c<1900||c>2100?null:new Date(c,s-1,o)}function s(e){if(!e)return null;let t=e.trim().match(/^(\d{1,2}):(\d{2})\s*(AM|PM)?$/i);if(!t)return null;let n=parseInt(t[1],10),r=parseInt(t[2],10),i=t[3]?.toUpperCase();return i===`PM`&&n<12&&(n+=12),i===`AM`&&n===12&&(n=0),n<0||n>23||r<0||r>59?null:{hours:n,minutes:r}}function c(e){return`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}T${String(e.getHours()).padStart(2,`0`)}:${String(e.getMinutes()).padStart(2,`0`)}`}function l(e,t=`system`){return t===`12h`?e.hour12=!0:t===`24h`&&(e.hour12=!1),e}function u(e){return e?e.endsWith(`Z`)||/[+-]\d{2}:\d{2}$/.test(e)?new Date(e):new Date(e+`Z`):null}function d(e,t){let n=u(e);return n?n.toLocaleString(void 0,t??{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`}):``}function f(e,t){let n=u(e);return n?n.toLocaleDateString(void 0,t??{year:`numeric`,month:`short`,day:`numeric`}):``}function p(e,t=`system`,n){let r=u(e);if(!r)return``;let i=l(n??{year:`numeric`,month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`},t);return r.toLocaleString(void 0,i)}function m(e,t=`system`,n){let r=l({hour:`2-digit`,minute:`2-digit`,...n},t);return e.toLocaleTimeString([],r)}function h(e,t=`system`,n,r){let i=r==null?new Date:new Date(r),a=new Date(i.getTime()+e*60*1e3),o=new Date(i);o.setHours(0,0,0,0);let s=new Date(a);s.setHours(0,0,0,0);let c=l({hour:`2-digit`,minute:`2-digit`},t),u=a.toLocaleTimeString([],c),d=Math.floor((s.getTime()-o.getTime())/864e5);return d===0?u:d===1?`${n?.(`common.tomorrow`)??`Tomorrow`} ${u}`:`${a.toLocaleDateString([],{weekday:`short`})} ${u}`}function g(e){if(e==null||e<0)return`--`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return t>0?`${t}h ${n}m`:`${n}m`}function _(e,t=`system`,n){if(!e)return n?.(`time.unknown`)??`-`;let r=u(e);if(!r)return n?.(`time.unknown`)??`-`;let i=new Date,a=r.getTime()-i.getTime(),o=a<0,s=Math.abs(a),c=Math.floor(s/6e4),l=Math.floor(s/36e5),d=Math.floor(s/864e5);return c<1?o?n?.(`time.justNow`)??`Just now`:n?.(`time.now`)??`Now`:l<1?o?n?.(`time.minsAgo`,{count:c})??`${c}m ago`:n?.(`time.inMins`,{count:c})??`in ${c}m`:d<1?o?n?.(`time.hoursAgo`,{count:l})??`${l}h ago`:n?.(`time.inHours`,{count:l})??`in ${l}h`:d<7?o?n?.(`time.daysAgo`,{count:d})??`${d}d ago`:n?.(`time.inDays`,{count:d})??`in ${d}d`:p(e,t)}function v(e){return`${Math.floor(e/60)}:${Math.floor(e%60).toString().padStart(2,`0`)}`}function y(e){if(e<1)return`${Math.round(e*60)}m`;let t=Math.floor(e),n=Math.round((e-t)*60);return n>0?`${t}h ${n}m`:`${t}h`}function b(e){let t=typeof e==`string`?u(e):e;return t?`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`:``}export{s as _,p as a,h as c,r as d,m as f,o as g,b as h,f as i,v as l,t as m,d as n,g as o,e as p,n as r,y as s,l as t,_ as u,u as v,c as y};
|