Skip to content

Commit 371a08f

Browse files
committed
feat: merge main
2 parents 149e12e + 53663f9 commit 371a08f

13 files changed

+299
-15
lines changed

.github/workflows/dhis2-verify-lib.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
with:
9898
path: '**/node_modules'
9999
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
100-
100+
101101
- name: Build
102102
run: yarn build
103103

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
1+
## [1.3.1](https://github.com/dhis2/multi-calendar-dates/compare/v1.3.0...v1.3.1) (2024-09-26)
2+
3+
4+
### Bug Fixes
5+
6+
* add back eslint-disable ([1e66fb5](https://github.com/dhis2/multi-calendar-dates/commit/1e66fb55e62bcce8e81e9b368750bb3eb4d3acbd))
7+
* add tests ([4bfaa7c](https://github.com/dhis2/multi-calendar-dates/commit/4bfaa7c7d0ba657c3e24ac30342274a9a8e3481f))
8+
* address merge issues [LIBS-684] ([6770573](https://github.com/dhis2/multi-calendar-dates/commit/67705737f7cc17ba61256070cbf0b8fc22160a34))
9+
* changes for data entry app [LIBS-684] ([ea7e8af](https://github.com/dhis2/multi-calendar-dates/commit/ea7e8af472886fb26d737ca1013e3e192dcbeb6a))
10+
* clean up for period generation in data entry app [LIBS-684] ([4cabc55](https://github.com/dhis2/multi-calendar-dates/commit/4cabc555f488407dca425eb7e92f67184f935600))
11+
* remove replaceAll, add locale check ([c8c2e8a](https://github.com/dhis2/multi-calendar-dates/commit/c8c2e8a174b051bca1a7e724f34cae9d6a026a43))
12+
13+
# [1.3.0](https://github.com/dhis2/multi-calendar-dates/compare/v1.2.4...v1.3.0) (2024-09-24)
14+
15+
16+
### Bug Fixes
17+
18+
* format undefined when thers is a mismatch ([79b54fd](https://github.com/dhis2/multi-calendar-dates/commit/79b54fdbac8d8de1eab5e197dc65f2cb523e35cc))
19+
* localise validation message in multi calendar ([#61](https://github.com/dhis2/multi-calendar-dates/issues/61)) ([ead860b](https://github.com/dhis2/multi-calendar-dates/commit/ead860bb9513b6436f345ef36f374829240cefe5))
20+
* remove unnecessary console warn ([b2d795d](https://github.com/dhis2/multi-calendar-dates/commit/b2d795d39d4e5a6d936b10ef3f6bb46bd9ead798))
21+
22+
23+
### Features
24+
25+
* expose function to convert dates ([622f0eb](https://github.com/dhis2/multi-calendar-dates/commit/622f0ebb5aa9952866127feb140a50639669975d))
26+
* expose function to convert dates ([9d42640](https://github.com/dhis2/multi-calendar-dates/commit/9d426408e06f7f2d04025edc267559edb8f73768))
27+
* expose methods for converting between iso8601 and calendars ([#37](https://github.com/dhis2/multi-calendar-dates/issues/37)) ([33fa25d](https://github.com/dhis2/multi-calendar-dates/commit/33fa25d30e9b0f5fe45e2174e18d41bc4cd7c058))
28+
* reararnge memorized variables so that we only recompute them when necessary ([b754dcc](https://github.com/dhis2/multi-calendar-dates/commit/b754dcc4c3c8f0aecb06836b0c3915af1b2af6d5))
29+
* support min & max date, DD-MM-YYYY date format ([#36](https://github.com/dhis2/multi-calendar-dates/issues/36)) ([3b2e57e](https://github.com/dhis2/multi-calendar-dates/commit/3b2e57e7bc1bb3326ab83662c7eaac8e6447be41))
30+
* **validation:** add and expose validateDateString utility ([cb4c919](https://github.com/dhis2/multi-calendar-dates/commit/cb4c9191dd96ff0da3e05a73ac0149e9304f974d))
31+
132
# [1.3.0-alpha.2](https://github.com/dhis2/multi-calendar-dates/compare/v1.3.0-alpha.1...v1.3.0-alpha.2) (2024-08-28)
233

334

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@dhis2/multi-calendar-dates",
3-
"version": "1.3.0-alpha.2",
3+
"version": "1.3.1",
44
"license": "BSD-3-Clause",
55
"publishConfig": {
66
"access": "public"

src/period-calculation/create-fixed-period-from-period-id/create-fixed-period-from-period-id.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import i18n from '@dhis2/d2-i18n'
22
import { dhis2CalendarsMap } from '../../constants/dhis2CalendarsMap'
33
import { SupportedCalendar } from '../../types'
4+
import getValidLocale from '../../utils/getValidLocale'
45
import { fromAnyDate, getCustomCalendarIfExists } from '../../utils/index'
56
import { buildDailyFixedPeriod } from '../daily-periods/index'
67
import { generateFixedPeriods } from '../generate-fixed-periods/index'
@@ -31,6 +32,8 @@ const createFixedPeriodFromPeriodId: ParseFixedPeriodId = ({
3132
dhis2CalendarsMap[requestedCalendar] ?? requestedCalendar
3233
) as SupportedCalendar
3334

35+
const validLocale = getValidLocale(locale) ?? 'en'
36+
3437
if (isAnyYearlyPeriodId(periodId)) {
3538
const year = parseInt(periodId.substring(0, 4), 10)
3639
const periodType = getYearlyFixedPeriodTypeForPeriodId(periodId)
@@ -45,7 +48,7 @@ const createFixedPeriodFromPeriodId: ParseFixedPeriodId = ({
4548
periodType,
4649
year,
4750
calendar,
48-
locale,
51+
locale: validLocale,
4952
})
5053

5154
const foundThisYear = monthlyPeriodsForYear.find(
@@ -62,7 +65,7 @@ const createFixedPeriodFromPeriodId: ParseFixedPeriodId = ({
6265
year: year + 1,
6366
periodType,
6467
calendar,
65-
locale,
68+
locale: validLocale,
6669
}).slice(-1)
6770

6871
const foundNextYear = monthlyPeriodsForNextYear.find(

src/period-calculation/generate-fixed-periods/does-period-end-before.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
import { Temporal } from '@js-temporal/polyfill'
2+
import { SupportedCalendar } from '../../types'
3+
import { fromAnyDate } from '../../utils'
24

35
type DoesPeriodEndBefore = (args: {
46
period: { startDate: string; endDate: string }
57
date: Temporal.PlainDate
8+
calendar: SupportedCalendar
69
}) => boolean
710

8-
const doesPeriodEndBefore: DoesPeriodEndBefore = ({ period, date }) => {
9-
const periodStartDay = Temporal.PlainDate.from(period.startDate)
10-
const periodEndDay = Temporal.PlainDate.from(period.endDate)
11+
const doesPeriodEndBefore: DoesPeriodEndBefore = ({
12+
period,
13+
date,
14+
calendar,
15+
}) => {
16+
const periodStartDay = fromAnyDate({ calendar, date: period.startDate })
17+
const periodEndDay = fromAnyDate({ calendar, date: period.endDate })
1118

1219
const periodStartsOnOrAfterDate =
1320
Temporal.PlainDate.compare(date, periodStartDay) < 1

src/period-calculation/generate-fixed-periods/generate-fixed-periods-monthly.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const generateFixedPeriodsMonthly: GenerateFixedPeriodsMonthly = ({
6262

6363
if (
6464
endsBefore &&
65-
doesPeriodEndBefore({ period, date: endsBefore })
65+
doesPeriodEndBefore({ period, date: endsBefore, calendar })
6666
) {
6767
break
6868
}

src/period-calculation/generate-fixed-periods/generate-fixed-periods-weekly.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ const generateFixedPeriodsWeekly: GenerateFixedPeriodsWeekly = ({
5252
endsBefore &&
5353
doesPeriodEndBefore({
5454
period: {
55-
startDate: date.toString(),
56-
endDate: endofWeek.toString(),
55+
startDate: formatDate(date),
56+
endDate: formatDate(endofWeek),
5757
},
5858
date: endsBefore,
59+
calendar,
5960
})
6061
) {
6162
break

src/period-calculation/generate-fixed-periods/generate-fixed-periods-yearly.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ const generateFixedPeriodsYearly: GenerateFixedPeriodsYearly = ({
6565
calendar,
6666
})
6767

68-
if (endsBefore && doesPeriodEndBefore({ period, date: endsBefore })) {
68+
if (
69+
endsBefore &&
70+
doesPeriodEndBefore({ period, date: endsBefore, calendar })
71+
) {
6972
continue
7073
}
7174

src/period-calculation/generate-fixed-periods/generate-fixed-periods.ethiopic.spec.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,101 @@ describe('Ethiopic Calendar fixed period calculation', () => {
293293
// expect(periods[periods.length - 1]).toEqual("2015-11-01/2015-13-06");
294294
})
295295
})
296+
297+
describe('periods calculated with endsBefore', () => {
298+
it('should omit every period on/after the exclude date (daily)', () => {
299+
const results = generateFixedPeriods({
300+
periodType: 'DAILY',
301+
year: 2016,
302+
calendar: 'ethiopic',
303+
locale: 'en',
304+
endsBefore: '2016-03-03',
305+
})
306+
307+
expect(results.length).toBe(62)
308+
expect(results[0]).toMatchObject({
309+
displayName: 'Meskerem 1, 2016 ERA0',
310+
endDate: '2016-01-01',
311+
id: '20160101',
312+
iso: '20160101',
313+
name: '2016-01-01',
314+
periodType: 'DAILY',
315+
startDate: '2016-01-01',
316+
})
317+
expect(results[results.length - 1]).toMatchObject({
318+
displayName: 'Hedar 2, 2016 ERA0',
319+
endDate: '2016-03-02',
320+
id: '20160302',
321+
iso: '20160302',
322+
name: '2016-03-02',
323+
periodType: 'DAILY',
324+
startDate: '2016-03-02',
325+
})
326+
})
327+
328+
it('should omit every period on/after the exclude date (monthly)', () => {
329+
const results = generateFixedPeriods({
330+
periodType: 'MONTHLY',
331+
year: 2014,
332+
calendar: 'ethiopic',
333+
locale: 'en',
334+
endsBefore: '2014-07-12',
335+
})
336+
337+
expect(results.length).toBe(6)
338+
expect(results[0]).toMatchObject({
339+
periodType: 'MONTHLY',
340+
id: '201401',
341+
iso: '201401',
342+
name: 'Meskerem 2014',
343+
displayName: 'Meskerem 2014',
344+
startDate: '2014-01-01',
345+
endDate: '2014-01-30',
346+
})
347+
expect(results[results.length - 1]).toMatchObject({
348+
periodType: 'MONTHLY',
349+
id: '201406',
350+
iso: '201406',
351+
name: 'Yekatit 2014',
352+
displayName: 'Yekatit 2014',
353+
startDate: '2014-06-01',
354+
endDate: '2014-06-30',
355+
})
356+
})
357+
358+
it('should omit every period on/after the exclude date (weekly)', () => {
359+
const results = generateFixedPeriods({
360+
periodType: 'WEEKLY',
361+
year: 2014,
362+
calendar: 'ethiopic',
363+
locale: 'en',
364+
endsBefore: '2014-07-12',
365+
startingDay: 1,
366+
})
367+
368+
expect(results[results.length - 1]).toMatchObject({
369+
id: '2014W26',
370+
iso: '2014W26',
371+
name: 'Week 26 - 2014-06-29 - 2014-07-05',
372+
displayName: 'Week 26 - 2014-06-29 - 2014-07-05',
373+
})
374+
})
375+
376+
it('should omit every period on/after the exclude date (yearly)', () => {
377+
const result = generateFixedPeriods({
378+
periodType: 'YEARLY',
379+
year: 2015,
380+
endsBefore: '2015-03-01',
381+
calendar: 'ethiopic',
382+
locale: 'en',
383+
yearsCount: null,
384+
})
385+
expect(result[0]).toMatchObject({
386+
id: '2014',
387+
iso: '2014',
388+
name: '2014',
389+
displayName: '2014',
390+
})
391+
})
392+
})
296393
})

src/period-calculation/generate-fixed-periods/generate-fixed-periods.nepali.spec.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,101 @@ describe('Nepali Calendar fixed period calculation', () => {
210210
expect(periods[periods.length - 1]).toEqual('2079-11-01/2079-12-30')
211211
})
212212
})
213+
214+
describe('periods calculated with endsBefore', () => {
215+
it('should omit every period on/after the exclude date (daily)', () => {
216+
const results = generateFixedPeriods({
217+
periodType: 'DAILY',
218+
year: 2076,
219+
calendar: 'nepali',
220+
locale: 'en',
221+
endsBefore: '2076-03-03',
222+
})
223+
224+
expect(results.length).toBe(65)
225+
expect(results[0]).toMatchObject({
226+
displayName: '2076-01-01',
227+
endDate: '2076-01-01',
228+
id: '20760101',
229+
iso: '20760101',
230+
name: '2076-01-01',
231+
periodType: 'DAILY',
232+
startDate: '2076-01-01',
233+
})
234+
expect(results[results.length - 1]).toMatchObject({
235+
displayName: '2076-03-02',
236+
endDate: '2076-03-02',
237+
id: '20760302',
238+
iso: '20760302',
239+
name: '2076-03-02',
240+
periodType: 'DAILY',
241+
startDate: '2076-03-02',
242+
})
243+
})
244+
245+
it('should omit every period on/after the exclude date (monthly)', () => {
246+
const results = generateFixedPeriods({
247+
periodType: 'MONTHLY',
248+
year: 2074,
249+
calendar: 'nepali',
250+
locale: 'en',
251+
endsBefore: '2074-07-12',
252+
})
253+
254+
expect(results.length).toBe(6)
255+
expect(results[0]).toMatchObject({
256+
periodType: 'MONTHLY',
257+
id: '207401',
258+
iso: '207401',
259+
name: 'Baisakh 2074',
260+
displayName: 'Baisakh 2074',
261+
startDate: '2074-01-01',
262+
endDate: '2074-01-31',
263+
})
264+
expect(results[results.length - 1]).toMatchObject({
265+
periodType: 'MONTHLY',
266+
id: '207406',
267+
iso: '207406',
268+
name: 'Ashwin 2074',
269+
displayName: 'Ashwin 2074',
270+
startDate: '2074-06-01',
271+
endDate: '2074-06-31',
272+
})
273+
})
274+
275+
it('should omit every period on/after the exclude date (weekly)', () => {
276+
const results = generateFixedPeriods({
277+
periodType: 'WEEKLY',
278+
year: 2014,
279+
calendar: 'nepali',
280+
locale: 'en',
281+
endsBefore: '2014-07-12',
282+
startingDay: 1,
283+
})
284+
285+
expect(results[results.length - 1]).toMatchObject({
286+
id: '2014W28',
287+
iso: '2014W28',
288+
name: 'Week 28 - 2014-07-05 - 2014-07-11',
289+
displayName: 'Week 28 - 2014-07-05 - 2014-07-11',
290+
})
291+
})
292+
293+
it('should omit every period on/after the exclude date (yearly)', () => {
294+
const result = generateFixedPeriods({
295+
periodType: 'YEARLY',
296+
year: 2075,
297+
endsBefore: '2075-03-01',
298+
calendar: 'nepali',
299+
locale: 'en',
300+
yearsCount: null,
301+
})
302+
expect(result[0]).toMatchObject({
303+
id: '2074',
304+
iso: '2074',
305+
name: '2074',
306+
displayName: '2074',
307+
})
308+
})
309+
})
213310
})

0 commit comments

Comments
 (0)