function parseDuration(duration) {
  const iso8601Regex = /P(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?/;
  const iso8601Match = duration.match(iso8601Regex);
  if (iso8601Match && iso8601Match[0] === duration) {
    const days = parseInt(iso8601Match[1] || "0");
    const hours = parseInt(iso8601Match[2] || "0");
    const minutes = parseInt(iso8601Match[3] || "0");
    const seconds = parseInt(iso8601Match[4] || "0");
    return days * 24 * 60 * 60 * 1e3 + hours * 60 * 60 * 1e3 + minutes * 60 * 1e3 + seconds * 1e3;
  }
  const simpleRegex = /^(\d+)(d|h|m|s)$/;
  const simpleMatch = duration.match(simpleRegex);
  if (simpleMatch) {
    const value = parseInt(simpleMatch[1]);
    const unit = simpleMatch[2];
    switch (unit) {
      case "d":
        return value * 24 * 60 * 60 * 1e3;
      case "h":
        return value * 60 * 60 * 1e3;
      case "m":
        return value * 60 * 1e3;
      case "s":
        return value * 1e3;
    }
  }
  throw new Error(`Invalid duration format: ${duration}`);
}
export {
  parseDuration
};
//# sourceMappingURL=duration.js.map
