/**
 * Copyright IBM Corp. 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { int, pad } from "./index.js";
//#region ../../node_modules/flatpickr/dist/esm/utils/formatting.js
var doNothing = function() {};
var monthToStr = function(monthNumber, shorthand, locale) {
	return locale.months[shorthand ? "shorthand" : "longhand"][monthNumber];
};
var revFormat = {
	D: doNothing,
	F: function(dateObj, monthName, locale) {
		dateObj.setMonth(locale.months.longhand.indexOf(monthName));
	},
	G: function(dateObj, hour) {
		dateObj.setHours((dateObj.getHours() >= 12 ? 12 : 0) + parseFloat(hour));
	},
	H: function(dateObj, hour) {
		dateObj.setHours(parseFloat(hour));
	},
	J: function(dateObj, day) {
		dateObj.setDate(parseFloat(day));
	},
	K: function(dateObj, amPM, locale) {
		dateObj.setHours(dateObj.getHours() % 12 + 12 * int(new RegExp(locale.amPM[1], "i").test(amPM)));
	},
	M: function(dateObj, shortMonth, locale) {
		dateObj.setMonth(locale.months.shorthand.indexOf(shortMonth));
	},
	S: function(dateObj, seconds) {
		dateObj.setSeconds(parseFloat(seconds));
	},
	U: function(_, unixSeconds) {
		return /* @__PURE__ */ new Date(parseFloat(unixSeconds) * 1e3);
	},
	W: function(dateObj, weekNum, locale) {
		var weekNumber = parseInt(weekNum);
		var date = new Date(dateObj.getFullYear(), 0, 2 + (weekNumber - 1) * 7, 0, 0, 0, 0);
		date.setDate(date.getDate() - date.getDay() + locale.firstDayOfWeek);
		return date;
	},
	Y: function(dateObj, year) {
		dateObj.setFullYear(parseFloat(year));
	},
	Z: function(_, ISODate) {
		return new Date(ISODate);
	},
	d: function(dateObj, day) {
		dateObj.setDate(parseFloat(day));
	},
	h: function(dateObj, hour) {
		dateObj.setHours((dateObj.getHours() >= 12 ? 12 : 0) + parseFloat(hour));
	},
	i: function(dateObj, minutes) {
		dateObj.setMinutes(parseFloat(minutes));
	},
	j: function(dateObj, day) {
		dateObj.setDate(parseFloat(day));
	},
	l: doNothing,
	m: function(dateObj, month) {
		dateObj.setMonth(parseFloat(month) - 1);
	},
	n: function(dateObj, month) {
		dateObj.setMonth(parseFloat(month) - 1);
	},
	s: function(dateObj, seconds) {
		dateObj.setSeconds(parseFloat(seconds));
	},
	u: function(_, unixMillSeconds) {
		return new Date(parseFloat(unixMillSeconds));
	},
	w: doNothing,
	y: function(dateObj, year) {
		dateObj.setFullYear(2e3 + parseFloat(year));
	}
};
var tokenRegex = {
	D: "",
	F: "",
	G: "(\\d\\d|\\d)",
	H: "(\\d\\d|\\d)",
	J: "(\\d\\d|\\d)\\w+",
	K: "",
	M: "",
	S: "(\\d\\d|\\d)",
	U: "(.+)",
	W: "(\\d\\d|\\d)",
	Y: "(\\d{4})",
	Z: "(.+)",
	d: "(\\d\\d|\\d)",
	h: "(\\d\\d|\\d)",
	i: "(\\d\\d|\\d)",
	j: "(\\d\\d|\\d)",
	l: "",
	m: "(\\d\\d|\\d)",
	n: "(\\d\\d|\\d)",
	s: "(\\d\\d|\\d)",
	u: "(.+)",
	w: "(\\d\\d|\\d)",
	y: "(\\d{2})"
};
var formats = {
	Z: function(date) {
		return date.toISOString();
	},
	D: function(date, locale, options) {
		return locale.weekdays.shorthand[formats.w(date, locale, options)];
	},
	F: function(date, locale, options) {
		return monthToStr(formats.n(date, locale, options) - 1, false, locale);
	},
	G: function(date, locale, options) {
		return pad(formats.h(date, locale, options));
	},
	H: function(date) {
		return pad(date.getHours());
	},
	J: function(date, locale) {
		return locale.ordinal !== void 0 ? date.getDate() + locale.ordinal(date.getDate()) : date.getDate();
	},
	K: function(date, locale) {
		return locale.amPM[int(date.getHours() > 11)];
	},
	M: function(date, locale) {
		return monthToStr(date.getMonth(), true, locale);
	},
	S: function(date) {
		return pad(date.getSeconds());
	},
	U: function(date) {
		return date.getTime() / 1e3;
	},
	W: function(date, _, options) {
		return options.getWeek(date);
	},
	Y: function(date) {
		return pad(date.getFullYear(), 4);
	},
	d: function(date) {
		return pad(date.getDate());
	},
	h: function(date) {
		return date.getHours() % 12 ? date.getHours() % 12 : 12;
	},
	i: function(date) {
		return pad(date.getMinutes());
	},
	j: function(date) {
		return date.getDate();
	},
	l: function(date, locale) {
		return locale.weekdays.longhand[date.getDay()];
	},
	m: function(date) {
		return pad(date.getMonth() + 1);
	},
	n: function(date) {
		return date.getMonth() + 1;
	},
	s: function(date) {
		return date.getSeconds();
	},
	u: function(date) {
		return date.getTime();
	},
	w: function(date) {
		return date.getDay();
	},
	y: function(date) {
		return String(date.getFullYear()).substring(2);
	}
};
//#endregion
export { formats, monthToStr, revFormat, tokenRegex };

//# sourceMappingURL=formatting.js.map