@sonill/nepali-dates 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +376 -0
- package/data/README.md +84 -0
- package/data/calendar-data.json +105 -0
- package/data/reference-dates.json +50 -0
- package/dist/index.d.mts +371 -0
- package/dist/index.d.ts +371 -0
- package/dist/index.js +682 -0
- package/dist/index.mjs +624 -0
- package/package.json +62 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BASE_AD_DATE: () => BASE_AD_DATE,
|
|
24
|
+
BASE_BS_DATE: () => BASE_BS_DATE,
|
|
25
|
+
ENGLISH_MONTH_NAMES: () => ENGLISH_MONTH_NAMES,
|
|
26
|
+
MAX_YEAR: () => MAX_YEAR,
|
|
27
|
+
MIN_YEAR: () => MIN_YEAR,
|
|
28
|
+
NEPALI_CALENDAR_DATA: () => NEPALI_CALENDAR_DATA,
|
|
29
|
+
NEPALI_MONTH_NAMES_EN: () => NEPALI_MONTH_NAMES_EN,
|
|
30
|
+
NEPALI_MONTH_NAMES_NE: () => NEPALI_MONTH_NAMES_NE,
|
|
31
|
+
NepaliMonth: () => NepaliMonth,
|
|
32
|
+
REFERENCE_DATES: () => REFERENCE_DATES,
|
|
33
|
+
adToBs: () => adToBs,
|
|
34
|
+
bsToAd: () => bsToAd,
|
|
35
|
+
formatAdDate: () => formatAdDate,
|
|
36
|
+
formatBsDate: () => formatBsDate,
|
|
37
|
+
getAllCalendarData: () => getAllCalendarData,
|
|
38
|
+
getCalendarData: () => getCalendarData,
|
|
39
|
+
getDataRange: () => getDataRange,
|
|
40
|
+
getDaysInAdMonth: () => getDaysInAdMonth,
|
|
41
|
+
getDaysInRange: () => getDaysInRange,
|
|
42
|
+
getEnglishMonthName: () => getEnglishMonthName,
|
|
43
|
+
getNepaliMonthName: () => getNepaliMonthName,
|
|
44
|
+
getNextMonth: () => getNextMonth,
|
|
45
|
+
getPrevMonth: () => getPrevMonth,
|
|
46
|
+
getTotalDaysInMonth: () => getTotalDaysInMonth,
|
|
47
|
+
getTotalDaysInYear: () => getTotalDaysInYear,
|
|
48
|
+
hasDataForYear: () => hasDataForYear,
|
|
49
|
+
isLeapYear: () => isLeapYear,
|
|
50
|
+
isValidAdDate: () => isValidAdDate,
|
|
51
|
+
isValidBsDate: () => isValidBsDate,
|
|
52
|
+
parseDate: () => parseDate,
|
|
53
|
+
toArray: () => toArray,
|
|
54
|
+
toIsoString: () => toIsoString
|
|
55
|
+
});
|
|
56
|
+
module.exports = __toCommonJS(index_exports);
|
|
57
|
+
|
|
58
|
+
// src/types/index.ts
|
|
59
|
+
var NepaliMonth = /* @__PURE__ */ ((NepaliMonth2) => {
|
|
60
|
+
NepaliMonth2[NepaliMonth2["Baisakh"] = 1] = "Baisakh";
|
|
61
|
+
NepaliMonth2[NepaliMonth2["Jestha"] = 2] = "Jestha";
|
|
62
|
+
NepaliMonth2[NepaliMonth2["Ashar"] = 3] = "Ashar";
|
|
63
|
+
NepaliMonth2[NepaliMonth2["Shrawan"] = 4] = "Shrawan";
|
|
64
|
+
NepaliMonth2[NepaliMonth2["Bhadra"] = 5] = "Bhadra";
|
|
65
|
+
NepaliMonth2[NepaliMonth2["Ashwin"] = 6] = "Ashwin";
|
|
66
|
+
NepaliMonth2[NepaliMonth2["Kartik"] = 7] = "Kartik";
|
|
67
|
+
NepaliMonth2[NepaliMonth2["Mangsir"] = 8] = "Mangsir";
|
|
68
|
+
NepaliMonth2[NepaliMonth2["Poush"] = 9] = "Poush";
|
|
69
|
+
NepaliMonth2[NepaliMonth2["Magh"] = 10] = "Magh";
|
|
70
|
+
NepaliMonth2[NepaliMonth2["Falgun"] = 11] = "Falgun";
|
|
71
|
+
NepaliMonth2[NepaliMonth2["Chaitra"] = 12] = "Chaitra";
|
|
72
|
+
return NepaliMonth2;
|
|
73
|
+
})(NepaliMonth || {});
|
|
74
|
+
var NEPALI_MONTH_NAMES_EN = {
|
|
75
|
+
1: "Baisakh",
|
|
76
|
+
2: "Jestha",
|
|
77
|
+
3: "Ashar",
|
|
78
|
+
4: "Shrawan",
|
|
79
|
+
5: "Bhadra",
|
|
80
|
+
6: "Ashwin",
|
|
81
|
+
7: "Kartik",
|
|
82
|
+
8: "Mangsir",
|
|
83
|
+
9: "Poush",
|
|
84
|
+
10: "Magh",
|
|
85
|
+
11: "Falgun",
|
|
86
|
+
12: "Chaitra"
|
|
87
|
+
};
|
|
88
|
+
var NEPALI_MONTH_NAMES_NE = {
|
|
89
|
+
1: "\u092C\u0948\u0936\u093E\u0916",
|
|
90
|
+
2: "\u091C\u0947\u0920",
|
|
91
|
+
3: "\u0905\u0938\u093E\u0930",
|
|
92
|
+
4: "\u0936\u094D\u0930\u093E\u0935\u0923",
|
|
93
|
+
5: "\u092D\u093E\u0926\u094D\u0930",
|
|
94
|
+
6: "\u0906\u0936\u094D\u0935\u093F\u0928",
|
|
95
|
+
7: "\u0915\u093E\u0930\u094D\u0924\u093F\u0915",
|
|
96
|
+
8: "\u092E\u0902\u0938\u093F\u0930",
|
|
97
|
+
9: "\u092A\u094C\u0937",
|
|
98
|
+
10: "\u092E\u093E\u0918",
|
|
99
|
+
11: "\u092B\u093E\u0932\u094D\u0917\u0941\u0928",
|
|
100
|
+
12: "\u091A\u0948\u0924\u094D\u0930"
|
|
101
|
+
};
|
|
102
|
+
var ENGLISH_MONTH_NAMES = {
|
|
103
|
+
1: "January",
|
|
104
|
+
2: "February",
|
|
105
|
+
3: "March",
|
|
106
|
+
4: "April",
|
|
107
|
+
5: "May",
|
|
108
|
+
6: "June",
|
|
109
|
+
7: "July",
|
|
110
|
+
8: "August",
|
|
111
|
+
9: "September",
|
|
112
|
+
10: "October",
|
|
113
|
+
11: "November",
|
|
114
|
+
12: "December"
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// data/calendar-data.json
|
|
118
|
+
var calendar_data_default = {
|
|
119
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
120
|
+
description: "Nepali Calendar Data (Bikram Sambat). Each year maps to an array of 12 numbers representing the days in each month. Months: [Baisakh, Jestha, Ashar, Shrawan, Bhadra, Ashwin, Kartik, Mangsir, Poush, Magh, Falgun, Chaitra]. Data Sources: Nepal Panchanga Nirnayak Samiti, verified against historical records. Data Range: BS 2000 - 2100 (AD 1943 - 2043)",
|
|
121
|
+
"2000": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
122
|
+
"2001": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
123
|
+
"2002": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
124
|
+
"2003": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
125
|
+
"2004": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
126
|
+
"2005": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
127
|
+
"2006": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
128
|
+
"2007": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
129
|
+
"2008": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
130
|
+
"2009": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
131
|
+
"2010": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
132
|
+
"2011": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
133
|
+
"2012": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
134
|
+
"2013": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
135
|
+
"2014": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
136
|
+
"2015": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
137
|
+
"2016": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
138
|
+
"2017": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
139
|
+
"2018": [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
140
|
+
"2019": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
141
|
+
"2020": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
142
|
+
"2021": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
143
|
+
"2022": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
144
|
+
"2023": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
145
|
+
"2024": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
146
|
+
"2025": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
147
|
+
"2026": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
148
|
+
"2027": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
149
|
+
"2028": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
150
|
+
"2029": [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
151
|
+
"2030": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
152
|
+
"2031": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
153
|
+
"2032": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
154
|
+
"2033": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
155
|
+
"2034": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
156
|
+
"2035": [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
157
|
+
"2036": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
158
|
+
"2037": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
159
|
+
"2038": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
160
|
+
"2039": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
161
|
+
"2040": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
162
|
+
"2041": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
163
|
+
"2042": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
164
|
+
"2043": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
165
|
+
"2044": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
166
|
+
"2045": [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
167
|
+
"2046": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
168
|
+
"2047": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
169
|
+
"2048": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
170
|
+
"2049": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
171
|
+
"2050": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
172
|
+
"2051": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
173
|
+
"2052": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
174
|
+
"2053": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
175
|
+
"2054": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
176
|
+
"2055": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
177
|
+
"2056": [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
|
|
178
|
+
"2057": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
179
|
+
"2058": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
180
|
+
"2059": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
181
|
+
"2060": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
182
|
+
"2061": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
183
|
+
"2062": [30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
|
|
184
|
+
"2063": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
185
|
+
"2064": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
186
|
+
"2065": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
187
|
+
"2066": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
|
|
188
|
+
"2067": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
189
|
+
"2068": [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
190
|
+
"2069": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
191
|
+
"2070": [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
|
|
192
|
+
"2071": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
193
|
+
"2072": [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
194
|
+
"2073": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
|
|
195
|
+
"2074": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
196
|
+
"2075": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
197
|
+
"2076": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
198
|
+
"2077": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
|
|
199
|
+
"2078": [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
200
|
+
"2079": [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
|
|
201
|
+
"2080": [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
|
|
202
|
+
"2081": [31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
203
|
+
"2082": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
204
|
+
"2083": [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
205
|
+
"2084": [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
206
|
+
"2085": [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
207
|
+
"2086": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
208
|
+
"2087": [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
209
|
+
"2088": [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
|
|
210
|
+
"2089": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
211
|
+
"2090": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
212
|
+
"2091": [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
|
|
213
|
+
"2092": [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
214
|
+
"2093": [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
215
|
+
"2094": [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
216
|
+
"2095": [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],
|
|
217
|
+
"2096": [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
|
|
218
|
+
"2097": [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
|
|
219
|
+
"2098": [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31],
|
|
220
|
+
"2099": [31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30],
|
|
221
|
+
"2100": [31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/data/calendar-data.ts
|
|
225
|
+
var NEPALI_CALENDAR_DATA = Object.fromEntries(
|
|
226
|
+
Object.entries(calendar_data_default).filter(([key]) => !key.startsWith("$") && key !== "description").map(([key, value]) => [Number(key), value])
|
|
227
|
+
);
|
|
228
|
+
var MIN_YEAR = Math.min(...Object.keys(NEPALI_CALENDAR_DATA).map(Number));
|
|
229
|
+
var MAX_YEAR = Math.max(...Object.keys(NEPALI_CALENDAR_DATA).map(Number));
|
|
230
|
+
|
|
231
|
+
// data/reference-dates.json
|
|
232
|
+
var reference_dates_default = {
|
|
233
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
234
|
+
description: "Reference date pairs for validation and testing. These are verified BS-AD date pairs used to validate conversion accuracy. Each pair represents a known accurate conversion point. Sources: Official Nepal government publications, historical records and verified events, cross-referenced with multiple calendar systems.",
|
|
235
|
+
referenceDates: [
|
|
236
|
+
{
|
|
237
|
+
bs: { year: 2001, month: 1, day: 1 },
|
|
238
|
+
ad: { year: 1944, month: 4, day: 13 }
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
bs: { year: 2010, month: 1, day: 1 },
|
|
242
|
+
ad: { year: 1953, month: 4, day: 13 }
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
bs: { year: 2015, month: 1, day: 1 },
|
|
246
|
+
ad: { year: 1958, month: 4, day: 13 }
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
bs: { year: 2025, month: 1, day: 1 },
|
|
250
|
+
ad: { year: 1968, month: 4, day: 13 }
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
bs: { year: 2035, month: 1, day: 1 },
|
|
254
|
+
ad: { year: 1978, month: 4, day: 14 }
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
bs: { year: 2045, month: 1, day: 1 },
|
|
258
|
+
ad: { year: 1988, month: 4, day: 13 }
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
bs: { year: 2055, month: 1, day: 1 },
|
|
262
|
+
ad: { year: 1998, month: 4, day: 14 }
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
bs: { year: 2065, month: 1, day: 1 },
|
|
266
|
+
ad: { year: 2008, month: 4, day: 13 }
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
bs: { year: 2075, month: 1, day: 1 },
|
|
270
|
+
ad: { year: 2018, month: 4, day: 14 }
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
bs: { year: 2082, month: 1, day: 1 },
|
|
274
|
+
ad: { year: 2025, month: 4, day: 14 }
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
bs: { year: 2083, month: 1, day: 1 },
|
|
278
|
+
ad: { year: 2026, month: 4, day: 14 }
|
|
279
|
+
}
|
|
280
|
+
]
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
// src/data/reference-dates.ts
|
|
284
|
+
var BASE_BS_DATE = { year: 2e3, month: 1, day: 1 };
|
|
285
|
+
var BASE_AD_DATE = { year: 1943, month: 4, day: 14 };
|
|
286
|
+
var REFERENCE_DATES = reference_dates_default.referenceDates.map(
|
|
287
|
+
({ bs, ad }) => ({ bs, ad })
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
// src/utils/validators.ts
|
|
291
|
+
function hasDataForYear(year) {
|
|
292
|
+
return year in NEPALI_CALENDAR_DATA;
|
|
293
|
+
}
|
|
294
|
+
function isValidBsDate(year, month, day) {
|
|
295
|
+
if (year < MIN_YEAR || year > MAX_YEAR) {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
if (!hasDataForYear(year)) {
|
|
299
|
+
return false;
|
|
300
|
+
}
|
|
301
|
+
if (month < 1 || month > 12) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
const daysInMonth = NEPALI_CALENDAR_DATA[year][month - 1];
|
|
305
|
+
if (day < 1 || day > daysInMonth) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
function isValidAdDate(year, month, day) {
|
|
311
|
+
if (year < 1 || year > 9999) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (month < 1 || month > 12) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
318
|
+
if (month === 2 && isLeapYear(year)) {
|
|
319
|
+
daysInMonth[1] = 29;
|
|
320
|
+
}
|
|
321
|
+
if (day < 1 || day > daysInMonth[month - 1]) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
function isLeapYear(year) {
|
|
327
|
+
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
328
|
+
}
|
|
329
|
+
function getDaysInAdMonth(year, month) {
|
|
330
|
+
const daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
331
|
+
if (month === 2 && isLeapYear(year)) {
|
|
332
|
+
return 29;
|
|
333
|
+
}
|
|
334
|
+
return daysInMonth[month - 1];
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
// src/converters/bs-to-ad.ts
|
|
338
|
+
function bsToAd(year, month, day, options) {
|
|
339
|
+
if (!isValidBsDate(year, month, day)) {
|
|
340
|
+
throw new Error(`Invalid BS date: ${year}-${month}-${day}`);
|
|
341
|
+
}
|
|
342
|
+
let totalDays = 0;
|
|
343
|
+
for (let y = BASE_BS_DATE.year; y < year; y++) {
|
|
344
|
+
if (y in NEPALI_CALENDAR_DATA) {
|
|
345
|
+
totalDays += NEPALI_CALENDAR_DATA[y].reduce((sum, days) => sum + days, 0);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
for (let m = 0; m < month - 1; m++) {
|
|
349
|
+
totalDays += NEPALI_CALENDAR_DATA[year][m];
|
|
350
|
+
}
|
|
351
|
+
totalDays += day - 1;
|
|
352
|
+
const adDate = addDaysToAdDate(
|
|
353
|
+
BASE_AD_DATE.year,
|
|
354
|
+
BASE_AD_DATE.month,
|
|
355
|
+
BASE_AD_DATE.day,
|
|
356
|
+
totalDays
|
|
357
|
+
);
|
|
358
|
+
return formatDate(adDate, options);
|
|
359
|
+
}
|
|
360
|
+
function addDaysToAdDate(year, month, day, daysToAdd) {
|
|
361
|
+
let y = year;
|
|
362
|
+
let m = month;
|
|
363
|
+
let d = day;
|
|
364
|
+
for (let i = 0; i < daysToAdd; i++) {
|
|
365
|
+
d++;
|
|
366
|
+
const daysInCurrentMonth = getDaysInAdMonth(y, m);
|
|
367
|
+
if (d > daysInCurrentMonth) {
|
|
368
|
+
d = 1;
|
|
369
|
+
m++;
|
|
370
|
+
if (m > 12) {
|
|
371
|
+
m = 1;
|
|
372
|
+
y++;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return { year: y, month: m, day: d };
|
|
377
|
+
}
|
|
378
|
+
function formatDate(date, options) {
|
|
379
|
+
const format = options?.format || "object";
|
|
380
|
+
switch (format) {
|
|
381
|
+
case "object":
|
|
382
|
+
return date;
|
|
383
|
+
case "iso":
|
|
384
|
+
return `${date.year}-${String(date.month).padStart(2, "0")}-${String(date.day).padStart(2, "0")}`;
|
|
385
|
+
case "string": {
|
|
386
|
+
const pattern = options?.pattern || "YYYY-MM-DD";
|
|
387
|
+
return pattern.replace("YYYY", String(date.year)).replace("MM", String(date.month).padStart(2, "0")).replace("DD", String(date.day).padStart(2, "0"));
|
|
388
|
+
}
|
|
389
|
+
case "array":
|
|
390
|
+
return [date.year, date.month, date.day];
|
|
391
|
+
default:
|
|
392
|
+
return date;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/converters/ad-to-bs.ts
|
|
397
|
+
function adToBs(year, month, day, options) {
|
|
398
|
+
if (!isValidAdDate(year, month, day)) {
|
|
399
|
+
throw new Error(`Invalid AD date: ${year}-${month}-${day}`);
|
|
400
|
+
}
|
|
401
|
+
const totalDaysFromBase = calculateDaysBetweenAdDates(
|
|
402
|
+
BASE_AD_DATE.year,
|
|
403
|
+
BASE_AD_DATE.month,
|
|
404
|
+
BASE_AD_DATE.day,
|
|
405
|
+
year,
|
|
406
|
+
month,
|
|
407
|
+
day
|
|
408
|
+
);
|
|
409
|
+
if (totalDaysFromBase < 0) {
|
|
410
|
+
throw new Error(`Date is before the minimum supported date (${BASE_AD_DATE.year}-${BASE_AD_DATE.month}-${BASE_AD_DATE.day})`);
|
|
411
|
+
}
|
|
412
|
+
const bsDate = addDaysToBsDate(
|
|
413
|
+
BASE_BS_DATE.year,
|
|
414
|
+
BASE_BS_DATE.month,
|
|
415
|
+
BASE_BS_DATE.day,
|
|
416
|
+
totalDaysFromBase
|
|
417
|
+
);
|
|
418
|
+
return formatDate2(bsDate, options);
|
|
419
|
+
}
|
|
420
|
+
function calculateDaysBetweenAdDates(fromYear, fromMonth, fromDay, toYear, toMonth, toDay) {
|
|
421
|
+
let days = 0;
|
|
422
|
+
if (toYear < fromYear || toYear === fromYear && toMonth < fromMonth || toYear === fromYear && toMonth === fromMonth && toDay < fromDay) {
|
|
423
|
+
return -1;
|
|
424
|
+
}
|
|
425
|
+
let y = fromYear;
|
|
426
|
+
let m = fromMonth;
|
|
427
|
+
let d = fromDay;
|
|
428
|
+
while (y !== toYear || m !== toMonth || d !== toDay) {
|
|
429
|
+
d++;
|
|
430
|
+
const daysInMonth = getDaysInAdMonth(y, m);
|
|
431
|
+
if (d > daysInMonth) {
|
|
432
|
+
d = 1;
|
|
433
|
+
m++;
|
|
434
|
+
if (m > 12) {
|
|
435
|
+
m = 1;
|
|
436
|
+
y++;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
days++;
|
|
440
|
+
}
|
|
441
|
+
return days;
|
|
442
|
+
}
|
|
443
|
+
function addDaysToBsDate(year, month, day, daysToAdd) {
|
|
444
|
+
let y = year;
|
|
445
|
+
let m = month;
|
|
446
|
+
let d = day;
|
|
447
|
+
for (let i = 0; i < daysToAdd; i++) {
|
|
448
|
+
d++;
|
|
449
|
+
const daysInCurrentMonth = NEPALI_CALENDAR_DATA[y][m - 1];
|
|
450
|
+
if (d > daysInCurrentMonth) {
|
|
451
|
+
d = 1;
|
|
452
|
+
m++;
|
|
453
|
+
if (m > 12) {
|
|
454
|
+
m = 1;
|
|
455
|
+
y++;
|
|
456
|
+
}
|
|
457
|
+
if (y > MAX_YEAR) {
|
|
458
|
+
throw new Error(`Date exceeds maximum supported year (BS ${MAX_YEAR})`);
|
|
459
|
+
}
|
|
460
|
+
if (!(y in NEPALI_CALENDAR_DATA)) {
|
|
461
|
+
throw new Error(`No calendar data available for BS year ${y}`);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return { year: y, month: m, day: d };
|
|
466
|
+
}
|
|
467
|
+
function formatDate2(date, options) {
|
|
468
|
+
const format = options?.format || "object";
|
|
469
|
+
switch (format) {
|
|
470
|
+
case "object":
|
|
471
|
+
return date;
|
|
472
|
+
case "iso":
|
|
473
|
+
return `${date.year}-${String(date.month).padStart(2, "0")}-${String(date.day).padStart(2, "0")}`;
|
|
474
|
+
case "string": {
|
|
475
|
+
const pattern = options?.pattern || "YYYY-MM-DD";
|
|
476
|
+
return pattern.replace("YYYY", String(date.year)).replace("MM", String(date.month).padStart(2, "0")).replace("DD", String(date.day).padStart(2, "0"));
|
|
477
|
+
}
|
|
478
|
+
case "array":
|
|
479
|
+
return [date.year, date.month, date.day];
|
|
480
|
+
default:
|
|
481
|
+
return date;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// src/utils/date-helpers.ts
|
|
486
|
+
function getTotalDaysInMonth(year, month) {
|
|
487
|
+
if (!hasDataForYear(year)) {
|
|
488
|
+
throw new Error(`No data available for year ${year}`);
|
|
489
|
+
}
|
|
490
|
+
if (month < 1 || month > 12) {
|
|
491
|
+
throw new Error(`Invalid month: ${month}. Month must be between 1 and 12.`);
|
|
492
|
+
}
|
|
493
|
+
return NEPALI_CALENDAR_DATA[year][month - 1];
|
|
494
|
+
}
|
|
495
|
+
function getTotalDaysInYear(year) {
|
|
496
|
+
if (!hasDataForYear(year)) {
|
|
497
|
+
throw new Error(`No data available for year ${year}`);
|
|
498
|
+
}
|
|
499
|
+
return NEPALI_CALENDAR_DATA[year].reduce((sum, days) => sum + days, 0);
|
|
500
|
+
}
|
|
501
|
+
function getNextMonth(year, month) {
|
|
502
|
+
if (month < 1 || month > 12) {
|
|
503
|
+
throw new Error(`Invalid month: ${month}. Month must be between 1 and 12.`);
|
|
504
|
+
}
|
|
505
|
+
if (month === 12) {
|
|
506
|
+
const nextYear = year + 1;
|
|
507
|
+
if (!hasDataForYear(nextYear)) {
|
|
508
|
+
throw new Error(`No data available for year ${nextYear}`);
|
|
509
|
+
}
|
|
510
|
+
return { year: nextYear, month: 1 };
|
|
511
|
+
}
|
|
512
|
+
return { year, month: month + 1 };
|
|
513
|
+
}
|
|
514
|
+
function getPrevMonth(year, month) {
|
|
515
|
+
if (month < 1 || month > 12) {
|
|
516
|
+
throw new Error(`Invalid month: ${month}. Month must be between 1 and 12.`);
|
|
517
|
+
}
|
|
518
|
+
if (month === 1) {
|
|
519
|
+
const prevYear = year - 1;
|
|
520
|
+
if (!hasDataForYear(prevYear)) {
|
|
521
|
+
throw new Error(`No data available for year ${prevYear}`);
|
|
522
|
+
}
|
|
523
|
+
return { year: prevYear, month: 12 };
|
|
524
|
+
}
|
|
525
|
+
return { year, month: month - 1 };
|
|
526
|
+
}
|
|
527
|
+
function getCalendarData(year) {
|
|
528
|
+
if (!hasDataForYear(year)) {
|
|
529
|
+
throw new Error(`No data available for year ${year}`);
|
|
530
|
+
}
|
|
531
|
+
return [...NEPALI_CALENDAR_DATA[year]];
|
|
532
|
+
}
|
|
533
|
+
function getDataRange() {
|
|
534
|
+
return {
|
|
535
|
+
minYear: MIN_YEAR,
|
|
536
|
+
maxYear: MAX_YEAR,
|
|
537
|
+
totalYears: MAX_YEAR - MIN_YEAR + 1
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function getDaysInRange(fromYear, fromMonth, fromDay, toYear, toMonth, toDay) {
|
|
541
|
+
if (!hasDataForYear(fromYear) || !hasDataForYear(toYear)) {
|
|
542
|
+
throw new Error("One or more years are outside the available data range");
|
|
543
|
+
}
|
|
544
|
+
let days = 0;
|
|
545
|
+
let currentYear = fromYear;
|
|
546
|
+
let currentMonth = fromMonth;
|
|
547
|
+
let currentDay = fromDay;
|
|
548
|
+
const isForward = toYear > fromYear || toYear === fromYear && toMonth > fromMonth || toYear === fromYear && toMonth === fromMonth && toDay >= fromDay;
|
|
549
|
+
if (!isForward) {
|
|
550
|
+
while (currentYear > toYear || currentMonth > toMonth || currentDay > toDay) {
|
|
551
|
+
currentDay--;
|
|
552
|
+
days--;
|
|
553
|
+
if (currentDay < 1) {
|
|
554
|
+
const prevMonth = getPrevMonth(currentYear, currentMonth);
|
|
555
|
+
currentYear = prevMonth.year;
|
|
556
|
+
currentMonth = prevMonth.month;
|
|
557
|
+
currentDay = getTotalDaysInMonth(currentYear, currentMonth);
|
|
558
|
+
}
|
|
559
|
+
if (currentYear === toYear && currentMonth === toMonth && currentDay === toDay) {
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
} else {
|
|
564
|
+
while (currentYear < toYear || currentMonth < toMonth || currentDay < toDay) {
|
|
565
|
+
currentDay++;
|
|
566
|
+
days++;
|
|
567
|
+
const daysInMonth = getTotalDaysInMonth(currentYear, currentMonth);
|
|
568
|
+
if (currentDay > daysInMonth) {
|
|
569
|
+
const nextMonth = getNextMonth(currentYear, currentMonth);
|
|
570
|
+
currentYear = nextMonth.year;
|
|
571
|
+
currentMonth = nextMonth.month;
|
|
572
|
+
currentDay = 1;
|
|
573
|
+
}
|
|
574
|
+
if (currentYear === toYear && currentMonth === toMonth && currentDay === toDay) {
|
|
575
|
+
break;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
return days;
|
|
580
|
+
}
|
|
581
|
+
function getAllCalendarData() {
|
|
582
|
+
return { ...NEPALI_CALENDAR_DATA };
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/utils/formatters.ts
|
|
586
|
+
function formatBsDate(year, month, day, options) {
|
|
587
|
+
const pattern = options?.pattern || "YYYY-MM-DD";
|
|
588
|
+
return formatWithPattern(year, month, day, pattern);
|
|
589
|
+
}
|
|
590
|
+
function formatAdDate(year, month, day, options) {
|
|
591
|
+
const pattern = options?.pattern || "YYYY-MM-DD";
|
|
592
|
+
return formatWithPattern(year, month, day, pattern);
|
|
593
|
+
}
|
|
594
|
+
function formatWithPattern(year, month, day, pattern) {
|
|
595
|
+
return pattern.replace("YYYY", String(year)).replace("MM", String(month).padStart(2, "0")).replace("DD", String(day).padStart(2, "0"));
|
|
596
|
+
}
|
|
597
|
+
function getNepaliMonthName(month, locale = "en") {
|
|
598
|
+
if (month < 1 || month > 12) {
|
|
599
|
+
throw new Error(`Invalid month: ${month}. Month must be between 1 and 12.`);
|
|
600
|
+
}
|
|
601
|
+
if (locale === "ne") {
|
|
602
|
+
return NEPALI_MONTH_NAMES_NE[month];
|
|
603
|
+
}
|
|
604
|
+
return NEPALI_MONTH_NAMES_EN[month];
|
|
605
|
+
}
|
|
606
|
+
function getEnglishMonthName(month) {
|
|
607
|
+
if (month < 1 || month > 12) {
|
|
608
|
+
throw new Error(`Invalid month: ${month}. Month must be between 1 and 12.`);
|
|
609
|
+
}
|
|
610
|
+
return ENGLISH_MONTH_NAMES[month];
|
|
611
|
+
}
|
|
612
|
+
function parseDate(dateString, pattern = "YYYY-MM-DD") {
|
|
613
|
+
const separator = pattern.includes("-") ? "-" : "/";
|
|
614
|
+
const parts = dateString.split(separator);
|
|
615
|
+
if (parts.length !== 3) {
|
|
616
|
+
throw new Error(`Invalid date string: ${dateString}`);
|
|
617
|
+
}
|
|
618
|
+
const patternParts = pattern.split(separator);
|
|
619
|
+
const dateObj = { year: 0, month: 0, day: 0 };
|
|
620
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
621
|
+
const value = parseInt(parts[i], 10);
|
|
622
|
+
if (isNaN(value)) {
|
|
623
|
+
throw new Error(`Invalid date value in: ${dateString}`);
|
|
624
|
+
}
|
|
625
|
+
switch (patternParts[i]) {
|
|
626
|
+
case "YYYY":
|
|
627
|
+
dateObj.year = value;
|
|
628
|
+
break;
|
|
629
|
+
case "MM":
|
|
630
|
+
dateObj.month = value;
|
|
631
|
+
break;
|
|
632
|
+
case "DD":
|
|
633
|
+
dateObj.day = value;
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
if (dateObj.year === 0 || dateObj.month === 0 || dateObj.day === 0) {
|
|
638
|
+
throw new Error(`Failed to parse date: ${dateString}`);
|
|
639
|
+
}
|
|
640
|
+
return dateObj;
|
|
641
|
+
}
|
|
642
|
+
function toIsoString(date) {
|
|
643
|
+
return `${date.year}-${String(date.month).padStart(2, "0")}-${String(date.day).padStart(2, "0")}`;
|
|
644
|
+
}
|
|
645
|
+
function toArray(date) {
|
|
646
|
+
return [date.year, date.month, date.day];
|
|
647
|
+
}
|
|
648
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
649
|
+
0 && (module.exports = {
|
|
650
|
+
BASE_AD_DATE,
|
|
651
|
+
BASE_BS_DATE,
|
|
652
|
+
ENGLISH_MONTH_NAMES,
|
|
653
|
+
MAX_YEAR,
|
|
654
|
+
MIN_YEAR,
|
|
655
|
+
NEPALI_CALENDAR_DATA,
|
|
656
|
+
NEPALI_MONTH_NAMES_EN,
|
|
657
|
+
NEPALI_MONTH_NAMES_NE,
|
|
658
|
+
NepaliMonth,
|
|
659
|
+
REFERENCE_DATES,
|
|
660
|
+
adToBs,
|
|
661
|
+
bsToAd,
|
|
662
|
+
formatAdDate,
|
|
663
|
+
formatBsDate,
|
|
664
|
+
getAllCalendarData,
|
|
665
|
+
getCalendarData,
|
|
666
|
+
getDataRange,
|
|
667
|
+
getDaysInAdMonth,
|
|
668
|
+
getDaysInRange,
|
|
669
|
+
getEnglishMonthName,
|
|
670
|
+
getNepaliMonthName,
|
|
671
|
+
getNextMonth,
|
|
672
|
+
getPrevMonth,
|
|
673
|
+
getTotalDaysInMonth,
|
|
674
|
+
getTotalDaysInYear,
|
|
675
|
+
hasDataForYear,
|
|
676
|
+
isLeapYear,
|
|
677
|
+
isValidAdDate,
|
|
678
|
+
isValidBsDate,
|
|
679
|
+
parseDate,
|
|
680
|
+
toArray,
|
|
681
|
+
toIsoString
|
|
682
|
+
});
|