feat: add birthday
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Kieran 2023-11-29 12:44:00 +00:00
parent d84843a46d
commit bbcedbd99c
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
3 changed files with 24 additions and 9 deletions

View File

@ -8,6 +8,11 @@ export const Hour = 60 * 60;
*/
export const Day = Hour * 24;
/**
* Day this project started
*/
export const Birthday = new Date(2022, 11, 17);
/**
* Add-on api for snort features
*/

View File

@ -1,14 +1,20 @@
import useLogin from "../../Hooks/useLogin";
import { getCurrentSubscription } from "../../Subscription";
import { isChristmas, isHalloween, isStPatricksDay } from "../../SnortUtils";
import { isBirthday, isChristmas, isHalloween, isStPatricksDay } from "../../SnortUtils";
import { Link } from "react-router-dom";
import { mapPlanName } from "../subscribe";
import Icon from "@/Icons/Icon";
import { unixNowMs } from "@snort/shared";
import { Birthday, Day } from "@/Const";
export function LogoHeader({ showText = false }) {
const { subscriptions } = useLogin();
const currentSubscription = getCurrentSubscription(subscriptions);
const extra = () => {
if (isBirthday()) {
const age = (unixNowMs() - Birthday.getTime()) / (Day * 365_000);
return <span className="text-xs">{age.toFixed(0)}st 🎂</span>;
}
if (isHalloween()) return "🎃";
if (isStPatricksDay()) return "🍀";
if (isChristmas()) return "🎄";
@ -29,8 +35,8 @@ export function LogoHeader({ showText = false }) {
)}
{showText && (
<div className="md:hidden xl:inline ml-2">
{extra()}
{CONFIG.appName}
{extra()}
</div>
)}
</h1>

View File

@ -19,7 +19,7 @@ import {
UserMetadata,
} from "@snort/system";
import { isHex, isOffline } from "@snort/shared";
import { Day } from "@/Const";
import { Birthday, Day } from "@/Const";
import AnimalName from "@/Element/User/AnimalName";
export const sha256 = (str: string | Uint8Array): u256 => {
@ -472,26 +472,30 @@ export function isFormElement(target: HTMLElement): boolean {
}
const ThisYear = new Date().getFullYear();
const SeasonalEventsWindow = 7; // n days before
const IsTheSeason = (target: Date) => {
const IsTheSeason = (target: Date, window: number) => {
const now = new Date();
const days = (target.getTime() - now.getTime()) / (Day * 1000);
return days > 0 && days <= SeasonalEventsWindow;
return (days >= 0 && days <= window) || (now.getDate() === target.getDate() && now.getMonth() === target.getMonth());
};
export const isHalloween = () => {
const event = new Date(ThisYear, 9, 31);
return IsTheSeason(event);
return IsTheSeason(event, 7);
};
export const isStPatricksDay = () => {
const event = new Date(ThisYear, 2, 17);
return IsTheSeason(event);
return IsTheSeason(event, 7);
};
export const isChristmas = () => {
const event = new Date(ThisYear, 11, 25);
return IsTheSeason(event);
return IsTheSeason(event, 30);
};
export const isBirthday = () => {
const event = new Date(ThisYear, Birthday.getMonth(), Birthday.getDate());
return IsTheSeason(event, 1);
};
export function getDisplayName(user: UserMetadata | undefined, pubkey: HexKey): string {