Skip to content

Commit

Permalink
Update readme.md
Browse files Browse the repository at this point in the history
  • Loading branch information
OzzyCzech committed Apr 11, 2024
1 parent 49f598d commit c7272b2
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
9 changes: 9 additions & 0 deletions lib/easter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ export function getEasterSunday(year: number): DateTime {
return DateTime.fromObject({year, month, day});
}

/**
* Returns true if the given date is Easter Sunday.
* @param date
*/
export function isEasterSunday(date: DateTime | Date): boolean {
date = date instanceof Date ? DateTime.fromJSDate(date) : date;
return date.equals(getEasterSunday(date.year));
}

/**
* Returns the date of Holy Saturday for a given year.
* @param year
Expand Down
6 changes: 3 additions & 3 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {getNameDayArray} from "./names.js";
import {isPublicHoliday, getPublicHoliday} from "./holidays.js";
import {getSignificantDay, isSignificantDay} from "./significant.js";
import {areShopsOpen, getShopsStatus} from "./shops.js";
import {getEasterDayName, isEasterMonday, isGoodFriday, isHolySaturday, isHolyWeek} from "./easter.js";
import {getEasterDayName, isEasterMonday, isEasterSunday, isGoodFriday, isHolySaturday, isHolyWeek} from "./easter.js";

interface Easter {
name: string | undefined;
isGoodFriday: boolean;
isHolySaturday: boolean;
isHolySunday: boolean;
ieEasterSunday: boolean;
isEasterMonday: boolean;
}

Expand Down Expand Up @@ -53,7 +53,7 @@ export function getDayMeta(date: DateTime | Date): DayMetadata {
name: getEasterDayName(date),
isGoodFriday: isGoodFriday(date),
isHolySaturday: isHolySaturday(date),
isHolySunday: isHolySaturday(date),
ieEasterSunday: isEasterSunday(date),
isEasterMonday: isEasterMonday(date),
}
}
Expand Down
77 changes: 56 additions & 21 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Holidays (cs)

Public holidays, Easter, name days and important days in the Czech Republic.

## Functions

All functions are available in the main module. You can import them like this:
Expand All @@ -18,26 +20,21 @@ you can use the `response.toJSDate()` method.
You can get the name day for a given date:

```javascript
import {DateTime} from 'luxon';
import {getNameDay, getNameDayArray} from 'holidays-cs';

getNameDay(new Date(2024, 11, 24)); // Adam a Eva
getNameDayArray(new Date(2024, 11, 24)); // [ 'Adam', 'Eva' ]
// String of name days
getNameDay(DateTime.fromISO('2024-12-24')); // Adam a Eva
getNameDay(DateTime.fromISO('2024-12-24'), ', '); // Adam, Eva

// Array of name days
getNameDayArray(DateTime.fromISO('2024-12-24')); // ['Adam', 'Eva']
```

## Easter

Easter Monday and Good Friday are public holidays in the Czech Republic.

```javascript
import {DateTime} from 'luxon';
import {isEasterMonday, isGoodFriday} from 'holidays-cs';

// 29. march 2024 - Good Friday
isGoodFriday(DateTime.fromISO('2024-03-29')); // true

// 1. april 2024 - Easter Monday
isEasterMonday(DateTime.fromISO('2024-04-01')); // true
```
**Easter Monday** (Velikonoční pondělí) and **Good Friday** (Velký pátek)
are public holidays in the Czech Republic.

### Easter date

Expand All @@ -50,14 +47,49 @@ getEaster(2024).toISODate(); // 2024-03-31
getEaster(2025).toISODate(); // 2025-04-20
```

### Easter days

```javascript
import {getGoodFriday, getHolySaturday, getEasterSunday, getEaster, getEasterMonday} from 'holidays-cs';

getGoodFriday(2024).toISODate(); // 2024-03-29
getHolySaturday(2024).toISODate(); // 2024-03-30

// Easter Sunday and Easter are the same
getEasterSunday(2024).toISODate(); // 2024-03-31
getEaster(2024).toISODate(); // 2024-03-31

getEasterMonday(2024).toISODate(); // 2024-04-01
```

You can also check if a given date is Good Friday, Holy Saturday, Easter Sunday or Easter Monday:

```javascript
import {isGoodFriday, isHolySaturday, isEasterSunday, isEasterMonday} from 'holidays-cs';
import {DateTime} from 'luxon';


// 29. march 2024 - Good Friday
isGoodFriday(DateTime.fromISO('2024-03-29')); // true

// 30. march 2024 - Holy Saturday
isHolySaturday(DateTime.fromISO('2024-03-30')); // true

// 31. march 2024 - Easter Sunday
isEasterSunday(DateTime.fromISO('2024-03-31')); // true

// 1. april 2024 - Easter Monday
isEasterMonday(DateTime.fromISO('2024-04-01')); // true
```

### Holy Week

You can also check if given date is part of the Holy Week.
Holy Week is the week before Easter plus Easter Monday.
Starts with Palm Sunday and ends with Easter Monday.

```javascript
import {isHolyWeek} from 'holidays-cs';
import {isHolyWeek, getHollyWeekInterval} from 'holidays-cs';

// 29. march 2024
isHolyWeek(DateTime.fromISO('2024-03-29')); // true it's Good Friday
Expand All @@ -69,6 +101,7 @@ getHollyWeekInterval(2024) // {start: DateTime, end: DateTime}
You can also get the name of the day in the Holy Week:

```javascript
import {DateTime} from 'luxon';
import {getEasterDayName} from 'holidays-cs';

getEasterDayName(DateTime.fromISO('2024-03-29')); // Velký pátek
Expand All @@ -77,17 +110,18 @@ getEasterDayName(DateTime.fromISO('2024-03-29')); // Velký pátek
## Czech public holidays

```javascript
import {DateTime} from 'luxon';
import {isPublicHoliday, getPublicHoliday} from 'holidays-cs';

// 1. january
isPublicHoliday(new Date(2024, 0, 1)); // true
isPublicHoliday(DateTime.fromISO('2024-01-01')); // true

// 2. january
isPublicHoliday(new Date(2024, 0, 2)); // false
isPublicHoliday(DateTime.fromISO('2024-01-02')); // false

// 17. november
isPublicHoliday(new Date(2024, 10, 17)); // true
getPublicHoliday(new Date(2024, 10, 17)); // Den boje za svobodu a demokracii (1939 a 1989)
isPublicHoliday(DateTime.fromISO('2024-11-17')); // true
getPublicHoliday(DateTime.fromISO('2024-11-17')); // Den boje za svobodu a demokracii (1939 a 1989)
```

### Shops status
Expand All @@ -99,12 +133,13 @@ import {DateTime} from 'luxon';
import {areShopsOpen, getShopsStatus} from 'holidays-cs';

// 24. december 2024
areShopsOpen(new Date(2024, 11, 24)); // true
areShopsOpen(DateTime.fromISO('2024-12-24')); // true

// 25. december 2024
getShopsStatus(new Date(2024, 11, 25)); // otevřeno do 12:00
getShopsStatus(DateTime.fromISO('2024-12-25')); // otevřeno do 12:00

// New Year's Day 2025
areShopsOpen(DateTime.fromISO('2025-01-01')); // false
getShopsStatus(DateTime.fromISO('2025-01-01')); // zavřeno
```

Expand Down
6 changes: 4 additions & 2 deletions test/day-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ test("Christmas Eve in 2024", t => {
test('Easter Monday in 2024', t => {
const meta = getDayMeta(DateTime.fromISO('2024-04-01'));


if (meta.easter) {
t.is(meta.easter.name, 'Velikonoční pondělí');
t.is(meta.easter.isGoodFriday, false);
t.is(meta.easter.isHolySaturday, false);
t.is(meta.easter.isHolySunday, false);
t.is(meta.easter.ieEasterSunday, false);
t.is(meta.easter.isEasterMonday, true);
} else {
t.fail('Easter Monday expected');
}

t.is(meta.publicHoliday, 'Velikonoční pondělí');
t.false(meta.shops.areOpen);
});

0 comments on commit c7272b2

Please sign in to comment.