feat: seasonal features

This commit is contained in:
2023-10-18 11:39:15 +01:00
parent ab50afe917
commit c4bbafb9d7
3 changed files with 31 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import {
MetadataCache,
NostrLink,
} from "@snort/system";
import { Day } from "Const";
export const sha256 = (str: string | Uint8Array): u256 => {
return utils.bytesToHex(hash(str));
@ -469,7 +470,7 @@ export function kvToObject<T>(o: string, sep?: string) {
}
export function defaultAvatar(input?: string) {
return `https://robohash.v0l.io/${input ?? "missing"}.png${IsHalloween() ? "?set=set2" : ""}`;
return `https://robohash.v0l.io/${input ?? "missing"}.png${isHalloween() ? "?set=set2" : ""}`;
}
export function isFormElement(target: HTMLElement): boolean {
@ -480,7 +481,25 @@ export function isFormElement(target: HTMLElement): boolean {
return false;
}
export const IsHalloween = () => {
const ThisYear = new Date().getFullYear();
const SeasonalEventsWindow = 7; // n days before
const IsTheSeason = (target: Date) => {
const now = new Date();
return now.getMonth() === 9 && now.getDate() >= 17;
const days = (target.getTime() - now.getTime()) / (Day * 1000);
return days > 0 && days <= SeasonalEventsWindow;
};
export const isHalloween = () => {
const event = new Date(ThisYear, 9, 31);
return IsTheSeason(event);
};
export const isStPatricksDay = () => {
const event = new Date(ThisYear, 2, 17);
return IsTheSeason(event);
};
export const isChristmas = () => {
const event = new Date(ThisYear, 11, 25);
return IsTheSeason(event);
};