function formatDateTime(value) {
  if (!value) return null;
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return null;
  return date.toLocaleString();
}
function formatRelativeTime(value, options) {
  if (!value) return null;
  const date = new Date(value);
  if (Number.isNaN(date.getTime())) return null;
  const now = Date.now();
  const diffSeconds = (date.getTime() - now) / 1e3;
  const absSeconds = Math.abs(diffSeconds);
  const translate = options?.translate;
  const rtf = typeof Intl !== "undefined" && typeof Intl.RelativeTimeFormat === "function" ? new Intl.RelativeTimeFormat(options?.locale, { numeric: "auto" }) : null;
  const format = (unit, divisor) => {
    const valueToFormat = Math.round(diffSeconds / divisor);
    if (rtf) return rtf.format(valueToFormat, unit);
    const isPast = diffSeconds < 0;
    const fallbackSuffix = isPast ? "ago" : "from now";
    const suffixKey = isPast ? "time.relative.ago" : "time.relative.fromNow";
    const suffix = translate ? translate(suffixKey, fallbackSuffix) : fallbackSuffix;
    const magnitude = Math.abs(valueToFormat);
    return `${magnitude} ${unit}${magnitude === 1 ? "" : "s"} ${suffix}`;
  };
  if (absSeconds < 45) return format("second", 1);
  if (absSeconds < 45 * 60) return format("minute", 60);
  if (absSeconds < 24 * 60 * 60) return format("hour", 60 * 60);
  if (absSeconds < 7 * 24 * 60 * 60) return format("day", 24 * 60 * 60);
  if (absSeconds < 30 * 24 * 60 * 60) return format("week", 7 * 24 * 60 * 60);
  if (absSeconds < 365 * 24 * 60 * 60) return format("month", 30 * 24 * 60 * 60);
  return format("year", 365 * 24 * 60 * 60);
}
export {
  formatDateTime,
  formatRelativeTime
};
//# sourceMappingURL=time.js.map
