Skip to content

Commit cde231a

Browse files
committed
Expose constants for Norwegian standard ZoneId Europe/Oslo
1 parent 664343a commit cde231a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/main/java/no/bekk/bekkopen/date/NorwegianDateUtil.java

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.time.DayOfWeek;
3030
import java.time.LocalDate;
3131
import java.time.Month;
32+
import java.time.ZoneId;
3233
import java.time.ZonedDateTime;
3334
import java.util.Comparator;
3435
import java.util.HashMap;
@@ -42,6 +43,9 @@
4243
* Utility class for Norwegian dates.
4344
*/
4445
public class NorwegianDateUtil {
46+
47+
public static final String ZONEID_EUROPE_OSLO = "Europe/Oslo";
48+
public static final ZoneId ZONE_NORWAY = ZoneId.of(ZONEID_EUROPE_OSLO);
4549

4650
private final static Map<Integer, NavigableSet<LocalDate>> holidays = new HashMap<>();
4751

src/test/java/no/bekk/bekkopen/date/NorwegianDateUtilTest.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030

3131
import java.time.LocalDate;
3232
import java.time.Month;
33-
import java.time.ZoneId;
3433
import java.time.ZonedDateTime;
3534
import java.util.Arrays;
3635
import java.util.LinkedHashSet;
3736
import java.util.NavigableSet;
3837

38+
import static no.bekk.bekkopen.date.NorwegianDateUtil.ZONE_NORWAY;
3939
import static org.hamcrest.MatcherAssert.assertThat;
4040
import static org.junit.jupiter.api.Assertions.assertEquals;
4141
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -44,11 +44,10 @@
4444

4545
public class NorwegianDateUtilTest {
4646

47-
public static ZoneId NORGESONE = ZoneId.of("Europe/Oslo");
4847

4948
@Test
5049
public void testAdd2DaysWithinSameWeek() {
51-
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 18).atStartOfDay(NORGESONE);
50+
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 18).atStartOfDay(ZONE_NORWAY);
5251

5352
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 2);
5453

@@ -58,7 +57,7 @@ public void testAdd2DaysWithinSameWeek() {
5857

5958
@Test
6059
public void testAdd2DaysBeforeWeekend() {
61-
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 20).atStartOfDay(NORGESONE);
60+
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 20).atStartOfDay(ZONE_NORWAY);
6261

6362
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 2);
6463

@@ -68,7 +67,7 @@ public void testAdd2DaysBeforeWeekend() {
6867

6968
@Test
7069
void testAdd2DaysToLastDayOfMonth() {
71-
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(NORGESONE);
70+
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(ZONE_NORWAY);
7271

7372
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 2);
7473

@@ -78,7 +77,7 @@ void testAdd2DaysToLastDayOfMonth() {
7877

7978
@Test
8079
void testAdd5DaysWithNoHolidays() {
81-
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(NORGESONE);
80+
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(ZONE_NORWAY);
8281

8382
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 5);
8483

@@ -88,7 +87,7 @@ void testAdd5DaysWithNoHolidays() {
8887

8988
@Test
9089
void testAdd5DaysBeforeEasterHoliday() {
91-
ZonedDateTime zonedDateTime = LocalDate.of(2025, 4, 11).atStartOfDay(NORGESONE);
90+
ZonedDateTime zonedDateTime = LocalDate.of(2025, 4, 11).atStartOfDay(ZONE_NORWAY);
9291

9392
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 5);
9493

@@ -98,7 +97,7 @@ void testAdd5DaysBeforeEasterHoliday() {
9897

9998
@Test
10099
void testAdd5DaysBeforeNationalDay() {
101-
ZonedDateTime zonedDateTime = LocalDate.of(2007, 5, 16).atStartOfDay(NORGESONE);
100+
ZonedDateTime zonedDateTime = LocalDate.of(2007, 5, 16).atStartOfDay(ZONE_NORWAY);
102101

103102
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 5);
104103

@@ -108,7 +107,7 @@ void testAdd5DaysBeforeNationalDay() {
108107

109108
@Test
110109
void testAdd5DaysBeforeChristmas() {
111-
ZonedDateTime zonedDateTime = LocalDate.of(2024, 12, 20).atStartOfDay(NORGESONE);
110+
ZonedDateTime zonedDateTime = LocalDate.of(2024, 12, 20).atStartOfDay(ZONE_NORWAY);
112111

113112
ZonedDateTime ny = NorwegianDateUtil.addWorkingDaysToDate(zonedDateTime, 6);
114113

@@ -119,10 +118,10 @@ void testAdd5DaysBeforeChristmas() {
119118

120119
@Test
121120
public void testWorkingDays() {
122-
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 22).atStartOfDay(NORGESONE)), "Sunday not working day");
123-
assertTrue(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 16).atStartOfDay(NORGESONE)), "Monday is working day");
124-
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2025, 1, 1).atStartOfDay(NORGESONE)), "New years day not working day");
125-
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2007, 4, 8).atStartOfDay(NORGESONE)), "Easter day not working day");
121+
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 22).atStartOfDay(ZONE_NORWAY)), "Sunday not working day");
122+
assertTrue(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 16).atStartOfDay(ZONE_NORWAY)), "Monday is working day");
123+
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2025, 1, 1).atStartOfDay(ZONE_NORWAY)), "New years day not working day");
124+
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2007, 4, 8).atStartOfDay(ZONE_NORWAY)), "Easter day not working day");
126125
}
127126

128127

@@ -185,6 +184,6 @@ public void testGetAllNorwegianHolidaysForYear() {
185184
}
186185

187186
private void checkHoliday(LocalDate date) {
188-
assertThat(date.atStartOfDay(NORGESONE), where(NorwegianDateUtil::isHoliday));
187+
assertThat(date.atStartOfDay(ZONE_NORWAY), where(NorwegianDateUtil::isHoliday));
189188
}
190189
}

0 commit comments

Comments
 (0)