Skip to content

Commit

Permalink
Merge pull request #467 from focus-shift/462-new-holiday-types
Browse files Browse the repository at this point in the history
Add new holiday type bank and rename official holiday to public holiday
  • Loading branch information
derTobsch authored Sep 3, 2024
2 parents 51fac4f + d5cfef3 commit 29938b5
Show file tree
Hide file tree
Showing 51 changed files with 300 additions and 271 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,40 @@ To access the public holidays of a subdivision of a country, e.g. Baden-Württem
| Subdivisions ([ISO 3166-2]) | Yes |
| City Holiday | Yes |

## Holiday types

The following holiday types are supported:

**Public Holiday**
Public holidays are days when most of the public enjoys a paid non-working days. These days are determined by local laws
and regulations. Countries use various names for these official non-working days, such as:

| Other Names for Public Holiday | Country | Businesses |
|--------------------------------|------------------|------------|
| Bank Holiday | United Kingdom | Closed |
| National Holiday | Most Countries | Closed |
| Red Days | Norway | Closed |
| Regular Holidays | Philippines | Closed |
| Restricted Holidays | India | Closed |
| Statutory Holiday | Canada | Closed |

We will declare all of these as **Public Holiday**

**Bank Holiday**
Bank holidays are days when financial institutions and government offices (and government-regulated businesses)
are closed as determined by local laws and regulations. Other businesses, such as offices and retail stores,
may also be closed on these days, though are not mandated to by local laws and regulations.

**Observance**
Observance, is a celebration or commemoration that doesn't include a day off from work. When people celebrate or
commemorate something, but do not have a day off from work for that reason, we call it an observance.
There are different types of observance like Religious, Secular, Awareness, International or National observance.
We will declare all of these as **Observance**

**Unofficial Holidays**
Holidays which are not public or bank holidays. Unofficial holidays are deprecated and will be replaced by the other types over time.


## Development

If you want to **support** us at the development on **jollyday** than take a look at [Contributing to jollyday](./CONTRIBUTING.md).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package de.focus_shift.jollyday.core;

/**
* Type of holiday. Each holiday can be placed in a category and this is
* represented by this type. The categories can mark a holiday as a official
* holiday or not.
* Type of holiday.
* Each holiday can be placed in a category and this is represented by this type.
*/
public enum HolidayType {

OFFICIAL_HOLIDAY {
@Override
public boolean isOfficialHoliday() {
return true;
}
},
PUBLIC_HOLIDAY,

UNOFFICIAL_HOLIDAY {
@Override
public boolean isOfficialHoliday() {
return false;
}
};
BANK_HOLIDAY,

public abstract boolean isOfficialHoliday();
OBSERVANCE,

@Deprecated(since = "0.31.0", forRemoval = true)
UNOFFICIAL_HOLIDAY;
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Set<Holiday> getHolidays(final Year year, final String... args) {
final LocalDate twoDaysLater = holiday.getDate().plusDays(2);
if (CalendarUtil.contains(holidays, twoDaysLater)) {
final LocalDate bridgingDate = twoDaysLater.minusDays(1);
additionalHolidays.add(new Holiday(bridgingDate, BRIDGING_HOLIDAY_PROPERTIES_KEY, HolidayType.OFFICIAL_HOLIDAY));
additionalHolidays.add(new Holiday(bridgingDate, BRIDGING_HOLIDAY_PROPERTIES_KEY, HolidayType.PUBLIC_HOLIDAY));
}
}
holidays.addAll(additionalHolidays);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@

<xsd:simpleType name="HolidayType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="OFFICIAL_HOLIDAY"/>
<xsd:enumeration value="PUBLIC_HOLIDAY"/>
<xsd:enumeration value="BANK_HOLIDAY"/>
<xsd:enumeration value="OBSERVANCE"/>
<xsd:enumeration value="UNOFFICIAL_HOLIDAY"/>
</xsd:restriction>
</xsd:simpleType>
Expand Down Expand Up @@ -238,7 +240,7 @@
<xsd:attribute name="validTo" type="xsd:int"/>
<xsd:attribute name="every" type="HolidayCycleType" default="EVERY_YEAR"/>
<xsd:attribute name="descriptionPropertiesKey" type="xsd:string"/>
<xsd:attribute name="localizedType" type="HolidayType" default="OFFICIAL_HOLIDAY"/>
<xsd:attribute name="localizedType" type="HolidayType" default="PUBLIC_HOLIDAY"/>
</xsd:complexType>

<xsd:simpleType name="Substituted">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.time.LocalDate;
import java.util.Locale;

import static de.focus_shift.jollyday.core.HolidayType.OFFICIAL_HOLIDAY;
import static de.focus_shift.jollyday.core.HolidayType.PUBLIC_HOLIDAY;
import static de.focus_shift.jollyday.core.HolidayType.UNOFFICIAL_HOLIDAY;
import static java.util.Locale.ENGLISH;
import static java.util.Locale.GERMAN;
Expand All @@ -15,53 +15,53 @@ class HolidayTest {

@Test
void testComparable() {
final Holiday holiday = new Holiday(LocalDate.of(2015, 1, 1), null, OFFICIAL_HOLIDAY);
final Holiday holiday = new Holiday(LocalDate.of(2015, 1, 1), null, PUBLIC_HOLIDAY);
assertThat(holiday).isInstanceOf(Comparable.class);
}

@Test
void testCompareToLess() {
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, OFFICIAL_HOLIDAY);
final Holiday christmas = new Holiday(LocalDate.of(2015, 12, 25), null, OFFICIAL_HOLIDAY);
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, PUBLIC_HOLIDAY);
final Holiday christmas = new Holiday(LocalDate.of(2015, 12, 25), null, PUBLIC_HOLIDAY);
assertThat(newYear).isLessThan(christmas);
}

@Test
void testCompareToGreater() {
final Holiday christmas = new Holiday(LocalDate.of(2015, 12, 25), null, OFFICIAL_HOLIDAY);
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, OFFICIAL_HOLIDAY);
final Holiday christmas = new Holiday(LocalDate.of(2015, 12, 25), null, PUBLIC_HOLIDAY);
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, PUBLIC_HOLIDAY);
assertThat(christmas).isGreaterThan(newYear);
}

@Test
void testCompareToEqual() {
final Holiday firstDayOfYear = new Holiday(LocalDate.of(2015, 1, 1), null, OFFICIAL_HOLIDAY);
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, OFFICIAL_HOLIDAY);
final Holiday firstDayOfYear = new Holiday(LocalDate.of(2015, 1, 1), null, PUBLIC_HOLIDAY);
final Holiday newYear = new Holiday(LocalDate.of(2015, 1, 1), null, PUBLIC_HOLIDAY);
assertThat(firstDayOfYear).isEqualByComparingTo(newYear);
}

@Test
void testHolidayDescription() {
Locale.setDefault(ENGLISH);

final Holiday holiday = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", OFFICIAL_HOLIDAY);
final Holiday holiday = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY);
assertThat(holiday.getDescription()).isEqualTo("Christmas");
assertThat(holiday.getDescription(GERMAN)).isEqualTo("Weihnachten");
assertThat(holiday.getDescription(new Locale("nl"))).isEqualTo("Kerstmis");
}

@Test
void testHolidayEquals() {
final Holiday h1 = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", OFFICIAL_HOLIDAY);
final Holiday h1 = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY);
assertThat(h1).isEqualTo(h1);

final Holiday h2b = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", OFFICIAL_HOLIDAY);
final Holiday h2b = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", PUBLIC_HOLIDAY);
assertThat(h1).isEqualTo(h2b);

final Holiday h2 = new Holiday(LocalDate.of(2011, 2, 1), "CHRISTMAS", OFFICIAL_HOLIDAY);
final Holiday h2 = new Holiday(LocalDate.of(2011, 2, 1), "CHRISTMAS", PUBLIC_HOLIDAY);
assertThat(h1).isNotEqualTo(h2);

final Holiday h3 = new Holiday(LocalDate.of(2011, 2, 2), "NEW_YEAR", OFFICIAL_HOLIDAY);
final Holiday h3 = new Holiday(LocalDate.of(2011, 2, 2), "NEW_YEAR", PUBLIC_HOLIDAY);
assertThat(h1).isNotEqualTo(h3);

final Holiday h4 = new Holiday(LocalDate.of(2011, 2, 2), "CHRISTMAS", UNOFFICIAL_HOLIDAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public String descriptionPropertiesKey() {

@Override
public HolidayType officiality() {
return HolidayType.OFFICIAL_HOLIDAY;
return HolidayType.PUBLIC_HOLIDAY;
}
};

final Holiday holiday = new CreateHoliday(LocalDate.of(2020, 4, 1)).apply(described);

assertThat(holiday.getDate()).hasYear(2020).hasMonth(APRIL).hasDayOfMonth(1);
assertThat(holiday.getType()).isEqualTo(HolidayType.OFFICIAL_HOLIDAY);
assertThat(holiday.getType()).isEqualTo(HolidayType.PUBLIC_HOLIDAY);
assertThat(holiday.getPropertiesKey()).isEqualTo("propertiesKey");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return christianHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(christianHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return ethiopianOrthodoxHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(ethiopianOrthodoxHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayBetweenFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayBetweenFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayInMonth.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayInMonth.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayRelativeToFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayRelativeToFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return islamicHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(islamicHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToEasterSunday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToEasterSunday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToWeekdayInMonth.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToWeekdayInMonth.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void setDescriptionPropertiesKey(String value) {
*/
public HolidayType getLocalizedType() {
if (localizedType == null) {
return HolidayType.OFFICIAL_HOLIDAY;
return HolidayType.PUBLIC_HOLIDAY;
} else {
return localizedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

public enum HolidayType {

OFFICIAL_HOLIDAY,
PUBLIC_HOLIDAY,
BANK_HOLIDAY,
OBSERVANCE,
UNOFFICIAL_HOLIDAY;

public String value() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return christianHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(christianHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return ethiopianOrthodoxHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(ethiopianOrthodoxHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayBetweenFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayBetweenFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayInMonth.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayInMonth.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return fixedWeekdayRelativeToFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(fixedWeekdayRelativeToFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return islamicHoliday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(islamicHoliday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToEasterSunday.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToEasterSunday.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToFixed.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToFixed.getLocalizedType().name());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public String descriptionPropertiesKey() {
@Override
public HolidayType officiality() {
return relativeToWeekdayInMonth.getLocalizedType() == null
? HolidayType.OFFICIAL_HOLIDAY
? HolidayType.PUBLIC_HOLIDAY
: HolidayType.valueOf(relativeToWeekdayInMonth.getLocalizedType().name());
}

Expand Down
Loading

0 comments on commit 29938b5

Please sign in to comment.