"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { constants: () => constants_exports, getLeapMonth: () => getLeapMonth, getLeapMonthDays: () => getLeapMonthDays, getMonthDays: () => getMonthDays, getYearDays: () => getYearDays, isDate: () => isDate, isValidDate: () => isValidDate, isValidLunar: () => isValidLunar, isValidSolar: () => isValidSolar, toGMTDate: () => toGMTDate, toLunar: () => toLunar, toSolar: () => toSolar }); module.exports = __toCommonJS(src_exports); // src/constants/index.ts var constants_exports = {}; __export(constants_exports, { BASE_DAY: () => BASE_DAY, BASE_MONTH: () => BASE_MONTH, BASE_YEAR: () => BASE_YEAR, LUNAR_DATA: () => LUNAR_DATA, MAXIMUM_LUNAR_DAY: () => MAXIMUM_LUNAR_DAY, MAXIMUM_LUNAR_MONTH: () => MAXIMUM_LUNAR_MONTH, MAXIMUM_LUNAR_YEAR: () => MAXIMUM_LUNAR_YEAR, MAXIMUM_YEAR: () => MAXIMUM_YEAR }); var BASE_YEAR = 1900; var BASE_MONTH = 1; var BASE_DAY = 31; var MAXIMUM_YEAR = 2100; var MAXIMUM_LUNAR_YEAR = 2100; var MAXIMUM_LUNAR_MONTH = 12; var MAXIMUM_LUNAR_DAY = 1; var LUNAR_DATA = [ 19416, // 1900 19168, // 1901 42352, // 1902 21717, // 1903 53856, // 1904 55632, // 1905 91476, // 1906 22176, // 1907 39632, // 1908 21970, // 1909 19168, // 1910 42422, // 1911 42192, // 1912 53840, // 1913 119381, // 1914 46400, // 1915 54944, // 1916 44450, // 1917 38320, // 1918 84343, // 1919 18800, // 1920 42160, // 1921 46261, // 1922 27216, // 1923 27968, // 1924 109396, // 1925 11104, // 1926 38256, // 1927 21234, // 1928 18800, // 1929 25958, // 1930 54432, // 1931 59984, // 1932 28309, // 1933 23248, // 1934 11104, // 1935 100067, // 1936 37600, // 1937 116951, // 1938 51536, // 1939 54432, // 1940 120998, // 1941 46416, // 1942 22176, // 1943 107956, // 1944 9680, // 1945 37584, // 1946 53938, // 1947 43344, // 1948 46423, // 1949 27808, // 1950 46416, // 1951 86869, // 1952 19872, // 1953 42416, // 1954 83315, // 1955 21168, // 1956 43432, // 1957 59728, // 1958 27296, // 1959 44710, // 1960 43856, // 1961 19296, // 1962 43748, // 1963 42352, // 1964 21088, // 1965 62051, // 1966 55632, // 1967 23383, // 1968 22176, // 1969 38608, // 1970 19925, // 1971 19152, // 1972 42192, // 1973 54484, // 1974 53840, // 1975 54616, // 1976 46400, // 1977 46752, // 1978 103846, // 1979 38320, // 1980 18864, // 1981 43380, // 1982 42160, // 1983 45690, // 1984 27216, // 1985 27968, // 1986 44870, // 1987 43872, // 1988 38256, // 1989 19189, // 1990 18800, // 1991 25776, // 1992 29859, // 1993 59984, // 1994 27480, // 1995 21952, // 1996 43872, // 1997 38613, // 1998 37600, // 1999 51552, // 2000 55636, // 2001 54432, // 2002 55888, // 2003 30034, // 2004 22176, // 2005 43959, // 2006 9680, // 2007 37584, // 2008 51893, // 2009 43344, // 2010 46240, // 2011 47780, // 2012 44368, // 2013 21977, // 2014 19360, // 2015 42416, // 2016 86390, // 2017 21168, // 2018 43312, // 2019 31060, // 2020 27296, // 2021 44368, // 2022 23378, // 2023 19296, // 2024 42726, // 2025 42208, // 2026 53856, // 2027 60005, // 2028 54576, // 2029 23200, // 2030 30371, // 2031 38608, // 2032 19195, // 2033 19152, // 2034 42192, // 2035 118966, // 2036 53840, // 2037 54560, // 2038 56645, // 2039 46496, // 2040 22224, // 2041 21938, // 2042 18864, // 2043 42359, // 2044 42160, // 2045 43600, // 2046 111189, // 2047 27936, // 2048 44448, // 2049 84835, // 2050 37744, // 2051 18936, // 2052 18800, // 2053 25776, // 2054 92326, // 2055 59984, // 2056 27424, // 2057 108228, // 2058 43744, // 2059 41696, // 2060 53987, // 2061 51552, // 2062 54615, // 2063 54432, // 2064 55888, // 2065 23893, // 2066 22176, // 2067 42704, // 2068 21972, // 2069 21200, // 2070 43448, // 2071 43344, // 2072 46240, // 2073 46758, // 2074 44368, // 2075 21920, // 2076 43940, // 2077 42416, // 2078 21168, // 2079 45683, // 2080 26928, // 2081 29495, // 2082 27296, // 2083 44368, // 2084 84821, // 2085 19296, // 2086 42352, // 2087 21732, // 2088 53600, // 2089 59752, // 2090 54560, // 2091 55968, // 2092 92838, // 2093 22224, // 2094 19168, // 2095 43476, // 2096 41680, // 2097 53584, // 2098 62034, // 2099 54560 // 2100 ]; // src/get-leap-month/index.ts function getLeapMonth(year) { return LUNAR_DATA[year - BASE_YEAR] & 15; } // src/get-leap-month-days/index.ts function getLeapMonthDays(year) { if (!getLeapMonth(year)) return 0; return LUNAR_DATA[year - BASE_YEAR] & 65536 ? 30 : 29; } // src/get-month-days/index.ts function getMonthDays(year, month) { if (!year || year < BASE_YEAR || year > MAXIMUM_LUNAR_YEAR || !month || month > 12 || month < 1) { return -1; } return LUNAR_DATA[year - BASE_YEAR] & 65536 >> month ? 30 : 29; } // src/get-year-days/index.ts function getYearDays(year) { if (!year || year < BASE_YEAR || year > MAXIMUM_LUNAR_YEAR) return -1; let sum = 348; const yearData = LUNAR_DATA[year - BASE_YEAR]; for (let i = 32768; i > 8; i >>= 1) { sum += yearData & i ? 1 : 0; } return sum + (getLeapMonth(year) ? getLeapMonthDays(year) : 0); } // src/is-date/index.ts function isDate(value) { return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]"; } // src/is-valid-date/index.ts function isValidDate(date) { return isDate(date) && !Number.isNaN(date.getTime()); } // src/_lib/base-get-tag.ts function baseGetTag(value) { return Object.prototype.toString.call(value); } var base_get_tag_default = baseGetTag; // src/is-plain-object/index.ts function isPlainObject(value) { if (base_get_tag_default(value) !== "[object Object]") { return false; } const proto = Object.getPrototypeOf(value); if (proto === null) { return true; } const constructor = Object.hasOwn(proto, "constructor") && proto.constructor; return typeof constructor === "function" && constructor instanceof constructor && Function.prototype.toString.call(Object) === Function.prototype.toString.call(constructor); } // src/is-valid-lunar/index.ts function isValidLunar(lunar) { if (!isPlainObject(lunar) || typeof lunar.year !== "number" || typeof lunar.month !== "number" || typeof lunar.day !== "number" || lunar.month < 0 || lunar.day <= 0) { return false; } const isLeapMonth = Boolean(lunar.isLeapMonth); if (isLeapMonth && getLeapMonth(lunar.year) !== lunar.month || lunar.day > (isLeapMonth ? getLeapMonthDays(lunar.year) : getMonthDays(lunar.year, lunar.month))) { return false; } const baseDate = Date.UTC(BASE_YEAR, BASE_MONTH - 1, 1); const targetDate = Date.UTC(lunar.year, lunar.month - 1, lunar.day); const maximumDate = Date.UTC(MAXIMUM_LUNAR_YEAR, MAXIMUM_LUNAR_MONTH - 1, MAXIMUM_LUNAR_DAY); return targetDate >= baseDate && targetDate <= maximumDate; } // src/_lib/get-base-date.ts function getBaseDate() { return Date.UTC(BASE_YEAR, BASE_MONTH - 1, BASE_DAY); } var get_base_date_default = getBaseDate; // src/to-gmt-date/index.ts function toGMTDate(date) { return new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate())); } // src/is-valid-solar/index.ts function isValidSolar(date) { if (!isValidDate(date)) return false; const baseDate = get_base_date_default(); const targetDate = toGMTDate(date).getTime(); const maximumDate = Date.UTC(MAXIMUM_YEAR, 11, 31); return targetDate >= baseDate && targetDate <= maximumDate; } // src/to-lunar/index.ts function toLunar(date) { if (!isValidSolar(date)) return -1; const baseDate = get_base_date_default(); const targetDate = toGMTDate(date).getTime(); let offset = Math.floor((targetDate - baseDate) / 864e5); let year; let month; let isLeapMonth = false; let yearDays = 0; for (year = BASE_YEAR; year <= MAXIMUM_YEAR && offset > 0; year++) { yearDays = getYearDays(year); offset -= yearDays; } if (offset < 0 && year--) offset += yearDays; const leapMonth = getLeapMonth(year); let monthDays = 0; for (month = 1; month < 13 && offset > 0; month++) { if (leapMonth > 0 && month === leapMonth + 1 && !isLeapMonth) { monthDays = getLeapMonthDays(year); isLeapMonth = Boolean(month--); } else { monthDays = getMonthDays(year, month); } if (isLeapMonth && month === leapMonth + 1) isLeapMonth = false; offset -= monthDays; } if (offset === 0 && leapMonth > 0 && month === leapMonth + 1) { isLeapMonth = !isLeapMonth && Boolean(month--); } if (offset < 0 && month--) offset += monthDays; const day = offset + 1; return { year, month, day, isLeapMonth }; } // src/to-solar/index.ts function toSolar(lunar) { if (!isValidLunar(lunar)) return -1; let offset = 0; let isLeapProcessed = false; const leapMonth = getLeapMonth(lunar.year); for (let year = BASE_YEAR; year < lunar.year; year++) { offset += getYearDays(year); } for (let month = 1; month < lunar.month; month++) { offset += getMonthDays(lunar.year, month); if (!isLeapProcessed && leapMonth <= month && leapMonth > 0) { offset += getLeapMonthDays(lunar.year); isLeapProcessed = true; } } if (lunar.isLeapMonth) { offset += getMonthDays(lunar.year, lunar.month); } offset += lunar.day - 1; const baseDate = get_base_date_default(); const timezoneOffset = (/* @__PURE__ */ new Date()).getTimezoneOffset() * 6e4; return new Date(baseDate + offset * 864e5 + timezoneOffset); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { constants, getLeapMonth, getLeapMonthDays, getMonthDays, getYearDays, isDate, isValidDate, isValidLunar, isValidSolar, toGMTDate, toLunar, toSolar });