Skip to content

Commit

Permalink
Use Biome.js as main formater/linter
Browse files Browse the repository at this point in the history
# Conflicts:
#	package.json
#	yarn.lock
  • Loading branch information
OzzyCzech committed Oct 8, 2024
1 parent bf034a8 commit 355e88c
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 2,407 deletions.
33 changes: 33 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json",
"vcs": {
"enabled": false,
"clientKind": "git",
"useIgnoreFile": false
},
"files": {
"ignoreUnknown": false,
"include": ["lib/**/*.*", "test/**/*.*", "package.json"]
},
"formatter": {
"enabled": true,
"indentStyle": "tab"
},
"organizeImports": {
"enabled": true
},
"linter": {
"enabled": true,
"rules": {
"recommended": true,
"style": {
"noParameterAssign": "off"
}
}
},
"javascript": {
"formatter": {
"quoteStyle": "double"
}
}
}
44 changes: 26 additions & 18 deletions lib/easter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {DateTime, Interval} from 'luxon';
import * as EasterDate from 'easter-date';
import * as EasterDate from "easter-date";
import { DateTime, Interval } from "luxon";

/**
* Returns the date of Easter Monday for a given year.
Expand All @@ -14,7 +14,9 @@ export function getEasterMonday(year: number): DateTime {
* @param date
*/
export function isEasterMonday(date: DateTime | Date): boolean {
return EasterDate.isEasterMonday(date instanceof Date ? date : date.toJSDate());
return EasterDate.isEasterMonday(
date instanceof Date ? date : date.toJSDate(),
);
}

/**
Expand All @@ -39,7 +41,9 @@ export function getEasterSunday(year: number): DateTime {
* @param date
*/
export function isEasterSunday(date: DateTime | Date): boolean {
return EasterDate.isEasterSunday(date instanceof Date ? date : date.toJSDate());
return EasterDate.isEasterSunday(
date instanceof Date ? date : date.toJSDate(),
);
}

/**
Expand All @@ -55,7 +59,9 @@ export function getHolySaturday(year: number): DateTime {
* @param date
*/
export function isHolySaturday(date: DateTime | Date): boolean {
return EasterDate.isHolySaturday(date instanceof Date ? date : date.toJSDate());
return EasterDate.isHolySaturday(
date instanceof Date ? date : date.toJSDate(),
);
}

/**
Expand Down Expand Up @@ -83,8 +89,8 @@ export function getHollyWeekInterval(year: number): Interval {
const easter = getEaster(year);

return Interval.fromDateTimes(
easter.minus({days: 7}), // Palm Sunday
easter.plus({days: 1}), // Easter Monday
easter.minus({ days: 7 }), // Palm Sunday
easter.plus({ days: 1 }), // Easter Monday
);
}

Expand All @@ -99,22 +105,24 @@ export function isHolyWeek(date: DateTime | Date): boolean {
return false;
}

return interval.start && interval.end ? interval.start <= date && date <= interval.end : false;
return interval.start && interval.end
? interval.start <= date && date <= interval.end
: false;
}

/**
* Names of the days in Holy Week.
*/
const names: Record<string, string> = {
'-7': 'Květná neděle',
'-6': 'Modré pondělí',
'-5': 'Šedivé úterý',
'-4': 'Škaredá středa',
'-3': 'Zelený čtvrtek',
'-2': 'Velký pátek',
'-1': 'Bílá sobota',
'0': 'Velikonoční neděle',
'1': 'Velikonoční pondělí',
"-7": "Květná neděle",
"-6": "Modré pondělí",
"-5": "Šedivé úterý",
"-4": "Škaredá středa",
"-3": "Zelený čtvrtek",
"-2": "Velký pátek",
"-1": "Bílá sobota",
"0": "Velikonoční neděle",
"1": "Velikonoční pondělí",
};

/**
Expand All @@ -124,7 +132,7 @@ const names: Record<string, string> = {
export function getEasterDayName(date: DateTime | Date): string | undefined {
if (isHolyWeek(date)) {
date = date instanceof Date ? DateTime.fromJSDate(date) : date;
const index = date.diff(getEaster(date.year), 'days').as('days');
const index = date.diff(getEaster(date.year), "days").as("days");
return index in names ? names[index] : undefined;
}

Expand Down
23 changes: 16 additions & 7 deletions lib/get-meta.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import {DateTime} from 'luxon';
import {getPublicHoliday, isPublicHoliday} from './holidays.js';
import {getSignificantDay, isSignificantDay, type SignificantDay} from './significant.js';
import {areShopsOpen, getShopsStatus} from './shops.js';
import { DateTime } from "luxon";
import {
getEasterDayName, isEasterMonday, isEasterSunday, isGoodFriday, isHolySaturday, isHolyWeek,
} from './easter.js';
getEasterDayName,
isEasterMonday,
isEasterSunday,
isGoodFriday,
isHolySaturday,
isHolyWeek,
} from "./easter.js";
import { getPublicHoliday, isPublicHoliday } from "./holidays.js";
import { areShopsOpen, getShopsStatus } from "./shops.js";
import {
type SignificantDay,
getSignificantDay,
isSignificantDay,
} from "./significant.js";

export type EasterMetadata = {
name: string | undefined;
Expand All @@ -28,7 +37,7 @@ export type DayMetadata = {
easter?: EasterMetadata | undefined;

// Shops metadata
shops: {areOpen: boolean; status: string};
shops: { areOpen: boolean; status: string };
};

/**
Expand Down
51 changes: 31 additions & 20 deletions lib/holidays.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
import {DateTime} from 'luxon';
import { DateTime } from "luxon";
import {
getEasterDayName, getEasterMonday, getGoodFriday, isEasterMonday, isGoodFriday,
} from './easter.js';
getEasterDayName,
getEasterMonday,
getGoodFriday,
isEasterMonday,
isGoodFriday,
} from "./easter.js";

/**
* Zákon č. 245/2000 Sb., o státních svátcích a národních svátcích České republiky
*/
const holidays: Record<string, string> = {
'0101': 'Den obnovy samostatného českého státu',
'0105': 'Svátek práce',
'0805': 'Den vítězství (1945)',
'0507': 'Den slovanských věrozvěstů Cyrila a Metoděje',
'0607': 'Den upálení mistra Jana Husa (1415)',
'2809': 'Den české státnosti',
'2810': 'Den vzniku samostatného československého státu (1918)',
'1711': 'Den boje za svobodu a demokracii (1939 a 1989)',
'2412': 'Štědrý den',
'2512': 'První svátek vánoční',
'2612': 'Druhý svátek vánoční',
"0101": "Den obnovy samostatného českého státu",
"0105": "Svátek práce",
"0805": "Den vítězství (1945)",
"0507": "Den slovanských věrozvěstů Cyrila a Metoděje",
"0607": "Den upálení mistra Jana Husa (1415)",
"2809": "Den české státnosti",
"2810": "Den vzniku samostatného československého státu (1918)",
"1711": "Den boje za svobodu a demokracii (1939 a 1989)",
"2412": "Štědrý den",
"2512": "První svátek vánoční",
"2612": "Druhý svátek vánoční",
};

/**
Expand All @@ -26,7 +30,11 @@ const holidays: Record<string, string> = {
*/
export function isPublicHoliday(date: DateTime | Date): boolean {
date = date instanceof Date ? DateTime.fromJSDate(date) : date;
return isEasterMonday(date) || isGoodFriday(date) || date.toFormat('ddMM') in holidays;
return (
isEasterMonday(date) ||
isGoodFriday(date) ||
date.toFormat("ddMM") in holidays
);
}

/**
Expand All @@ -43,7 +51,7 @@ export function getPublicHoliday(date: DateTime | Date): string | undefined {
return getEasterDayName(date);
}

return holidays[date.toFormat('ddMM')];
return holidays[date.toFormat("ddMM")];
}

/**
Expand All @@ -54,18 +62,21 @@ export function getPublicHolidaysList(year: number): Map<string, string> {
const list = new Map<string, string>();
for (const date in holidays) {
if (Object.hasOwn(holidays, date)) {
const key = DateTime.fromFormat(date, 'ddMM').set({year}).toISODate();
const key = DateTime.fromFormat(date, "ddMM").set({ year }).toISODate();
if (key !== null) {
list.set(key, holidays[date] ?? '');
list.set(key, holidays[date] ?? "");
}
}
}

const goodFriday = getGoodFriday(year);
list.set(goodFriday.toISODate() ?? '', getEasterDayName(goodFriday) ?? '');
list.set(goodFriday.toISODate() ?? "", getEasterDayName(goodFriday) ?? "");

const easterMonday = getEasterMonday(year);
list.set(easterMonday.toISODate() ?? '', getEasterDayName(easterMonday) ?? '');
list.set(
easterMonday.toISODate() ?? "",
getEasterDayName(easterMonday) ?? "",
);

return list;
}
10 changes: 5 additions & 5 deletions lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './easter.js';
export * from './holidays.js';
export * from './significant.js';
export * from './shops.js';
export * from './get-meta.js';
export * from "./easter.js";
export * from "./holidays.js";
export * from "./significant.js";
export * from "./shops.js";
export * from "./get-meta.js";
26 changes: 13 additions & 13 deletions lib/shops.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import {DateTime} from 'luxon';
import {isEasterMonday} from './easter.js';
import { DateTime } from "luxon";
import { isEasterMonday } from "./easter.js";

/**
* List of days when the shop is closed.
* https://cs.wikipedia.org/wiki/%C4%8Cesk%C3%BD_st%C3%A1tn%C3%AD_sv%C3%A1tek
*/
const closed: Record<string, string> = {
'0101': 'Nový rok',
'0805': 'Den vítězství',
'2809': 'Den české státnosti',
'2810': 'Den vzniku samostatného československého státu',
'2512': '1. svátek vánoční',
'2612': '2. svátek vánoční',
"0101": "Nový rok",
"0805": "Den vítězství",
"2809": "Den české státnosti",
"2810": "Den vzniku samostatného československého státu",
"2512": "1. svátek vánoční",
"2612": "2. svátek vánoční",
};

/**
Expand All @@ -23,16 +23,16 @@ export function getShopsStatus(date: DateTime | Date): string {

// Easter Monday
if (isEasterMonday(date)) {
return 'zavřeno';
return "zavřeno";
}

// Christmas Eve
if (date.toFormat('ddMM') === '2412') {
return 'otevřeno do 12:00';
if (date.toFormat("ddMM") === "2412") {
return "otevřeno do 12:00";
}

// Other closed days
return date.toFormat('ddMM') in closed ? 'zavřeno' : 'otevřeno';
return date.toFormat("ddMM") in closed ? "zavřeno" : "otevřeno";
}

/**
Expand All @@ -41,5 +41,5 @@ export function getShopsStatus(date: DateTime | Date): string {
*/
export function areShopsOpen(date: DateTime | Date): boolean {
date = date instanceof Date ? DateTime.fromJSDate(date) : date;
return getShopsStatus(date).startsWith('otevřeno');
return getShopsStatus(date).startsWith("otevřeno");
}
Loading

0 comments on commit 355e88c

Please sign in to comment.