Skip to content

Commit

Permalink
Upgrade shops function name
Browse files Browse the repository at this point in the history
  • Loading branch information
OzzyCzech committed Apr 11, 2024
1 parent 98ea452 commit b8751d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/shops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const closed: Record<string, string> = {
* Returns the shop status for the given date.
* @param date
*/
export function getShopStatus(date: DateTime): string {
export function getShopsStatus(date: DateTime): string {
// Easter Monday
if (isEasterMonday(date)) {
return "zavřeno";
Expand All @@ -37,6 +37,6 @@ export function getShopStatus(date: DateTime): string {
* Returns true if the given date is a shop open day.
* @param date
*/
export function isOpen(date: DateTime): boolean {
return getShopStatus(date).startsWith("otevřeno")
export function areShopsOpen(date: DateTime): boolean {
return getShopsStatus(date).startsWith("otevřeno")
}
26 changes: 13 additions & 13 deletions test/shops.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import test from 'ava';
import {DateTime} from "luxon";
import {getShopStatus, isOpen} from "../lib/shops.js";
import {getShopsStatus, areShopsOpen} from "../lib/shops.js";

test('Check shops open/close status', t => {
t.is(getShopStatus(DateTime.fromISO('2024-12-25')), 'zavřeno');
t.is(getShopStatus(DateTime.fromISO('2024-12-26')), 'zavřeno');
t.is(getShopStatus(DateTime.fromISO('2024-05-01')), 'otevřeno');
t.is(getShopsStatus(DateTime.fromISO('2024-12-25')), 'zavřeno');
t.is(getShopsStatus(DateTime.fromISO('2024-12-26')), 'zavřeno');
t.is(getShopsStatus(DateTime.fromISO('2024-05-01')), 'otevřeno');
});

test('Check if Easter Monday is closed and Friday is not', t => {
t.is(getShopStatus(DateTime.fromISO('2024-03-28')), 'otevřeno'); // Friday
t.is(getShopStatus(DateTime.fromISO('2024-04-01')), 'zavřeno'); // Monday
t.is(getShopsStatus(DateTime.fromISO('2024-03-28')), 'otevřeno'); // Friday
t.is(getShopsStatus(DateTime.fromISO('2024-04-01')), 'zavřeno'); // Monday
})

test('Check if Christmas Eve is open until noon', t => {
t.is(getShopStatus(DateTime.fromISO('2024-12-24')), 'otevřeno do 12:00');
t.is(getShopStatus(DateTime.fromISO('2025-12-24')), 'otevřeno do 12:00');
t.is(getShopsStatus(DateTime.fromISO('2024-12-24')), 'otevřeno do 12:00');
t.is(getShopsStatus(DateTime.fromISO('2025-12-24')), 'otevřeno do 12:00');
})

test('Check if shops are open or closed', t => {
// open days
t.true(isOpen(DateTime.fromISO('2024-12-24'))); // Christmas Eve is open until noon
t.true(isOpen(DateTime.fromISO('2024-05-01'))); // Labour Day
t.true(isOpen(DateTime.fromISO('2024-11-17'))); // Struggle for Freedom and Democracy Day
t.true(areShopsOpen(DateTime.fromISO('2024-12-24'))); // Christmas Eve is open until noon
t.true(areShopsOpen(DateTime.fromISO('2024-05-01'))); // Labour Day
t.true(areShopsOpen(DateTime.fromISO('2024-11-17'))); // Struggle for Freedom and Democracy Day

// closed days
t.false(isOpen(DateTime.fromISO('2024-01-01')));
t.false(isOpen(DateTime.fromISO('2024-12-26')));
t.false(areShopsOpen(DateTime.fromISO('2024-01-01')));
t.false(areShopsOpen(DateTime.fromISO('2024-12-26')));
});

0 comments on commit b8751d4

Please sign in to comment.