Skip to content

Commit

Permalink
Expose constants for Norwegian standard ZoneId Europe/Oslo
Browse files Browse the repository at this point in the history
  • Loading branch information
eivinhb committed Oct 4, 2024
1 parent 664343a commit cde231a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/main/java/no/bekk/bekkopen/date/NorwegianDateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Comparator;
import java.util.HashMap;
Expand All @@ -42,6 +43,9 @@
* Utility class for Norwegian dates.
*/
public class NorwegianDateUtil {

public static final String ZONEID_EUROPE_OSLO = "Europe/Oslo";
public static final ZoneId ZONE_NORWAY = ZoneId.of(ZONEID_EUROPE_OSLO);

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

Expand Down
27 changes: 13 additions & 14 deletions src/test/java/no/bekk/bekkopen/date/NorwegianDateUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

import java.time.LocalDate;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.NavigableSet;

import static no.bekk.bekkopen.date.NorwegianDateUtil.ZONE_NORWAY;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -44,11 +44,10 @@

public class NorwegianDateUtilTest {

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

@Test
public void testAdd2DaysWithinSameWeek() {
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 18).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 18).atStartOfDay(ZONE_NORWAY);

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

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

@Test
public void testAdd2DaysBeforeWeekend() {
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 20).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 20).atStartOfDay(ZONE_NORWAY);

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

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

@Test
void testAdd2DaysToLastDayOfMonth() {
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(ZONE_NORWAY);

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

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

@Test
void testAdd5DaysWithNoHolidays() {
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2024, 9, 30).atStartOfDay(ZONE_NORWAY);

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

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

@Test
void testAdd5DaysBeforeEasterHoliday() {
ZonedDateTime zonedDateTime = LocalDate.of(2025, 4, 11).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2025, 4, 11).atStartOfDay(ZONE_NORWAY);

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

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

@Test
void testAdd5DaysBeforeNationalDay() {
ZonedDateTime zonedDateTime = LocalDate.of(2007, 5, 16).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2007, 5, 16).atStartOfDay(ZONE_NORWAY);

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

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

@Test
void testAdd5DaysBeforeChristmas() {
ZonedDateTime zonedDateTime = LocalDate.of(2024, 12, 20).atStartOfDay(NORGESONE);
ZonedDateTime zonedDateTime = LocalDate.of(2024, 12, 20).atStartOfDay(ZONE_NORWAY);

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

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

@Test
public void testWorkingDays() {
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 22).atStartOfDay(NORGESONE)), "Sunday not working day");
assertTrue(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 16).atStartOfDay(NORGESONE)), "Monday is working day");
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2025, 1, 1).atStartOfDay(NORGESONE)), "New years day not working day");
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2007, 4, 8).atStartOfDay(NORGESONE)), "Easter day not working day");
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 22).atStartOfDay(ZONE_NORWAY)), "Sunday not working day");
assertTrue(NorwegianDateUtil.isWorkingDay(LocalDate.of(2024, 9, 16).atStartOfDay(ZONE_NORWAY)), "Monday is working day");
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2025, 1, 1).atStartOfDay(ZONE_NORWAY)), "New years day not working day");
assertFalse(NorwegianDateUtil.isWorkingDay(LocalDate.of(2007, 4, 8).atStartOfDay(ZONE_NORWAY)), "Easter day not working day");
}


Expand Down Expand Up @@ -185,6 +184,6 @@ public void testGetAllNorwegianHolidaysForYear() {
}

private void checkHoliday(LocalDate date) {
assertThat(date.atStartOfDay(NORGESONE), where(NorwegianDateUtil::isHoliday));
assertThat(date.atStartOfDay(ZONE_NORWAY), where(NorwegianDateUtil::isHoliday));
}
}

0 comments on commit cde231a

Please sign in to comment.