import O from "./utils/normalizeDate.js";
function F(e, t) {
  const n = Z(t);
  return "formatToParts" in n ? _(n, e) : $(n, e);
}
const y = {
  year: 0,
  month: 1,
  day: 2,
  hour: 3,
  minute: 4,
  second: 5
};
function _(e, t) {
  try {
    const n = e.formatToParts(t), r = [];
    for (let a = 0; a < n.length; a++) {
      const i = y[n[a].type];
      i !== void 0 && (r[i] = parseInt(n[a].value, 10));
    }
    return r;
  } catch (n) {
    if (n instanceof RangeError)
      return [NaN];
    throw n;
  }
}
function $(e, t) {
  const n = e.format(t), r = /(\d+)\/(\d+)\/(\d+),? (\d+):(\d+):(\d+)/.exec(n);
  return [
    parseInt(r[3], 10),
    parseInt(r[1], 10),
    parseInt(r[2], 10),
    parseInt(r[4], 10),
    parseInt(r[5], 10),
    parseInt(r[6], 10)
  ];
}
const f = {};
function Z(e) {
  if (!f[e]) {
    const t = new Intl.DateTimeFormat("en-US", {
      hourCycle: "h23",
      timeZone: "America/New_York",
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }).format(/* @__PURE__ */ new Date("2014-06-25T04:00:00.123Z")), n = t === "06/25/2014, 00:00:00" || t === "‎06‎/‎25‎/‎2014‎ ‎00‎:‎00‎:‎00";
    f[e] = n ? new Intl.DateTimeFormat("en-US", {
      hourCycle: "h23",
      timeZone: e,
      year: "numeric",
      month: "numeric",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    }) : new Intl.DateTimeFormat("en-US", {
      hour12: !1,
      timeZone: e,
      year: "numeric",
      month: "numeric",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    });
  }
  return f[e];
}
function C(e, t, n, r, a, i, o) {
  const u = /* @__PURE__ */ new Date(0);
  return u.setUTCFullYear(e, t, n), u.setUTCHours(r, a, i, o), u;
}
const m = 36e5, b = 6e4, D = {
  timezoneZ: /^(Z)$/,
  timezoneHH: /^([+-]\d{2})$/,
  timezoneHHMM: /^([+-])(\d{2}):?(\d{2})$/
};
function U(e, t, n) {
  if (!e)
    return 0;
  let r = D.timezoneZ.exec(e);
  if (r)
    return 0;
  let a, i;
  if (r = D.timezoneHH.exec(e), r)
    return a = parseInt(r[1], 10), p(a) ? -(a * m) : NaN;
  if (r = D.timezoneHHMM.exec(e), r) {
    a = parseInt(r[2], 10);
    const o = parseInt(r[3], 10);
    return p(a, o) ? (i = Math.abs(a) * m + o * b, r[1] === "+" ? -i : i) : NaN;
  }
  if (L(e)) {
    t = new Date(t || Date.now());
    const o = n ? t : A(t), u = N(o, e);
    return -(n ? u : S(t, u, e));
  }
  return NaN;
}
function A(e) {
  return C(e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes(), e.getSeconds(), e.getMilliseconds());
}
function N(e, t) {
  const n = F(e, t), r = C(n[0], n[1] - 1, n[2], n[3] % 24, n[4], n[5], 0).getTime();
  let a = e.getTime();
  const i = a % 1e3;
  return a -= i >= 0 ? i : 1e3 + i, r - a;
}
function S(e, t, n) {
  let a = e.getTime() - t;
  const i = N(new Date(a), n);
  if (t === i)
    return t;
  a -= i - t;
  const o = N(new Date(a), n);
  return i === o ? i : Math.max(i, o);
}
function p(e, t) {
  return -23 <= e && e <= 23 && (t == null || 0 <= t && t <= 59);
}
const Y = {};
function L(e) {
  if (Y[e])
    return !0;
  try {
    return new Intl.DateTimeFormat(void 0, { timeZone: e }), Y[e] = !0, !0;
  } catch {
    return !1;
  }
}
function I(e) {
  const t = new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate(), e.getHours(), e.getMinutes(), e.getSeconds(), e.getMilliseconds()));
  return t.setUTCFullYear(e.getFullYear()), +e - +t;
}
const E = /(Z|[+-]\d{2}(?::?\d{2})?| UTC| [a-zA-Z]+\/[a-zA-Z_]+(?:\/[a-zA-Z_]+)?)$/, d = 36e5, w = 6e4, z = 2, s = {
  dateTimePattern: /^([0-9W+-]+)(T| )(.*)/,
  datePattern: /^([0-9W+-]+)(.*)/,
  // year tokens
  YY: /^(\d{2})$/,
  YYY: [
    /^([+-]\d{2})$/,
    // 0 additional digits
    /^([+-]\d{3})$/,
    // 1 additional digit
    /^([+-]\d{4})$/
    // 2 additional digits
  ],
  YYYY: /^(\d{4})/,
  YYYYY: [
    /^([+-]\d{4})/,
    // 0 additional digits
    /^([+-]\d{5})/,
    // 1 additional digit
    /^([+-]\d{6})/
    // 2 additional digits
  ],
  // date tokens
  MM: /^-(\d{2})$/,
  DDD: /^-?(\d{3})$/,
  MMDD: /^-?(\d{2})-?(\d{2})$/,
  Www: /^-?W(\d{2})$/,
  WwwD: /^-?W(\d{2})-?(\d{1})$/,
  HH: /^(\d{2}([.,]\d*)?)$/,
  HHMM: /^(\d{2}):?(\d{2}([.,]\d*)?)$/,
  HHMMSS: /^(\d{2}):?(\d{2}):?(\d{2}([.,]\d*)?)$/,
  // time zone tokens (to identify the presence of a tz)
  timeZone: E
};
function H(e, t = {}) {
  if (arguments.length < 1)
    throw new TypeError("1 argument required, but only " + arguments.length + " present");
  if (e === null)
    return /* @__PURE__ */ new Date(NaN);
  const n = t.additionalDigits == null ? z : Number(t.additionalDigits);
  if (n !== 2 && n !== 1 && n !== 0)
    throw new RangeError("additionalDigits must be 0, 1 or 2");
  if (e instanceof Date || typeof e == "object" && Object.prototype.toString.call(e) === "[object Date]")
    return new Date(e.getTime());
  if (typeof e == "number" || Object.prototype.toString.call(e) === "[object Number]")
    return new Date(e);
  if (Object.prototype.toString.call(e) !== "[object String]")
    return /* @__PURE__ */ new Date(NaN);
  const r = W(e), { year: a, restDateString: i } = k(r.date, n), o = P(i, a);
  if (o === null || isNaN(o.getTime()))
    return /* @__PURE__ */ new Date(NaN);
  if (o) {
    const u = o.getTime();
    let c = 0, l;
    if (r.time && (c = v(r.time), c === null || isNaN(c)))
      return /* @__PURE__ */ new Date(NaN);
    if (r.timeZone || t.timeZone) {
      if (l = U(r.timeZone || t.timeZone, new Date(u + c)), isNaN(l))
        return /* @__PURE__ */ new Date(NaN);
    } else
      l = I(new Date(u + c)), l = I(new Date(u + c + l));
    return new Date(u + c + l);
  } else
    return /* @__PURE__ */ new Date(NaN);
}
function W(e) {
  const t = {};
  let n = s.dateTimePattern.exec(e), r;
  if (n ? (t.date = n[1], r = n[3]) : (n = s.datePattern.exec(e), n ? (t.date = n[1], r = n[2]) : (t.date = null, r = e)), r) {
    const a = s.timeZone.exec(r);
    a ? (t.time = r.replace(a[1], ""), t.timeZone = a[1].trim()) : t.time = r;
  }
  return t;
}
function k(e, t) {
  if (e) {
    const n = s.YYY[t], r = s.YYYYY[t];
    let a = s.YYYY.exec(e) || r.exec(e);
    if (a) {
      const i = a[1];
      return {
        year: parseInt(i, 10),
        restDateString: e.slice(i.length)
      };
    }
    if (a = s.YY.exec(e) || n.exec(e), a) {
      const i = a[1];
      return {
        year: parseInt(i, 10) * 100,
        restDateString: e.slice(i.length)
      };
    }
  }
  return {
    year: null
  };
}
function P(e, t) {
  if (t === null)
    return null;
  let n, r, a;
  if (!e || !e.length)
    return n = /* @__PURE__ */ new Date(0), n.setUTCFullYear(t), n;
  let i = s.MM.exec(e);
  if (i)
    return n = /* @__PURE__ */ new Date(0), r = parseInt(i[1], 10) - 1, g(t, r) ? (n.setUTCFullYear(t, r), n) : /* @__PURE__ */ new Date(NaN);
  if (i = s.DDD.exec(e), i) {
    n = /* @__PURE__ */ new Date(0);
    const o = parseInt(i[1], 10);
    return G(t, o) ? (n.setUTCFullYear(t, 0, o), n) : /* @__PURE__ */ new Date(NaN);
  }
  if (i = s.MMDD.exec(e), i) {
    n = /* @__PURE__ */ new Date(0), r = parseInt(i[1], 10) - 1;
    const o = parseInt(i[2], 10);
    return g(t, r, o) ? (n.setUTCFullYear(t, r, o), n) : /* @__PURE__ */ new Date(NaN);
  }
  if (i = s.Www.exec(e), i)
    return a = parseInt(i[1], 10) - 1, h(a) ? M(t, a) : /* @__PURE__ */ new Date(NaN);
  if (i = s.WwwD.exec(e), i) {
    a = parseInt(i[1], 10) - 1;
    const o = parseInt(i[2], 10) - 1;
    return h(a, o) ? M(t, a, o) : /* @__PURE__ */ new Date(NaN);
  }
  return null;
}
function v(e) {
  let t, n, r = s.HH.exec(e);
  if (r)
    return t = parseFloat(r[1].replace(",", ".")), T(t) ? t % 24 * d : NaN;
  if (r = s.HHMM.exec(e), r)
    return t = parseInt(r[1], 10), n = parseFloat(r[2].replace(",", ".")), T(t, n) ? t % 24 * d + n * w : NaN;
  if (r = s.HHMMSS.exec(e), r) {
    t = parseInt(r[1], 10), n = parseInt(r[2], 10);
    const a = parseFloat(r[3].replace(",", "."));
    return T(t, n, a) ? t % 24 * d + n * w + a * 1e3 : NaN;
  }
  return null;
}
function M(e, t, n) {
  t = t || 0, n = n || 0;
  const r = /* @__PURE__ */ new Date(0);
  r.setUTCFullYear(e, 0, 4);
  const a = r.getUTCDay() || 7, i = t * 7 + n + 1 - a;
  return r.setUTCDate(r.getUTCDate() + i), r;
}
const j = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31], R = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
function x(e) {
  return e % 400 === 0 || e % 4 === 0 && e % 100 !== 0;
}
function g(e, t, n) {
  if (t < 0 || t > 11)
    return !1;
  if (n != null) {
    if (n < 1)
      return !1;
    const r = x(e);
    if (r && n > R[t] || !r && n > j[t])
      return !1;
  }
  return !0;
}
function G(e, t) {
  if (t < 1)
    return !1;
  const n = x(e);
  return !(n && t > 366 || !n && t > 365);
}
function h(e, t) {
  return !(e < 0 || e > 52 || t != null && (t < 0 || t > 6));
}
function T(e, t, n) {
  return !(e < 0 || e >= 25 || t != null && (t < 0 || t >= 60) || n != null && (n < 0 || n >= 60));
}
function q(e, t, n) {
  e = H(e, n);
  const r = U(t, e, !0), a = new Date(e.getTime() - r), i = /* @__PURE__ */ new Date(0);
  return i.setFullYear(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate()), i.setHours(a.getUTCHours(), a.getUTCMinutes(), a.getUTCSeconds(), a.getUTCMilliseconds()), i;
}
function V(e, t) {
  const n = H(O(e), { timeZone: "Etc/UTC" });
  return q(n, t);
}
export {
  H as a,
  V as b,
  U as t
};
//# sourceMappingURL=toTimeZone-Coq1oPTt.js.map
