UNPKG

14.6 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const dateAdd = require("date-fns/add_days");
4const dateCompare = require("date-fns/compare_asc");
5const dateDiff = require("date-fns/difference_in_calendar_days");
6const AstaWara_1 = require("./AstaWara");
7exports.AstaWara = AstaWara_1.AstaWara;
8const BalineseDateUtil_1 = require("./BalineseDateUtil");
9exports.BalineseDateUtil = BalineseDateUtil_1.BalineseDateUtil;
10const CaturWara_1 = require("./CaturWara");
11exports.CaturWara = CaturWara_1.CaturWara;
12const DasaWara_1 = require("./DasaWara");
13exports.DasaWara = DasaWara_1.DasaWara;
14const DwiWara_1 = require("./DwiWara");
15exports.DwiWara = DwiWara_1.DwiWara;
16const EkaJalaRsi_1 = require("./EkaJalaRsi");
17exports.EkaJalaRsi = EkaJalaRsi_1.EkaJalaRsi;
18const EkaWara_1 = require("./EkaWara");
19exports.EkaWara = EkaWara_1.EkaWara;
20const Filter_1 = require("./Filter");
21exports.Filter = Filter_1.Filter;
22const Ingkel_1 = require("./Ingkel");
23exports.Ingkel = Ingkel_1.Ingkel;
24const Pivot_1 = require("./internal/Pivot");
25const Jejepan_1 = require("./Jejepan");
26exports.Jejepan = Jejepan_1.Jejepan;
27const Lintang_1 = require("./Lintang");
28exports.Lintang = Lintang_1.Lintang;
29const PancaSuda_1 = require("./PancaSuda");
30exports.PancaSuda = PancaSuda_1.PancaSuda;
31const PancaWara_1 = require("./PancaWara");
32exports.PancaWara = PancaWara_1.PancaWara;
33const Pararasan_1 = require("./Pararasan");
34exports.Pararasan = Pararasan_1.Pararasan;
35const PratithiSamutPada_1 = require("./PratithiSamutPada");
36exports.PratithiSamutPada = PratithiSamutPada_1.PratithiSamutPada;
37const Rahinan_1 = require("./Rahinan");
38exports.Rahinan = Rahinan_1.Rahinan;
39const Rakam_1 = require("./Rakam");
40exports.Rakam = Rakam_1.Rakam;
41const SadWara_1 = require("./SadWara");
42exports.SadWara = SadWara_1.SadWara;
43const SangaWara_1 = require("./SangaWara");
44exports.SangaWara = SangaWara_1.SangaWara;
45const SaptaWara_1 = require("./SaptaWara");
46exports.SaptaWara = SaptaWara_1.SaptaWara;
47const Sasih_1 = require("./Sasih");
48exports.Sasih = Sasih_1.Sasih;
49const SasihDayInfo_1 = require("./SasihDayInfo");
50exports.SasihDayInfo = SasihDayInfo_1.SasihDayInfo;
51const TriWara_1 = require("./TriWara");
52exports.TriWara = TriWara_1.TriWara;
53const WatekAlit_1 = require("./WatekAlit");
54exports.WatekAlit = WatekAlit_1.WatekAlit;
55const WatekMadya_1 = require("./WatekMadya");
56exports.WatekMadya = WatekMadya_1.WatekMadya;
57const Wuku_1 = require("./Wuku");
58exports.Wuku = Wuku_1.Wuku;
59class BalineseDate {
60 constructor(date = new Date()) {
61 this.date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
62 Object.freeze(this.date);
63 const pivot = _F_BEST_PIVOT(this.date);
64 const pawukonDay = _F_PAWUKON_DAY(pivot, this.date);
65 this.wuku = Wuku_1.Wuku.values[Math.floor(pawukonDay / 7)];
66 this.triWara = TriWara_1.TriWara.values[pawukonDay % 3];
67 this.pancaWara = PancaWara_1.PancaWara.values[pawukonDay % 5];
68 this.sadWara = SadWara_1.SadWara.values[pawukonDay % 6];
69 this.saptaWara = SaptaWara_1.SaptaWara.values[pawukonDay % 7];
70 this.jejepan = Jejepan_1.Jejepan.values[pawukonDay % 6];
71 this.lintang = Lintang_1.Lintang.values[pawukonDay % 35];
72 this.pancaSuda = PancaSuda_1.PancaSuda.values[(this.saptaWara.kertaAji + this.pancaWara.urip) % 7];
73 this.rakam = Rakam_1.Rakam.values[(this.saptaWara.kupih + this.pancaWara.kupih) % 6];
74 this.ekaJalaRsi = EkaJalaRsi_1.EkaJalaRsi.values[_C_EJR_MAP[pawukonDay]];
75 this.ingkel = Ingkel_1.Ingkel.values[this.wuku.id % 6];
76 const urip = this.pancaWara.urip + this.saptaWara.urip;
77 this.ekaWara = EkaWara_1.EkaWara.values[urip % 2];
78 this.dwiWara = DwiWara_1.DwiWara.values[urip % 2];
79 this.dasaWara = DasaWara_1.DasaWara.values[urip % 10];
80 this.watekAlit = WatekAlit_1.WatekAlit.values[urip % 4];
81 this.watekMadya = WatekMadya_1.WatekMadya.values[urip % 5];
82 this.pararasan = Pararasan_1.Pararasan.values[urip % 10];
83 this.caturWara = _F_CALC_CATURWARA(pawukonDay);
84 this.astaWara = _F_CALC_ASTAWARA(pawukonDay);
85 this.sangaWara = _F_CALC_SANGAWARA(pawukonDay);
86 const resSasih = _F_CALC_SASIH_INFO(pivot, this.date);
87 const resSasihDay = _F_CALC_SASIH_DAY(pivot, this.date);
88 this.saka = resSasih[0];
89 this.sasih = _F_CALC_SASIH(resSasih);
90 this.sasihDayInfo = _F_CALC_SASIH_DAY_INFO(resSasihDay, this.sasih, this.saka);
91 if (resSasihDay[2] === 1) {
92 this.sasihDay = [resSasihDay[0], ((resSasihDay[0] === 15) ? 1 : resSasihDay[0] + 1)];
93 }
94 else {
95 this.sasihDay = [resSasihDay[0]];
96 }
97 Object.freeze(this.sasihDay);
98 this.pratithiSamutPada = _F_CALC_PRATITHI_S_P(this.sasihDay, this.sasihDayInfo, this.sasih, this.date);
99 Object.freeze(this);
100 }
101}
102exports.BalineseDate = BalineseDate;
103const _C_DAY_PAWUKON = 210;
104const _C_DAY_NGUNARATRI = 63;
105const _C_PANGALANTAKA_PAING = new Date(2000, 0, 6);
106Object.freeze(_C_PANGALANTAKA_PAING);
107const _C_SK_START = new Date(1993, 0, 24);
108Object.freeze(_C_SK_START);
109const _C_SK_END = new Date(2003, 0, 3);
110Object.freeze(_C_SK_END);
111const _C_EJR_MAP = Object.freeze([23, 7, 17, 7, 23, 23, 17, 9, 7, 13, 26, 24, 23, 20, 13, 7, 13, 25, 19, 6, 2,
112 14, 26, 17, 20, 25, 22, 0, 10, 6, 15, 23, 7, 17, 23, 17, 25, 5, 23, 2, 2, 2, 12, 12, 5, 14, 12, 26, 26, 1,
113 23, 23, 15, 25, 15, 6, 9, 25, 18, 25, 11, 15, 21, 25, 25, 12, 0, 17, 13, 0, 15, 23, 12, 7, 16, 25, 18, 24,
114 12, 12, 6, 7, 6, 26, 7, 6, 12, 7, 25, 2, 12, 25, 25, 14, 15, 26, 7, 12, 20, 7, 6, 25, 25, 6, 13, 25, 17, 13,
115 23, 6, 26, 20, 25, 25, 23, 7, 18, 18, 17, 7, 17, 7, 5, 26, 17, 6, 9, 12, 12, 13, 25, 18, 18, 6, 2, 25, 25,
116 2, 25, 17, 20, 14, 27, 23, 17, 8, 25, 17, 6, 17, 7, 3, 15, 18, 25, 2, 7, 13, 25, 20, 7, 15, 15, 23, 7, 8,
117 24, 2, 12, 9, 24, 24, 17, 24, 20, 7, 12, 12, 14, 18, 25, 20, 5, 18, 5, 20, 26, 12, 23, 18, 17, 17, 25, 15,
118 2, 24, 4, 2, 23, 25, 18, 25, 20, 14, 4, 2, 25, 7, 25, 17]);
119const _F_MOD = (a, b) => ((a % b) + b) % b;
120const _F_DELTA_D = (a, b) => dateDiff(b, a);
121const _F_BEST_PIVOT = (date) => {
122 return dateCompare(date, _C_PANGALANTAKA_PAING) < 0 ? Pivot_1.Pivot.PIVOT_1971 : Pivot_1.Pivot.PIVOT_2000;
123};
124const _F_PAWUKON_DAY = (pivot, date) => {
125 return _F_MOD(pivot.pawukonDay + _F_DELTA_D(pivot.date, date), _C_DAY_PAWUKON);
126};
127const _F_CALC_CATURWARA = (pawukonDay) => {
128 if (pawukonDay < 71) {
129 return CaturWara_1.CaturWara.values[pawukonDay % 4];
130 }
131 else if (pawukonDay > 72) {
132 return CaturWara_1.CaturWara.values[(pawukonDay - 2) % 4];
133 }
134 else {
135 return CaturWara_1.CaturWara.JAYA;
136 }
137};
138const _F_CALC_ASTAWARA = (pawukonDay) => {
139 if (pawukonDay < 71) {
140 return AstaWara_1.AstaWara.values[pawukonDay % 8];
141 }
142 else if (pawukonDay > 72) {
143 return AstaWara_1.AstaWara.values[(pawukonDay - 2) % 8];
144 }
145 else {
146 return AstaWara_1.AstaWara.KALA;
147 }
148};
149const _F_CALC_SANGAWARA = (pawukonDay) => {
150 if (pawukonDay > 3) {
151 return SangaWara_1.SangaWara.values[(pawukonDay - 3) % 9];
152 }
153 else {
154 return SangaWara_1.SangaWara.DANGU;
155 }
156};
157const _F_CALC_SASIH_INFO = (pivot, date) => {
158 const res = new Array(3);
159 const ptime = pivot.date;
160 const dayDiff = _F_DELTA_D(ptime, date);
161 const daySkip = Math.ceil(dayDiff / _C_DAY_NGUNARATRI);
162 const dayTotal = pivot.sasihDay + dayDiff + daySkip;
163 const pivotOffset = (pivot.sasihDay === 0 && pivot.ngunaRatriDay === 0) ? 0 : 1;
164 let totalSasih = Math.ceil(dayTotal / 30) - pivotOffset;
165 let currentSasih = pivot.sasih.id;
166 let currentSaka = pivot.saka - (currentSasih === Sasih_1.Sasih.KADASA.id ? 1 : 0);
167 let nampihCount = pivot.isNampihSasih ? 1 : 0;
168 let inSK = false;
169 if (dateCompare(ptime, _C_SK_START) >= 0 && dateCompare(ptime, _C_SK_END) < 0) {
170 inSK = true;
171 }
172 while (totalSasih !== 0) {
173 if (dayDiff >= 0) {
174 if (nampihCount === 0 || nampihCount === 2) {
175 nampihCount = 0;
176 currentSasih = _F_MOD(currentSasih + 1, 12);
177 }
178 totalSasih = totalSasih - 1;
179 if (currentSasih === Sasih_1.Sasih.KADASA.id && nampihCount === 0) {
180 currentSaka = currentSaka + 1;
181 }
182 if (currentSasih === Sasih_1.Sasih.KAWOLU.id && currentSaka === 1914) {
183 inSK = true;
184 }
185 else if (currentSasih === Sasih_1.Sasih.KAWOLU.id && currentSaka === 1924) {
186 inSK = false;
187 }
188 }
189 else if (dayDiff < 0) {
190 if (nampihCount === 0 || nampihCount === 2) {
191 nampihCount = 0;
192 currentSasih = _F_MOD(currentSasih - 1, 12);
193 }
194 totalSasih = totalSasih + 1;
195 if (currentSasih === Sasih_1.Sasih.KASANGA.id && nampihCount === 0) {
196 currentSaka = currentSaka - 1;
197 }
198 if (currentSasih === Sasih_1.Sasih.KAPITU.id && currentSaka === 1914) {
199 inSK = false;
200 }
201 else if (currentSasih === Sasih_1.Sasih.KAPITU.id && currentSaka === 1924) {
202 inSK = true;
203 }
204 }
205 switch (currentSaka % 19) {
206 case 0:
207 case 6:
208 case 11:
209 if (currentSasih === Sasih_1.Sasih.DESTHA.id && !inSK) {
210 if (currentSaka !== 1925) {
211 nampihCount++;
212 }
213 }
214 break;
215 case 3:
216 case 8:
217 case 14:
218 case 16:
219 if (currentSasih === Sasih_1.Sasih.SADHA.id && !inSK) {
220 nampihCount++;
221 }
222 break;
223 case 2:
224 case 10:
225 if (currentSasih === Sasih_1.Sasih.DESTHA.id && inSK) {
226 nampihCount++;
227 }
228 break;
229 case 4:
230 if (currentSasih === Sasih_1.Sasih.KATIGA.id && inSK) {
231 nampihCount++;
232 }
233 break;
234 case 7:
235 if (currentSasih === Sasih_1.Sasih.KASA.id && inSK) {
236 nampihCount++;
237 }
238 break;
239 case 13:
240 if (currentSasih === Sasih_1.Sasih.KADASA.id && inSK) {
241 nampihCount++;
242 }
243 break;
244 case 15:
245 if (currentSasih === Sasih_1.Sasih.KARO.id && inSK) {
246 nampihCount++;
247 }
248 break;
249 case 18:
250 if (currentSasih === Sasih_1.Sasih.SADHA.id && inSK) {
251 nampihCount++;
252 }
253 break;
254 default:
255 break;
256 }
257 }
258 res[0] = currentSaka;
259 res[1] = currentSasih;
260 if (dayTotal >= 0) {
261 res[2] = nampihCount === 2 ? 1 : 0;
262 }
263 else {
264 res[2] = nampihCount === 1 ? 1 : 0;
265 }
266 return res;
267};
268const _F_CALC_SASIH_DAY = (pivot, date) => {
269 const res = new Array(3);
270 const ptime = pivot.date;
271 const dayDiff = _F_DELTA_D(ptime, date);
272 const daySkip = Math.ceil(dayDiff / _C_DAY_NGUNARATRI);
273 const dayTotal = pivot.sasihDay + dayDiff + daySkip;
274 res[0] = _F_MOD(dayTotal, 30);
275 res[1] = (res[0] === 0 || res[0] > 15) ? 1 : 0;
276 res[2] = (_F_MOD(dayDiff, _C_DAY_NGUNARATRI) === 0) ? 1 : 0;
277 res[0] = _F_MOD(res[0], 15);
278 res[0] = (res[0] === 0) ? 15 : res[0];
279 return res;
280};
281const _F_CALC_SASIH = (resSasih) => {
282 const saka = resSasih[0];
283 const sasih = resSasih[1];
284 let res = Sasih_1.Sasih.values[sasih];
285 if (resSasih[2] === 1) {
286 if (res === Sasih_1.Sasih.DESTHA) {
287 res = (saka < 1914) ? Sasih_1.Sasih.MALA_DESTHA : Sasih_1.Sasih.NAMPIH_DESTHA;
288 }
289 else if (res === Sasih_1.Sasih.KATIGA) {
290 res = Sasih_1.Sasih.NAMPIH_KATIGA;
291 }
292 else if (res === Sasih_1.Sasih.KASA) {
293 res = Sasih_1.Sasih.NAMPIH_KASA;
294 }
295 else if (res === Sasih_1.Sasih.KADASA) {
296 res = Sasih_1.Sasih.NAMPIH_KADASA;
297 }
298 else if (res === Sasih_1.Sasih.KARO) {
299 res = Sasih_1.Sasih.NAMPIH_KARO;
300 }
301 else if (res === Sasih_1.Sasih.SADHA) {
302 res = (saka < 1914) ? Sasih_1.Sasih.MALA_SADHA : Sasih_1.Sasih.NAMPIH_SADHA;
303 }
304 }
305 return res;
306};
307const _F_CALC_SASIH_DAY_INFO = (resSasihDay, sasih, saka) => {
308 const date = resSasihDay[0];
309 const isPangelong = resSasihDay[1] === 1;
310 const isNgunaRatri = resSasihDay[2] === 1;
311 if (isPangelong) {
312 if (date === 15 || (date === 14 && isNgunaRatri)) {
313 return SasihDayInfo_1.SasihDayInfo.TILEM;
314 }
315 else if (date === 14 && sasih === Sasih_1.Sasih.KAPITU && saka === 1921) {
316 return SasihDayInfo_1.SasihDayInfo.TILEM;
317 }
318 else {
319 return SasihDayInfo_1.SasihDayInfo.PANGELONG;
320 }
321 }
322 else {
323 if (date === 15 || (date === 14 && isNgunaRatri)) {
324 return SasihDayInfo_1.SasihDayInfo.PURNAMA;
325 }
326 else {
327 return SasihDayInfo_1.SasihDayInfo.PENANGGAL;
328 }
329 }
330};
331const _F_CALC_PRATITHI_S_P = (sasihDay, sasihDayInfo, sasih, date) => {
332 let move = 0;
333 const isNG = sasihDay.length > 1;
334 const day = isNG ? sasihDay[1] : sasihDay[0];
335 if (sasihDayInfo.reference === SasihDayInfo_1.SasihDayInfo.PENANGGAL) {
336 if (day === 1 && isNG) {
337 move = 0;
338 }
339 else {
340 if (day >= 1 && day <= 8) {
341 move = day - 1;
342 }
343 else if (day >= 9 && day <= 13) {
344 move = day - 2;
345 }
346 else if (day === 14) {
347 move = 11;
348 }
349 else if (day === 15) {
350 move = 0;
351 }
352 }
353 }
354 else {
355 if (day === 1 && isNG) {
356 const temp = dateAdd(date, 1);
357 const nextDay = new BalineseDate(temp);
358 if (nextDay.sasih.reference !== sasih.reference) {
359 move = -1;
360 }
361 }
362 else {
363 move = (day >= 13) ? day - 11 : day - 1;
364 }
365 }
366 const start = PratithiSamutPada_1.PratithiSamutPada.values[sasih.reference.id];
367 const newID = _F_MOD(start.id - move, 12);
368 return PratithiSamutPada_1.PratithiSamutPada.values[newID];
369};