import{createRequire} from"node:module";const require=createRequire(import.meta.url);
import{a as y}from"./chunk-RBQG6ZUG.js";import{a as w,b as T,c as h}from"./chunk-QAYAQNCG.js";var g={name:"date",summary:"display the current time in the given FORMAT",usage:"date [OPTION]... [+FORMAT]",options:["-d, --date=STRING   display time described by STRING, not 'now'","-u, --utc           print Coordinated Universal Time (UTC)","-I, --iso-8601      output date/time in ISO 8601 format","-R, --rfc-email     output RFC 5322 date format","    --help          display this help and exit"]};function D(e){try{return new Intl.DateTimeFormat(void 0,{timeZone:e}),!0}catch{return!1}}function $(e,s){let r=new Intl.DateTimeFormat("en-US",{timeZone:s,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1}).formatToParts(e),t=n=>r.find(u=>u.type===n)?.value??"00",o=Number.parseInt(t("hour"),10)%24,i=new Date(`${t("year")}-${t("month")}-${t("day")}T${String(o).padStart(2,"0")}:${t("minute")}:${t("second")}Z`);return Number.isNaN(i.getTime())?null:i}function I(e,s){let r=e.match(/^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2}))?)?$/);if(!r)return null;let[,t,o,i,n="00",u="00",c="00"]=r,m=new Date(`${t}-${o}-${i}T${n}:${u}:${c}Z`);if(Number.isNaN(m.getTime()))return null;try{let d=m;for(let l=0;l<3;l++){let f=$(d,s);if(f===null)return null;let a=f.getTime()-m.getTime();if(a===0)return d;d=new Date(d.getTime()-a)}return d}catch{return null}}function N(e){let s=e.match(/^(?:(next|this)\s+)?(sunday|monday|tuesday|wednesday|thursday|friday|saturday)$/i);if(!s)return null;let r={sunday:0,monday:1,tuesday:2,wednesday:3,thursday:4,friday:5,saturday:6},t=s[1]?.toLowerCase(),o=r[s[2].toLowerCase()],i=new Date,n=(o-i.getDay()+7)%7;return t==="next"&&n===0&&(n=7),i.setDate(i.getDate()+n),i}function b(e,s){if(e.startsWith("@")){let n=e.slice(1);return/^-?\d+$/.test(n)?new Date(Number.parseInt(n,10)*1e3):null}let r=e.toLowerCase().trim();if(r==="now"||r==="today")return new Date;if(r==="yesterday")return new Date(Date.now()-864e5);if(r==="tomorrow")return new Date(Date.now()+864e5);let t=r.match(/^([+-]\d+)\s+days?$/);if(t){let n=Number.parseInt(t[1],10);return new Date(Date.now()+n*864e5)}let o=N(r);if(o)return o;if(s&&!/Z$/i.test(e)&&!/[+-]\d{2}:?\d{2}$/.test(e)){let n=I(e,s);if(n)return n}let i=new Date(e);return Number.isNaN(i.getTime())?null:i}var v={name:"date",async execute(e,s){if(T(e))return w(g);let r=!1,t=null,o=null,i=!1,n=!1;for(let f=0;f<e.length;f++){let a=e[f];if(a==="-u"||a==="--utc")r=!0;else if(a==="-d"||a==="--date")t=e[++f]??"";else if(a.startsWith("--date="))t=a.slice(7);else if(a==="-I"||a==="--iso-8601")i=!0;else if(a==="-R"||a==="--rfc-email")n=!0;else if(a.startsWith("+"))o=a.slice(1);else{if(a.startsWith("--"))return h("date",a);if(a.startsWith("-"))for(let p of a.slice(1))if(p==="u")r=!0;else if(p==="I")i=!0;else if(p==="R")n=!0;else return h("date",`-${p}`)}}let u=s.env.get("TZ");u&&!D(u)&&(u=void 0);let c=r?"UTC":u??"UTC",m=t!==null?b(t,u):new Date;if(!m)return{stdout:"",stderr:`date: invalid date '${t}'
`,exitCode:1};let d=Math.floor(m.getTime()/1e3),l;return o?l=y(o,d,c):i?l=y("%Y-%m-%dT%H:%M:%S%z",d,c):n?l=y("%a, %d %b %Y %H:%M:%S %z",d,c):l=y("%a %b %e %H:%M:%S %Z %Y",d,c),{stdout:`${l}
`,stderr:"",exitCode:0}}},R={name:"date",flags:[{flag:"-d",type:"value",valueHint:"string"},{flag:"-u",type:"boolean"},{flag:"-I",type:"boolean"},{flag:"-R",type:"boolean"}]};export{v as a,R as b};
