diff --git a/src/constants/dates.ts b/src/constants/dates.ts new file mode 100644 index 0000000..98def5c --- /dev/null +++ b/src/constants/dates.ts @@ -0,0 +1,38 @@ +import type { IntRange } from '../types/utils'; + +export type SpecialDate = { + month: IntRange<0, 13>; + day: IntRange<0, 32>; +}; + +export type specialDateRange = { + start: SpecialDate; + end: SpecialDate; +}; + +const specialDateNames = ['helloween', 'christmas'] as const; + +export type SpecialDates = (typeof specialDateNames)[number]; + +export const dates: Record = { + helloween: { + start: { + month: 10, + day: 29 + }, + end: { + month: 11, + day: 1 + } + }, + christmas: { + start: { + month: 12, + day: 22 + }, + end: { + month: 12, + day: 26 + } + } +}; diff --git a/src/lib/navbar/Navbar.svelte b/src/lib/navbar/Navbar.svelte index ddbd99d..f0a6b52 100644 --- a/src/lib/navbar/Navbar.svelte +++ b/src/lib/navbar/Navbar.svelte @@ -1,5 +1,7 @@ + + +
(showTooltip = false)} + on:mouseenter={() => (showTooltip = true)} + role="img" + aria-label="Halloween" + > + Halloween +
+
+ +
+

+ " + かぼけゃ + " is marked with + CC0 1.0. +

+
diff --git a/src/lib/specialDates/isInRange.ts b/src/lib/specialDates/isInRange.ts new file mode 100644 index 0000000..1219ded --- /dev/null +++ b/src/lib/specialDates/isInRange.ts @@ -0,0 +1,39 @@ +import { + dates, + type SpecialDate, + type specialDateRange, + type SpecialDates +} from '../../constants/dates'; + +const isAfterDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth > date.month || (currentMonth === date.month && currentDay >= date.day); +}; + +const isBeforeDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth < date.month || (currentMonth === date.month && currentDay <= date.day); +}; + +const isDate = (date: SpecialDate): boolean => { + const currentDay = new Date().getDate(); + const currentMonth = new Date().getMonth() + 1; + return currentMonth === date.month && currentDay === date.day; +}; + +const isInRange = (date: specialDateRange): boolean => { + const { start, end } = date; + return (isAfterDate(start) && isBeforeDate(end)) || isDate(start) || isDate(end); +}; + +export const currentSpecialDates = (d: Record = dates) => { + const currentDates = Object.values(d).filter(isInRange); + const currentDatesNames = Object.keys(d).filter((key) => + currentDates.includes(d[key as SpecialDates]) + ); + return currentDatesNames as SpecialDates[]; +}; + +export const isSpecialDate = (date: SpecialDates): boolean => currentSpecialDates().includes(date); diff --git a/static/assets/pumpkin.svg b/static/assets/pumpkin.svg new file mode 100644 index 0000000..e8a5d9f --- /dev/null +++ b/static/assets/pumpkin.svg @@ -0,0 +1,60 @@ + + + + +Created by potrace 1.15, written by Peter Selinger 2001-2017 + + + + + + + + + + diff --git a/tests/settings.test.ts b/tests/settings.test.ts index 3de876e..fa82a46 100644 --- a/tests/settings.test.ts +++ b/tests/settings.test.ts @@ -66,7 +66,12 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(/.*/); + const navItemHasImg = (await navItem.locator('img').count()) > 0; + if (navItemHasImg) { + await expect(navItem).toHaveText(''); + } else { + await expect(navItem).toHaveText(/.*/); + } } await page.waitForTimeout(300); @@ -82,7 +87,8 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(''); + const navItemHasImg = (await navItem.locator('img').count()) > 0; + if (navItemHasImg) await expect(navItem).toHaveText(''); } await page.reload(); @@ -94,7 +100,8 @@ test('the text in navigion can be toggled and is saved', async ({ page }) => { for (let i = 0; i < navItemsArray.length; i++) { const navItem = navItemsArray[i]; - await expect(navItem).toHaveText(''); + const navItemHasBxIcon = (await navItem.locator('i.bx').count()) > 0; + if (navItemHasBxIcon) await expect(navItem).toHaveText(''); } localator = await page.getByRole('switch');