Skip to content

Commit

Permalink
fix: Nepali calendar support [DHIS2-18268] (#19691)
Browse files Browse the repository at this point in the history
* fix: Return ISO period name in user calendar

* fix: Weekly period generation for Nepali Calendar
  • Loading branch information
abyot authored Jan 20, 2025
1 parent 24fb6b5 commit 71848d0
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.calendar.impl;

import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -54,6 +55,10 @@ public class NepaliCalendar extends AbstractCalendar {

private static final Calendar SELF = new NepaliCalendar();

private static final int DEFAULT_WEEKS_IN_YEAR = 52;

private static final int WEEK_LENGTH = 7;

public static Calendar getInstance() {
return SELF;
}
Expand Down Expand Up @@ -144,25 +149,46 @@ public int isoWeek(DateTimeUnit dateTimeUnit) {

@Override
public int week(DateTimeUnit dateTimeUnit) {
return isoWeek(dateTimeUnit);
/*
* https://en.m.wikipedia.org/wiki/ISO_week_date
*
* 10 = the constant =>
* 1. we should get zero or positive week number.
* 2. the first week should contain 4th of Jan
* 3. the earliest day_of_year we could ask week number for is 1 = Jan 1
* 4. the latest day_of_week we could ask week number for is 7 = Sun
* week = the constant + 1 - 7 => 0 = the constant + 1 - 7 => the constant = 6
* however, we also need to add 4 more days to ensure Jan 4th is in the week
* hence the constant = 10.
*
*/
int week = (10 + getDayOfYear(dateTimeUnit) - isoWeekday(dateTimeUnit)) / WEEK_LENGTH;
if (week < 1) {
week = DEFAULT_WEEKS_IN_YEAR;
} else if (week > DEFAULT_WEEKS_IN_YEAR) {
week = 1;
}
return week;
}

@Override
public int isoWeekday(DateTimeUnit dateTimeUnit) {
DateTime dateTime =
toIso(dateTimeUnit).toJodaDateTime(ISOChronology.getInstance(DateTimeZone.getDefault()));
return dateTime.getDayOfWeek();
/*
* Calculating week day from calendar dateTimeUnit is best managed
* via Gregorian calendar as week duration is 7 days in 'all' calendars
* and Mon = Day 1, Tue = Day 2, Wed = Day 3, ...
*/
DateTimeUnit isoDateTimeUnit = toIso(dateTimeUnit);

LocalDate localDate =
LocalDate.of(
isoDateTimeUnit.getYear(), isoDateTimeUnit.getMonth(), isoDateTimeUnit.getDay());
return localDate.getDayOfWeek().getValue();
}

@Override
public int weekday(DateTimeUnit dateTimeUnit) {
int dayOfWeek = (isoWeekday(dateTimeUnit) + 1);

if (dayOfWeek > 7) {
return 1;
}

return dayOfWeek;
return isoWeekday(dateTimeUnit);
}

@Override
Expand Down Expand Up @@ -461,11 +487,24 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
return new DateInterval(from, to, DateIntervalType.ISO8601_DAY);
}

private int getDayOfYear(DateTimeUnit dateTimeUnit) {
int dayOfYear = dateTimeUnit.getDay();

if (CONVERSION_MAP.get(dateTimeUnit.getYear()) != null) {
for (int j = 1; j < dateTimeUnit.getMonth(); j++) {
dayOfYear += CONVERSION_MAP.get(dateTimeUnit.getYear())[j];
}
}
return dayOfYear;
}

// ------------------------------------------------------------------------------------------------------------
// Conversion map for Nepali calendar
// Conversion map for Nepali calendar from year 1970 to 2100.
//
// Based on map from:
// http://forjavaprogrammers.blogspot.com/2012/06/how-to-convert-english-date-to-nepali.html
// http://www.ashesh.com.np
// http://nepalicalendar.rat32.com/index.php
// http://www.ashesh.com.np/nepali-calendar/
// ------------------------------------------------------------------------------------------------------------

/**
Expand All @@ -475,6 +514,39 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
private static final Map<Integer, int[]> CONVERSION_MAP = new HashMap<>();

static {
CONVERSION_MAP.put(1970, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1971, new int[] {0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1972, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1973, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1974, new int[] {0, 30, 32, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1975, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1976, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1977, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1978, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1979, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(1980, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1981, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(1982, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1983, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1984, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1985, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(1986, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1987, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1988, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(1989, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(1990, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1991, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(1992, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1993, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1994, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1995, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(1996, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(1997, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1998, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(1999, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});

CONVERSION_MAP.put(2000, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2001, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2002, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
Expand All @@ -485,6 +557,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2007, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2008, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31});
CONVERSION_MAP.put(2009, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2010, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2011, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2012, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
Expand All @@ -495,6 +568,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2017, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2018, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2019, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});

CONVERSION_MAP.put(2020, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2021, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2022, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
Expand All @@ -505,6 +579,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2027, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2028, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2029, new int[] {0, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2030, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2031, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2032, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
Expand All @@ -515,6 +590,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2037, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2038, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2039, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});

CONVERSION_MAP.put(2040, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2041, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2042, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
Expand All @@ -525,6 +601,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2047, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2048, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2049, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});

CONVERSION_MAP.put(2050, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2051, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2052, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
Expand All @@ -535,6 +612,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2057, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2058, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2059, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2060, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2061, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2062, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
Expand All @@ -545,6 +623,7 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2067, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2068, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2069, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});

CONVERSION_MAP.put(2070, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(2071, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2072, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
Expand All @@ -555,26 +634,29 @@ private DateInterval toDayIsoInterval(DateTimeUnit dateTimeUnit, int offset, int
CONVERSION_MAP.put(2077, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2078, new int[] {0, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2079, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});

CONVERSION_MAP.put(2080, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30});
CONVERSION_MAP.put(2081, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2082, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2083, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2084, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2085, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2086, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2087, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2088, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2089, new int[] {0, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31});
CONVERSION_MAP.put(2090, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2091, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2092, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2093, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31});
CONVERSION_MAP.put(2094, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2095, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 29});
CONVERSION_MAP.put(2096, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 32});
CONVERSION_MAP.put(2097, new int[] {0, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30});
CONVERSION_MAP.put(2098, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2099, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2100, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31});
CONVERSION_MAP.put(2081, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2082, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2083, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2084, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2085, new int[] {0, 31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2086, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2087, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2088, new int[] {0, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2089, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});

CONVERSION_MAP.put(2090, new int[] {0, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2091, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2092, new int[] {0, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2093, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2094, new int[] {0, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2095, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30});
CONVERSION_MAP.put(2096, new int[] {0, 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30});
CONVERSION_MAP.put(2097, new int[] {0, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30});
CONVERSION_MAP.put(2098, new int[] {0, 31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31});
CONVERSION_MAP.put(2099, new int[] {0, 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30});

CONVERSION_MAP.put(2100, new int[] {0, 31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ public Period createPeriod(DateInterval dateInterval) {
final DateTimeUnit from = cal.toIso(dateInterval.getFrom());
final DateTimeUnit to = cal.toIso(dateInterval.getTo());

return new Period(this, from.toJdkDate(), to.toJdkDate(), getIsoDate(from));
return new Period(this, from.toJdkDate(), to.toJdkDate(), getIsoDate(dateInterval.getFrom()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,14 @@

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.util.Date;
import java.util.List;
import org.hisp.dhis.calendar.Calendar;
import org.hisp.dhis.calendar.DateTimeUnit;
import org.hisp.dhis.period.Cal;
import org.hisp.dhis.period.Period;
import org.hisp.dhis.period.WeeklyPeriodType;
import org.joda.time.DateTime;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -74,4 +80,36 @@ void testPlusDays() {
assertEquals(12, testDateTimeUnit.getMonth());
assertEquals(30, testDateTimeUnit.getDay());
}

@Test
void testGenerateWeeklyPeriods() {
Date startDate = new Cal(2021, 4, 12, true).time();
Date endDate = new Cal(2022, 4, 10, true).time();

List<Period> weeks = new WeeklyPeriodType().generatePeriods(calendar, startDate, endDate);
assertEquals(52, weeks.size());
}

@Test
void testIsoDates() {
DateTimeUnit dateTimeUnit = new DateTimeUnit(2081, 1, 3, false);
DateTime startDate = new DateTime(2024, 4, 15, 0, 0);
DateTime endDate = new DateTime(2024, 4, 21, 0, 0);

WeeklyPeriodType periodType = new WeeklyPeriodType();
Period period = periodType.createPeriod(dateTimeUnit, calendar);

assertEquals("2081W1", period.getIsoDate());
assertEquals(startDate.toDate(), period.getStartDate());
assertEquals(endDate.toDate(), period.getEndDate());

dateTimeUnit = new DateTimeUnit(2080, 12, 26, false);
startDate = new DateTime(2024, 4, 8, 0, 0);
endDate = new DateTime(2024, 4, 14, 0, 0);

period = periodType.createPeriod(dateTimeUnit, calendar);
assertEquals("2080W52", period.getIsoDate());
assertEquals(startDate.toDate(), period.getStartDate());
assertEquals(endDate.toDate(), period.getEndDate());
}
}

0 comments on commit 71848d0

Please sign in to comment.