react-native-bikram-sambat 0.1.0 → 0.1.2

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.
Files changed (156) hide show
  1. package/README.md +24 -253
  2. package/docs/screenshots/iphone-15-pro-max-calendar.png +0 -0
  3. package/lib/commonjs/accessibility/index.js +1 -1
  4. package/lib/commonjs/accessibility/labels.js +2 -2
  5. package/lib/commonjs/accessibility/labels.js.map +1 -1
  6. package/lib/commonjs/calendar/get-calendar-month-grid.js +5 -5
  7. package/lib/commonjs/calendar/index.js +1 -1
  8. package/lib/commonjs/components/NepaliCalendar/CalendarDay.js +2 -2
  9. package/lib/commonjs/components/NepaliCalendar/CalendarDay.js.map +1 -1
  10. package/lib/commonjs/components/NepaliCalendar/CalendarGrid.js +5 -5
  11. package/lib/commonjs/components/NepaliCalendar/CalendarGrid.js.map +1 -1
  12. package/lib/commonjs/components/NepaliCalendar/CalendarHeader.js +8 -8
  13. package/lib/commonjs/components/NepaliCalendar/CalendarHeader.js.map +1 -1
  14. package/lib/commonjs/components/NepaliCalendar/NepaliCalendar.js +37 -37
  15. package/lib/commonjs/components/NepaliCalendar/NepaliCalendar.js.map +1 -1
  16. package/lib/commonjs/components/NepaliCalendar/index.js +1 -1
  17. package/lib/commonjs/components/NepaliDatePicker/DatePickerModal.js +7 -7
  18. package/lib/commonjs/components/NepaliDatePicker/DatePickerModal.js.map +1 -1
  19. package/lib/commonjs/components/NepaliDatePicker/NepaliDatePicker.js +9 -9
  20. package/lib/commonjs/components/NepaliDatePicker/NepaliDatePicker.js.map +1 -1
  21. package/lib/commonjs/components/NepaliDatePicker/index.js +2 -2
  22. package/lib/commonjs/components/NepaliRangePicker/NepaliRangePicker.js +12 -12
  23. package/lib/commonjs/components/NepaliRangePicker/NepaliRangePicker.js.map +1 -1
  24. package/lib/commonjs/components/NepaliRangePicker/RangePickerModal.js +12 -12
  25. package/lib/commonjs/components/NepaliRangePicker/RangePickerModal.js.map +1 -1
  26. package/lib/commonjs/components/NepaliRangePicker/index.js +3 -3
  27. package/lib/commonjs/components/NepaliRangePicker/range-utils.js +7 -7
  28. package/lib/commonjs/components/NepaliRangePicker/range-utils.js.map +1 -1
  29. package/lib/commonjs/core/arithmetic.js +3 -3
  30. package/lib/commonjs/core/bsData.js +1 -1
  31. package/lib/commonjs/core/conversion.js +3 -3
  32. package/lib/commonjs/core/dateKey.js +1 -1
  33. package/lib/commonjs/core/format/format.js +9 -9
  34. package/lib/commonjs/core/format/format.js.map +1 -1
  35. package/lib/commonjs/core/format/index.js +2 -2
  36. package/lib/commonjs/core/format/parse.js +3 -3
  37. package/lib/commonjs/core/format/parse.js.map +1 -1
  38. package/lib/commonjs/core/index.js +19 -19
  39. package/lib/commonjs/core/index.js.map +1 -1
  40. package/lib/commonjs/core/locale/index.js +2 -2
  41. package/lib/commonjs/core/numerals/index.js +1 -1
  42. package/lib/commonjs/core/validation.js +2 -2
  43. package/lib/commonjs/index.js +32 -32
  44. package/lib/commonjs/index.js.map +1 -1
  45. package/lib/commonjs/theme/create-theme.js +1 -1
  46. package/lib/commonjs/theme/index.js +2 -2
  47. package/lib/commonjs/utils/date-helpers.js +4 -4
  48. package/lib/commonjs/utils/date-helpers.js.map +1 -1
  49. package/lib/commonjs/utils/index.js +1 -1
  50. package/lib/module/accessibility/index.js +1 -1
  51. package/lib/module/accessibility/index.js.map +1 -1
  52. package/lib/module/accessibility/labels.js +1 -1
  53. package/lib/module/accessibility/labels.js.map +1 -1
  54. package/lib/module/calendar/get-calendar-month-grid.js +6 -6
  55. package/lib/module/calendar/get-calendar-month-grid.js.map +1 -1
  56. package/lib/module/calendar/index.js +1 -1
  57. package/lib/module/calendar/index.js.map +1 -1
  58. package/lib/module/components/NepaliCalendar/CalendarDay.js +1 -1
  59. package/lib/module/components/NepaliCalendar/CalendarDay.js.map +1 -1
  60. package/lib/module/components/NepaliCalendar/CalendarGrid.js +3 -3
  61. package/lib/module/components/NepaliCalendar/CalendarGrid.js.map +1 -1
  62. package/lib/module/components/NepaliCalendar/CalendarHeader.js +4 -4
  63. package/lib/module/components/NepaliCalendar/CalendarHeader.js.map +1 -1
  64. package/lib/module/components/NepaliCalendar/NepaliCalendar.js +8 -8
  65. package/lib/module/components/NepaliCalendar/NepaliCalendar.js.map +1 -1
  66. package/lib/module/components/NepaliCalendar/index.js +1 -1
  67. package/lib/module/components/NepaliCalendar/index.js.map +1 -1
  68. package/lib/module/components/NepaliDatePicker/DatePickerModal.js +3 -3
  69. package/lib/module/components/NepaliDatePicker/DatePickerModal.js.map +1 -1
  70. package/lib/module/components/NepaliDatePicker/NepaliDatePicker.js +4 -4
  71. package/lib/module/components/NepaliDatePicker/NepaliDatePicker.js.map +1 -1
  72. package/lib/module/components/NepaliDatePicker/index.js +2 -2
  73. package/lib/module/components/NepaliDatePicker/index.js.map +1 -1
  74. package/lib/module/components/NepaliRangePicker/NepaliRangePicker.js +4 -4
  75. package/lib/module/components/NepaliRangePicker/NepaliRangePicker.js.map +1 -1
  76. package/lib/module/components/NepaliRangePicker/RangePickerModal.js +4 -4
  77. package/lib/module/components/NepaliRangePicker/RangePickerModal.js.map +1 -1
  78. package/lib/module/components/NepaliRangePicker/index.js +3 -3
  79. package/lib/module/components/NepaliRangePicker/index.js.map +1 -1
  80. package/lib/module/components/NepaliRangePicker/range-utils.js +1 -1
  81. package/lib/module/components/NepaliRangePicker/range-utils.js.map +1 -1
  82. package/lib/module/core/arithmetic.js +3 -3
  83. package/lib/module/core/arithmetic.js.map +1 -1
  84. package/lib/module/core/bsData.js +1 -1
  85. package/lib/module/core/bsData.js.map +1 -1
  86. package/lib/module/core/conversion.js +3 -3
  87. package/lib/module/core/conversion.js.map +1 -1
  88. package/lib/module/core/dateKey.js +1 -1
  89. package/lib/module/core/dateKey.js.map +1 -1
  90. package/lib/module/core/format/format.js +6 -6
  91. package/lib/module/core/format/format.js.map +1 -1
  92. package/lib/module/core/format/index.js +2 -2
  93. package/lib/module/core/format/index.js.map +1 -1
  94. package/lib/module/core/format/parse.js +2 -2
  95. package/lib/module/core/format/parse.js.map +1 -1
  96. package/lib/module/core/index.js +10 -10
  97. package/lib/module/core/index.js.map +1 -1
  98. package/lib/module/core/locale/index.js +2 -2
  99. package/lib/module/core/locale/index.js.map +1 -1
  100. package/lib/module/core/numerals/index.js +1 -1
  101. package/lib/module/core/numerals/index.js.map +1 -1
  102. package/lib/module/core/validation.js +2 -2
  103. package/lib/module/core/validation.js.map +1 -1
  104. package/lib/module/index.js +8 -8
  105. package/lib/module/index.js.map +1 -1
  106. package/lib/module/theme/create-theme.js +1 -1
  107. package/lib/module/theme/create-theme.js.map +1 -1
  108. package/lib/module/theme/index.js +2 -2
  109. package/lib/module/theme/index.js.map +1 -1
  110. package/lib/module/utils/date-helpers.js +2 -2
  111. package/lib/module/utils/date-helpers.js.map +1 -1
  112. package/lib/module/utils/index.js +1 -1
  113. package/lib/module/utils/index.js.map +1 -1
  114. package/package.json +41 -9
  115. package/lib/commonjs/core/validation.test.js +0 -248
  116. package/lib/commonjs/core/validation.test.js.map +0 -1
  117. package/lib/commonjs/exports.test.js +0 -133
  118. package/lib/commonjs/exports.test.js.map +0 -1
  119. package/lib/commonjs/package.json +0 -1
  120. package/lib/commonjs/phase2.test.js +0 -446
  121. package/lib/commonjs/phase2.test.js.map +0 -1
  122. package/lib/commonjs/phase3.test.js +0 -91
  123. package/lib/commonjs/phase3.test.js.map +0 -1
  124. package/lib/commonjs/phase4.test.js +0 -89
  125. package/lib/commonjs/phase4.test.js.map +0 -1
  126. package/lib/commonjs/phase5.test.js +0 -246
  127. package/lib/commonjs/phase5.test.js.map +0 -1
  128. package/lib/commonjs/phase7.test.js +0 -284
  129. package/lib/commonjs/phase7.test.js.map +0 -1
  130. package/lib/commonjs/range-helpers.test.js +0 -182
  131. package/lib/commonjs/range-helpers.test.js.map +0 -1
  132. package/lib/module/core/validation.test.js +0 -248
  133. package/lib/module/core/validation.test.js.map +0 -1
  134. package/lib/module/exports.test.js +0 -133
  135. package/lib/module/exports.test.js.map +0 -1
  136. package/lib/module/package.json +0 -1
  137. package/lib/module/phase2.test.js +0 -446
  138. package/lib/module/phase2.test.js.map +0 -1
  139. package/lib/module/phase3.test.js +0 -91
  140. package/lib/module/phase3.test.js.map +0 -1
  141. package/lib/module/phase4.test.js +0 -89
  142. package/lib/module/phase4.test.js.map +0 -1
  143. package/lib/module/phase5.test.js +0 -246
  144. package/lib/module/phase5.test.js.map +0 -1
  145. package/lib/module/phase7.test.js +0 -284
  146. package/lib/module/phase7.test.js.map +0 -1
  147. package/lib/module/range-helpers.test.js +0 -182
  148. package/lib/module/range-helpers.test.js.map +0 -1
  149. package/src/core/validation.test.ts +0 -207
  150. package/src/exports.test.ts +0 -135
  151. package/src/phase2.test.ts +0 -424
  152. package/src/phase3.test.ts +0 -83
  153. package/src/phase4.test.ts +0 -86
  154. package/src/phase5.test.ts +0 -257
  155. package/src/phase7.test.ts +0 -307
  156. package/src/range-helpers.test.ts +0 -153
@@ -1,424 +0,0 @@
1
- import {
2
- toNepaliNumerals,
3
- toLatinNumerals,
4
- formatBS,
5
- parseBS,
6
- getCalendarMonthGrid,
7
- compareBS,
8
- addBSDays,
9
- subBSDays,
10
- todayBS,
11
- isValidBSDate,
12
- createBSDateKey,
13
- } from './index';
14
-
15
- describe('Nepali numerals', () => {
16
- describe('toNepaliNumerals', () => {
17
- it('converts latin digits to devanagari', () => {
18
- expect(toNepaliNumerals('2082-01-05')).toBe('२०८२-०१-०५');
19
- });
20
-
21
- it('converts numbers to devanagari', () => {
22
- expect(toNepaliNumerals(2082)).toBe('२०८२');
23
- });
24
-
25
- it('preserves non-digit characters', () => {
26
- expect(toNepaliNumerals('2082/01/05')).toBe('२०८२/०१/०५');
27
- expect(toNepaliNumerals('Year 2082')).toBe('Year २०८२');
28
- });
29
-
30
- it('handles empty string', () => {
31
- expect(toNepaliNumerals('')).toBe('');
32
- });
33
-
34
- it('handles zero', () => {
35
- expect(toNepaliNumerals(0)).toBe('०');
36
- });
37
- });
38
-
39
- describe('toLatinNumerals', () => {
40
- it('converts devanagari digits to latin', () => {
41
- expect(toLatinNumerals('२०८२-०१-०५')).toBe('2082-01-05');
42
- });
43
-
44
- it('preserves non-digit characters', () => {
45
- expect(toLatinNumerals('२०८२/०१/०५')).toBe('2082/01/05');
46
- });
47
-
48
- it('handles empty string', () => {
49
- expect(toLatinNumerals('')).toBe('');
50
- });
51
-
52
- it('handles numbers by converting to string first', () => {
53
- expect(toLatinNumerals(2082)).toBe('2082');
54
- });
55
- });
56
- });
57
-
58
- describe('formatBS', () => {
59
- const date = { calendar: 'BS' as const, year: 2081, month: 1, day: 5 };
60
-
61
- it('formats yyyy-MM-dd', () => {
62
- expect(formatBS(date, 'yyyy-MM-dd')).toBe('2081-01-05');
63
- });
64
-
65
- it('formats yy token', () => {
66
- expect(formatBS(date, 'yy-MM-dd')).toBe('81-01-05');
67
- });
68
-
69
- it('formats M without padding', () => {
70
- expect(formatBS(date, 'yyyy-M-d')).toBe('2081-1-5');
71
- });
72
-
73
- it('formats MMM short month', () => {
74
- expect(formatBS(date, 'MMM yyyy')).toBe('Bai 2081');
75
- });
76
-
77
- it('formats MMMM full month', () => {
78
- expect(formatBS(date, 'MMMM yyyy')).toBe('Baisakh 2081');
79
- });
80
-
81
- it('formats with Nepali locale and devanagari numerals', () => {
82
- const result = formatBS(date, 'dd MMMM yyyy', {
83
- locale: 'ne',
84
- numerals: 'devanagari',
85
- });
86
- expect(result).toBe('०५ बैशाख २०८१');
87
- });
88
-
89
- it('formats weekday EEEE in English', () => {
90
- const result = formatBS(date, 'EEEE');
91
- expect(result).toBe('Wednesday');
92
- });
93
-
94
- it('formats weekday E in English', () => {
95
- const result = formatBS(date, 'E');
96
- expect(result).toBe('Wed');
97
- });
98
-
99
- it('formats weekday EEE in English', () => {
100
- const result = formatBS(date, 'EEE');
101
- expect(result).toBe('Wed');
102
- });
103
-
104
- it('formats weekday tokens in Nepali', () => {
105
- const full = formatBS(date, 'EEEE', { locale: 'ne' });
106
- const short = formatBS(date, 'E', { locale: 'ne' });
107
- expect(full).toBe('बुधबार');
108
- expect(short).toBe('बुध');
109
- });
110
-
111
- it('preserves literal characters that are not tokens', () => {
112
- expect(formatBS(date, 'yyyy/MM/dd')).toBe('2081/01/05');
113
- expect(formatBS(date, 'dd-MM-yyyy')).toBe('05-01-2081');
114
- });
115
-
116
- it('does not convert numerals on non-numeric tokens', () => {
117
- const result = formatBS(date, 'MMMM dd', {
118
- locale: 'en',
119
- numerals: 'devanagari',
120
- });
121
- expect(result).toBe('Baisakh ०५');
122
- });
123
-
124
- it('works with explicit numerals latin', () => {
125
- const result = formatBS(date, 'yyyy-MM-dd', {
126
- numerals: 'latin',
127
- });
128
- expect(result).toBe('2081-01-05');
129
- });
130
-
131
- it('accepts CalendarLocale object as locale', () => {
132
- const customLocale = {
133
- code: 'en' as const,
134
- months: ['Month1', 'Month2', 'Month3', 'Month4', 'Month5', 'Month6', 'Month7', 'Month8', 'Month9', 'Month10', 'Month11', 'Month12'],
135
- monthsShort: ['M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'M10', 'M11', 'M12'],
136
- weekdays: ['WD0', 'WD1', 'WD2', 'WD3', 'WD4', 'WD5', 'WD6'],
137
- weekdaysShort: ['W0', 'W1', 'W2', 'W3', 'W4', 'W5', 'W6'],
138
- today: 'Today',
139
- };
140
-
141
- const result = formatBS(date, 'MMMM E', { locale: customLocale });
142
- expect(result).toBe('Month1 W3');
143
- });
144
-
145
- it('throws for invalid BS date with range in message', () => {
146
- expect(() =>
147
- formatBS({ calendar: 'BS', year: 2081, month: 1, day: 100 }, 'yyyy-MM-dd')
148
- ).toThrow(/2081–2081/);
149
- });
150
-
151
- it('throws for out-of-range BS year with range in message', () => {
152
- expect(() =>
153
- formatBS({ calendar: 'BS', year: 2082, month: 1, day: 1 }, 'yyyy-MM-dd')
154
- ).toThrow(/2081–2081/);
155
- });
156
- });
157
-
158
- describe('parseBS', () => {
159
- it('parses latin numerals with yyyy-MM-dd', () => {
160
- const result = parseBS('2081-01-05', 'yyyy-MM-dd');
161
- expect(result).toEqual({ calendar: 'BS', year: 2081, month: 1, day: 5 });
162
- });
163
-
164
- it('parses devanagari numerals with yyyy-MM-dd', () => {
165
- const result = parseBS('२०८१-०१-०५', 'yyyy-MM-dd', {
166
- numerals: 'devanagari',
167
- });
168
- expect(result).toEqual({ calendar: 'BS', year: 2081, month: 1, day: 5 });
169
- });
170
-
171
- it('rejects single-digit month', () => {
172
- expect(() => parseBS('2081-1-05', 'yyyy-MM-dd')).toThrow(
173
- /Expected 4-digit year, 2-digit month/
174
- );
175
- });
176
-
177
- it('rejects single-digit day', () => {
178
- expect(() => parseBS('2081-01-5', 'yyyy-MM-dd')).toThrow(
179
- /Expected 4-digit year, 2-digit month/
180
- );
181
- });
182
-
183
- it('throws for invalid date', () => {
184
- expect(() => parseBS('2081-08-30', 'yyyy-MM-dd')).toThrow(RangeError);
185
- });
186
-
187
- it('throws for unsupported pattern', () => {
188
- expect(() => parseBS('2081-01-05', 'dd/MM/yyyy')).toThrow(
189
- /Unsupported parse pattern/
190
- );
191
- });
192
- });
193
-
194
- describe('compareBS', () => {
195
- const a = { calendar: 'BS' as const, year: 2081, month: 1, day: 5 };
196
- const b = { calendar: 'BS' as const, year: 2081, month: 1, day: 10 };
197
- const c = { calendar: 'BS' as const, year: 2081, month: 2, day: 1 };
198
- const d = { calendar: 'BS' as const, year: 2082, month: 1, day: 1 };
199
-
200
- it('returns 0 for equal dates', () => {
201
- expect(compareBS(a, { ...a })).toBe(0);
202
- });
203
-
204
- it('returns negative when first date is earlier by day', () => {
205
- expect(compareBS(a, b)).toBeLessThan(0);
206
- });
207
-
208
- it('returns positive when first date is later by day', () => {
209
- expect(compareBS(b, a)).toBeGreaterThan(0);
210
- });
211
-
212
- it('returns negative when first date is earlier by month', () => {
213
- expect(compareBS(a, c)).toBeLessThan(0);
214
- });
215
-
216
- it('returns negative when first date is earlier by year', () => {
217
- expect(compareBS(a, d)).toBeLessThan(0);
218
- });
219
- });
220
-
221
- describe('addBSDays and subBSDays', () => {
222
- const base = { calendar: 'BS' as const, year: 2081, month: 1, day: 5 };
223
-
224
- it('adds days correctly', () => {
225
- const result = addBSDays(base, 10);
226
- expect(result.day).toBe(15);
227
- expect(result.month).toBe(1);
228
- expect(result.year).toBe(2081);
229
- });
230
-
231
- it('subtracts days correctly', () => {
232
- const result = subBSDays(base, 3);
233
- expect(result.day).toBe(2);
234
- expect(result.month).toBe(1);
235
- expect(result.year).toBe(2081);
236
- });
237
-
238
- it('throws for invalid date', () => {
239
- expect(() =>
240
- addBSDays({ calendar: 'BS', year: 2081, month: 1, day: 100 }, 1)
241
- ).toThrow(RangeError);
242
- });
243
- });
244
-
245
- describe('todayBS', () => {
246
- it('returns a valid BSDateValue shape when within supported range', () => {
247
- try {
248
- const today = todayBS();
249
- expect(today.calendar).toBe('BS');
250
- expect(Number.isInteger(today.year)).toBe(true);
251
- expect(Number.isInteger(today.month)).toBe(true);
252
- expect(Number.isInteger(today.day)).toBe(true);
253
- expect(today.month).toBeGreaterThanOrEqual(1);
254
- expect(today.month).toBeLessThanOrEqual(12);
255
- expect(today.day).toBeGreaterThanOrEqual(1);
256
- } catch (error) {
257
- expect((error as Error).message).toMatch(/Conversion is limited/);
258
- }
259
- });
260
- });
261
-
262
- describe('getCalendarMonthGrid', () => {
263
- it('returns weeks array', () => {
264
- const grid = getCalendarMonthGrid({ year: 2081, month: 1 });
265
- expect(Array.isArray(grid.weeks)).toBe(true);
266
- expect(grid.weeks.length).toBeGreaterThanOrEqual(5);
267
- expect(grid.weeks.length).toBeLessThanOrEqual(6);
268
- });
269
-
270
- it('every week has 7 cells', () => {
271
- const grid = getCalendarMonthGrid({ year: 2081, month: 1 });
272
- for (const week of grid.weeks) {
273
- expect(week.length).toBe(7);
274
- }
275
- });
276
-
277
- it('current month cells are marked correctly', () => {
278
- const grid = getCalendarMonthGrid({ year: 2081, month: 1 });
279
- let foundCurrentMonth = false;
280
-
281
- for (const week of grid.weeks) {
282
- for (const cell of week) {
283
- if (cell.inCurrentMonth) {
284
- foundCurrentMonth = true;
285
- expect(cell.date.year).toBe(2081);
286
- expect(cell.date.month).toBe(1);
287
- }
288
- }
289
- }
290
-
291
- expect(foundCurrentMonth).toBe(true);
292
- });
293
-
294
- it('previous and next month filler cells exist when needed', () => {
295
- const grid = getCalendarMonthGrid({ year: 2081, month: 2 });
296
- let hasPrev = false;
297
- let hasNext = false;
298
-
299
- for (const week of grid.weeks) {
300
- for (const cell of week) {
301
- if (!cell.inCurrentMonth) {
302
- if (cell.date.month === 1 && cell.date.year === 2081) {
303
- hasPrev = true;
304
- }
305
- if (cell.date.month === 3 && cell.date.year === 2081) {
306
- hasNext = true;
307
- }
308
- }
309
- }
310
- }
311
-
312
- expect(hasPrev || hasNext).toBe(true);
313
- });
314
-
315
- it('minDate disables earlier dates', () => {
316
- const minDate = { calendar: 'BS' as const, year: 2081, month: 1, day: 10 };
317
- const grid = getCalendarMonthGrid({ year: 2081, month: 1, minDate });
318
-
319
- for (const week of grid.weeks) {
320
- for (const cell of week) {
321
- if (compareBS(cell.date, minDate) < 0) {
322
- expect(cell.isDisabled).toBe(true);
323
- }
324
- }
325
- }
326
- });
327
-
328
- it('maxDate disables later dates', () => {
329
- const maxDate = { calendar: 'BS' as const, year: 2081, month: 1, day: 10 };
330
- const grid = getCalendarMonthGrid({ year: 2081, month: 1, maxDate });
331
-
332
- for (const week of grid.weeks) {
333
- for (const cell of week) {
334
- if (compareBS(cell.date, maxDate) > 0) {
335
- expect(cell.isDisabled).toBe(true);
336
- }
337
- }
338
- }
339
- });
340
-
341
- it('today marks correct cell', () => {
342
- const today = { calendar: 'BS' as const, year: 2081, month: 1, day: 5 };
343
- const grid = getCalendarMonthGrid({ year: 2081, month: 1, today });
344
-
345
- let foundToday = false;
346
-
347
- for (const week of grid.weeks) {
348
- for (const cell of week) {
349
- if (cell.isToday) {
350
- foundToday = true;
351
- expect(cell.date.day).toBe(5);
352
- }
353
- }
354
- }
355
-
356
- expect(foundToday).toBe(true);
357
- });
358
-
359
- it('respects weekStartsOn: 1 (Monday)', () => {
360
- const gridSunday = getCalendarMonthGrid({ year: 2081, month: 1, weekStartsOn: 0 });
361
- const gridMonday = getCalendarMonthGrid({ year: 2081, month: 1, weekStartsOn: 1 });
362
-
363
- const firstCellSunday = gridSunday.weeks[0][0];
364
- const firstCellMonday = gridMonday.weeks[0][0];
365
-
366
- expect(firstCellSunday.key).not.toBe(firstCellMonday.key);
367
- });
368
-
369
- it('cell keys match createBSDateKey format for in-range dates', () => {
370
- const grid = getCalendarMonthGrid({ year: 2081, month: 1 });
371
-
372
- for (const week of grid.weeks) {
373
- for (const cell of week) {
374
- if (cell.inCurrentMonth && isValidBSDate(cell.date)) {
375
- expect(cell.key).toBe(createBSDateKey(cell.date));
376
- }
377
- }
378
- }
379
- });
380
-
381
- it('handles December to January year boundary', () => {
382
- const grid = getCalendarMonthGrid({ year: 2081, month: 12 });
383
-
384
- expect(grid.year).toBe(2081);
385
- expect(grid.month).toBe(12);
386
-
387
- const hasAnyTrailing = grid.weeks.some(week =>
388
- week.some(cell => !cell.inCurrentMonth && cell.date.month === 1)
389
- );
390
-
391
- if (hasAnyTrailing) {
392
- const hasNextYear = grid.weeks.some(week =>
393
- week.some(cell => !cell.inCurrentMonth && cell.date.year === 2082 && cell.date.month === 1)
394
- );
395
- expect(hasNextYear).toBe(true);
396
- }
397
- });
398
-
399
- it('marks filler cells from unsupported years as disabled', () => {
400
- const grid = getCalendarMonthGrid({ year: 2081, month: 1 });
401
-
402
- for (const week of grid.weeks) {
403
- for (const cell of week) {
404
- if (!cell.inCurrentMonth && cell.date.year !== 2081) {
405
- expect(cell.isDisabled).toBe(true);
406
- }
407
- }
408
- }
409
- });
410
- });
411
-
412
- describe('public exports', () => {
413
- it('all Phase 2 functions are exported', () => {
414
- expect(typeof toNepaliNumerals).toBe('function');
415
- expect(typeof toLatinNumerals).toBe('function');
416
- expect(typeof formatBS).toBe('function');
417
- expect(typeof parseBS).toBe('function');
418
- expect(typeof getCalendarMonthGrid).toBe('function');
419
- expect(typeof compareBS).toBe('function');
420
- expect(typeof addBSDays).toBe('function');
421
- expect(typeof subBSDays).toBe('function');
422
- expect(typeof todayBS).toBe('function');
423
- });
424
- });
@@ -1,83 +0,0 @@
1
- import {
2
- getDayAccessibilityLabel,
3
- HEADER_PREV_MONTH_LABEL,
4
- HEADER_NEXT_MONTH_LABEL,
5
- } from './accessibility/labels';
6
- import { EN_LOCALE, NE_LOCALE } from './core/locale';
7
-
8
- describe('accessibility labels', () => {
9
- const date = { calendar: 'BS' as const, year: 2081, month: 1, day: 5 };
10
-
11
- it('returns plain date label', () => {
12
- const label = getDayAccessibilityLabel(date, EN_LOCALE, false, false, false);
13
- expect(label).toBe('2081 Baisakh 5');
14
- });
15
-
16
- it('returns selected label', () => {
17
- const label = getDayAccessibilityLabel(date, EN_LOCALE, true, false, false);
18
- expect(label).toBe('2081 Baisakh 5, selected');
19
- });
20
-
21
- it('returns today label', () => {
22
- const label = getDayAccessibilityLabel(date, EN_LOCALE, false, true, false);
23
- expect(label).toBe('2081 Baisakh 5, today');
24
- });
25
-
26
- it('returns disabled label', () => {
27
- const label = getDayAccessibilityLabel(date, EN_LOCALE, false, false, true);
28
- expect(label).toBe('2081 Baisakh 5, disabled');
29
- });
30
-
31
- it('prioritizes disabled over selected', () => {
32
- const label = getDayAccessibilityLabel(date, EN_LOCALE, true, false, true);
33
- expect(label).toBe('2081 Baisakh 5, disabled');
34
- });
35
-
36
- it('works with Nepali locale', () => {
37
- const label = getDayAccessibilityLabel(date, NE_LOCALE, false, false, false);
38
- expect(label).toContain('बैशाख');
39
- });
40
-
41
- it('exports header navigation labels', () => {
42
- expect(HEADER_PREV_MONTH_LABEL).toBe('Previous month');
43
- expect(HEADER_NEXT_MONTH_LABEL).toBe('Next month');
44
- });
45
- });
46
-
47
- describe('month navigation helpers', () => {
48
- function getPreviousBSMonth(
49
- year: number,
50
- month: number
51
- ): { year: number; month: number } {
52
- if (month === 1) return { year: year - 1, month: 12 };
53
- return { year, month: month - 1 };
54
- }
55
-
56
- function getNextBSMonth(
57
- year: number,
58
- month: number
59
- ): { year: number; month: number } {
60
- if (month === 12) return { year: year + 1, month: 1 };
61
- return { year, month: month + 1 };
62
- }
63
-
64
- it('previous month of January goes to December of previous year', () => {
65
- const prev = getPreviousBSMonth(2081, 1);
66
- expect(prev).toEqual({ year: 2080, month: 12 });
67
- });
68
-
69
- it('previous month of non-January stays in same year', () => {
70
- const prev = getPreviousBSMonth(2081, 5);
71
- expect(prev).toEqual({ year: 2081, month: 4 });
72
- });
73
-
74
- it('next month of December goes to January of next year', () => {
75
- const next = getNextBSMonth(2081, 12);
76
- expect(next).toEqual({ year: 2082, month: 1 });
77
- });
78
-
79
- it('next month of non-December stays in same year', () => {
80
- const next = getNextBSMonth(2081, 5);
81
- expect(next).toEqual({ year: 2081, month: 6 });
82
- });
83
- });
@@ -1,86 +0,0 @@
1
- import { formatBS } from './core/format';
2
- import { isValidBSDate, isBSDateInSupportedRange } from './core/validation';
3
- import type { BSDateValue } from './core/types';
4
- import type { LocaleCode, NumeralSystem } from './core/locale';
5
-
6
- function safeFormatDate(
7
- date: BSDateValue | null | undefined,
8
- pattern: string,
9
- locale: LocaleCode | undefined,
10
- numerals: NumeralSystem | undefined
11
- ): string | null {
12
- if (!date) return null;
13
-
14
- try {
15
- return formatBS(date, pattern, { locale, numerals });
16
- } catch {
17
- return null;
18
- }
19
- }
20
-
21
- describe('DatePicker safe formatter', () => {
22
- it('returns null for null date', () => {
23
- expect(safeFormatDate(null, 'yyyy-MM-dd', undefined, undefined)).toBeNull();
24
- });
25
-
26
- it('returns null for undefined date', () => {
27
- expect(safeFormatDate(undefined, 'yyyy-MM-dd', undefined, undefined)).toBeNull();
28
- });
29
-
30
- it('formats valid in-range date', () => {
31
- const result = safeFormatDate(
32
- { calendar: 'BS', year: 2081, month: 1, day: 5 },
33
- 'yyyy-MM-dd',
34
- undefined,
35
- undefined
36
- );
37
- expect(result).toBe('2081-01-05');
38
- });
39
-
40
- it('returns null for out-of-range date instead of throwing', () => {
41
- const result = safeFormatDate(
42
- { calendar: 'BS', year: 2082, month: 1, day: 1 },
43
- 'yyyy-MM-dd',
44
- undefined,
45
- undefined
46
- );
47
- expect(result).toBeNull();
48
- });
49
-
50
- it('formats with Nepali locale and devanagari numerals', () => {
51
- const result = safeFormatDate(
52
- { calendar: 'BS', year: 2081, month: 1, day: 5 },
53
- 'dd MMMM yyyy',
54
- 'ne',
55
- 'devanagari'
56
- );
57
- expect(result).toBe('०५ बैशाख २०८१');
58
- });
59
-
60
- it('returns null for invalid date structure', () => {
61
- const result = safeFormatDate(
62
- { calendar: 'BS' as const, year: 2081, month: 1, day: 100 },
63
- 'yyyy-MM-dd',
64
- undefined,
65
- undefined
66
- );
67
- expect(result).toBeNull();
68
- });
69
- });
70
-
71
- describe('DatePicker initial temp date logic', () => {
72
- it('uses valid in-range value', () => {
73
- const value: BSDateValue = { calendar: 'BS', year: 2081, month: 3, day: 15 };
74
- expect(isValidBSDate(value) && isBSDateInSupportedRange(value)).toBe(true);
75
- });
76
-
77
- it('rejects out-of-range value for initial selection', () => {
78
- const value: BSDateValue = { calendar: 'BS', year: 2082, month: 1, day: 1 };
79
- expect(isBSDateInSupportedRange(value)).toBe(false);
80
- });
81
-
82
- it('rejects invalid date for initial selection', () => {
83
- const value: BSDateValue = { calendar: 'BS', year: 2081, month: 1, day: 100 };
84
- expect(isValidBSDate(value)).toBe(false);
85
- });
86
- });