"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const dayjs_min = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/dayjs.min.js");
const customParseFormat = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/customParseFormat.js");
const isBetween = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/isBetween.js");
const weekOfYear = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/weekOfYear.js");
const advancedFormat = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/advancedFormat.js");
const weekYear = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/weekYear.js");
const quarterOfYear = require("../../../../../../dayjs@1.11.5/node_modules/dayjs/plugin/quarterOfYear.js");
const is = require("./is.js");
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __read = globalThis && globalThis.__read || function(o, n) {
  var m = typeof Symbol === "function" && o[Symbol.iterator];
  if (!m)
    return o;
  var i = m.call(o), r, ar = [], e;
  try {
    while ((n === void 0 || n-- > 0) && !(r = i.next()).done)
      ar.push(r.value);
  } catch (error) {
    e = { error };
  } finally {
    try {
      if (r && !r.done && (m = i["return"]))
        m.call(i);
    } finally {
      if (e)
        throw e.error;
    }
  }
  return ar;
};
var __spreadArray = globalThis && globalThis.__spreadArray || function(to, from, pack) {
  if (pack || arguments.length === 2)
    for (var i = 0, l = from.length, ar; i < l; i++) {
      if (ar || !(i in from)) {
        if (!ar)
          ar = Array.prototype.slice.call(from, 0, i);
        ar[i] = from[i];
      }
    }
  return to.concat(ar || Array.prototype.slice.call(from));
};
var isMoment = dayjs_min()._isAMomentObject;
if (isMoment) {
  dayjs_min.extend = function() {
  };
}
var overwriteIsDayjs = function(_, Dayjs, dayjs2) {
  dayjs2 = function(date, c) {
    if (is.isDayjs(date)) {
      return date.clone();
    }
    var cfg = typeof c === "object" ? c : {};
    cfg.date = date;
    cfg.args = arguments;
    return new Dayjs(cfg);
  };
  var proto = Dayjs.prototype;
  var old$Utils = proto.$utils;
  proto.$utils = function() {
    var newUtils = old$Utils();
    newUtils.i = is.isDayjs;
    return newUtils;
  };
  dayjs2.isDayjs = is.isDayjs;
};
dayjs_min.extend(overwriteIsDayjs);
dayjs_min.extend(customParseFormat);
dayjs_min.extend(isBetween);
dayjs_min.extend(weekOfYear);
dayjs_min.extend(advancedFormat);
dayjs_min.extend(weekYear);
dayjs_min.extend(quarterOfYear);
var dayjs = dayjs_min;
var methods = {
  add: function(time, value, unit) {
    return isMoment ? time.clone().add(value, unit) : time.add(value, unit);
  },
  subtract: function(time, value, unit) {
    return isMoment ? time.clone().subtract(value, unit) : time.subtract(value, unit);
  },
  startOf: function(time, unit) {
    return isMoment ? time.clone().startOf(unit) : time.startOf(unit);
  },
  endOf: function(time, unit) {
    return isMoment ? time.clone().endOf(unit) : time.endOf(unit);
  },
  set: function(time, unit, value) {
    return isMoment ? time.clone().set(unit, value) : time.set(unit, value);
  },
  isSameWeek: function(date1, date2, weekStart, localeName) {
    return isMoment ? date1.locale(localeName, { week: { dow: weekStart } }).isSame(date2, "week") : date1.locale(__assign(__assign({}, dayjs.Ls[localeName]), { weekStart })).isSame(date2, "week");
  }
};
var typeToPos = {
  year: 0,
  month: 1,
  day: 2,
  hour: 3,
  minute: 4,
  second: 5
};
var dtfCache = {};
var getDateTimeFormat = function(timezone, timeZoneName) {
  var key = timezone + "|" + (timeZoneName || "short");
  var dtf = dtfCache[key];
  if (!dtf) {
    dtf = new Intl.DateTimeFormat("en-US", {
      hour12: false,
      timeZone: timezone,
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit"
    });
    dtfCache[key] = dtf;
  }
  return dtf;
};
var makeFormatParts = function(timestamp, timezone) {
  var date = new Date(timestamp);
  var dtf = getDateTimeFormat(timezone);
  return dtf.formatToParts(date);
};
var tzOffset = function(timestamp, timezone) {
  var formatResult = makeFormatParts(timestamp, timezone);
  var filled = [];
  for (var i = 0; i < formatResult.length; i += 1) {
    var _a = formatResult[i], type = _a.type, value = _a.value;
    var pos = typeToPos[type];
    if (pos >= 0) {
      filled[pos] = parseInt(value, 10);
    }
  }
  var hour = filled[3];
  var fixedHour = hour === 24 ? 0 : hour;
  var utcTs = Date.UTC(filled[0], filled[1] - 1, filled[2], fixedHour, filled[4], filled[5], 0);
  var asTS = +timestamp;
  var over = asTS % 1e3;
  asTS -= over;
  return (utcTs - asTS) / (60 * 1e3);
};
var fixOffset = function(localTS, o0, tz) {
  var utcGuess = localTS - o0 * 60 * 1e3;
  var o2 = tzOffset(utcGuess, tz);
  if (o0 === o2) {
    return [utcGuess, o0];
  }
  utcGuess -= (o2 - o0) * 60 * 1e3;
  var o3 = tzOffset(utcGuess, tz);
  if (o2 === o3) {
    return [utcGuess, o2];
  }
  return [localTS - Math.min(o2, o3) * 60 * 1e3, Math.max(o2, o3)];
};
function timezoneToOffset(inputTs, timezone) {
  return fixOffset(inputTs, tzOffset(new Date().getTime(), timezone), timezone)[1];
}
function getNow(utcOffset, timezone) {
  return is.isUndefined(utcOffset) && !timezone ? dayjs() : toTimezone(dayjs(), utcOffset, timezone);
}
function toTimezone(time, utcOffset, timezone, local) {
  if (!time || is.isUndefined(utcOffset) && !timezone) {
    return time;
  }
  var localOffset = -time.toDate().getTimezoneOffset();
  var uOffset = is.isUndefined(utcOffset) ? !timezone ? localOffset : timezoneToOffset(time.valueOf(), timezone) : utcOffset;
  var timezoneOffset = Math.abs(uOffset) <= 16 ? uOffset * 60 : uOffset;
  var diffOffset = local ? localOffset - timezoneOffset : timezoneOffset - localOffset;
  return dayjs(dayjs(time).valueOf() + diffOffset * 60 * 1e3);
}
function toLocal(time, utcOffset, timezone) {
  return toTimezone(time, utcOffset, timezone, true);
}
function getTimeFormat(format) {
  var units = ["H", "h", "m", "s", "A", "a"];
  var timeFormat = "";
  units.some(function(unit) {
    if (format.indexOf(unit) !== -1) {
      timeFormat = "" + unit + format.split(" " + unit)[1];
      return true;
    }
    return false;
  });
  return timeFormat || "HH:mm:ss";
}
function getDayjsValue(time, format, utcOffset, timezone) {
  if (!time) {
    return void 0;
  }
  var formatValue = function(value) {
    if (is.isDayjs(value)) {
      return dayjs(value.valueOf());
    }
    if (typeof value === "string") {
      var dv = dayjs(value, format);
      return dv.isValid() ? dv : dayjs(value, "YYYY-MM-DD");
    }
    return dayjs(value);
  };
  var getRealTime = function(t) {
    return utcOffset !== void 0 || timezone ? toTimezone(formatValue(t), utcOffset, timezone) : formatValue(t);
  };
  if (is.isArray(time)) {
    return time.map(function(t) {
      return t ? getRealTime(t) : void 0;
    });
  }
  return getRealTime(time);
}
function getValueWithTime(date, time) {
  var y = date.year();
  var m = date.month();
  var d = date.date();
  if (time) {
    var returnTime = time;
    returnTime = methods.set(returnTime, "year", y);
    returnTime = methods.set(returnTime, "month", m);
    returnTime = methods.set(returnTime, "date", d);
    return returnTime;
  }
  return date;
}
function getSortedDayjsArray(values) {
  if (!values || !values[0] || !values[1]) {
    return values;
  }
  var newValues = __spreadArray([], __read(values), false);
  newValues.sort(function(a, b) {
    return a.valueOf() - b.valueOf();
  });
  return newValues;
}
function isDayjsChange(prevValue, currentValue) {
  if (currentValue === void 0 && prevValue === void 0) {
    return false;
  }
  return currentValue && !prevValue || !currentValue && prevValue || dayjs(currentValue).valueOf() !== dayjs(prevValue).valueOf();
}
function isDayjsArrayChange(prevValue, currentValue) {
  if (currentValue === void 0 && prevValue === void 0) {
    return false;
  }
  return currentValue && !prevValue || !currentValue && prevValue || is.isArray(currentValue) && is.isArray(prevValue) && dayjs(currentValue[0]).valueOf() !== dayjs(prevValue[0]).valueOf() || dayjs(currentValue[1]).valueOf() !== dayjs(prevValue[1]).valueOf();
}
function isValidTimeString(str, format) {
  return typeof str === "string" && dayjs(str, format).format(format) === str;
}
exports.dayjs = dayjs;
exports.getDayjsValue = getDayjsValue;
exports.getNow = getNow;
exports.getSortedDayjsArray = getSortedDayjsArray;
exports.getTimeFormat = getTimeFormat;
exports.getValueWithTime = getValueWithTime;
exports.isDayjsArrayChange = isDayjsArrayChange;
exports.isDayjsChange = isDayjsChange;
exports.isValidTimeString = isValidTimeString;
exports.methods = methods;
exports.timezoneToOffset = timezoneToOffset;
exports.toLocal = toLocal;
exports.toTimezone = toTimezone;
//# sourceMappingURL=dayjs.js.map
