Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/app/components/norwegianFlags.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"use client";

export default function NorwegianFlagsBackground() {
const flags = Array.from({ length: 12 });

return (
<div className="pointer-events-none fixed inset-0 overflow-hidden z-0">
{flags.map((_, i) => (
<span
key={i}
className="absolute animate-norway-float text-3xl opacity-20"
style={{
// eslint-disable-next-line react-hooks/purity
left: `${Math.random() * 100}%`,
animationDelay: `${i * 0.8}s`,
animationDuration: `${10 + (i % 5)}s`,
}}
>
🇳🇴
</span>
))}
</div>
);
}
26 changes: 26 additions & 0 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,29 @@ body {
color: var(--foreground);
font-family: Arial, Helvetica, sans-serif;
}

@keyframes norway-float {
0% {
transform: translateY(110vh) rotate(0deg);
opacity: 0.5;
}

10% {
opacity: 0.7;
}

50% {
opacity: 0.65;
}

100% {
transform: translateY(-20vh) rotate(8deg);
opacity: 0.5;
}
}

.animate-norway-float {
animation-name: norway-float;
animation-timing-function: linear;
animation-iteration-count: infinite;
}
5 changes: 5 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
} from "../lib/calculations";
import Forecast from "./components/forcast";
import LoadingScreen from "./components/LoadingScreen";
import NorwegianFlagsBackground from "./components/norwegianFlags";
import { isSeventeenthOfMay } from "@/lib/time";

export default function Page() {
const now = new Date();
Expand Down Expand Up @@ -105,6 +107,9 @@ export default function Page() {
<main
className={`min-h-screen bg-linear-to-br ${backgroundClass} text-slate-900`}
>
{isSeventeenthOfMay(new Date().toISOString()) && (
<NorwegianFlagsBackground />
)}
<button
className="flex flex-col gap-1 absolute top-4 right-4 focus:outline-none focus:ring-2 focus:ring-slate-400 focus:ring-offset-2 disabled:cursor-not-allowed"
onClick={() => setShowForecast((prev) => !prev)}
Expand Down
13 changes: 13 additions & 0 deletions src/lib/calculations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ForecastPoint } from "@/types/weather";
import { isSeventeenthOfMay } from "@/lib/time";

function calculateTemperature(temperature: number) {
if (temperature < 5) return 0;
Expand Down Expand Up @@ -74,6 +75,10 @@ export function calculateUtepilsScore(
sunsetIso?: string | null,
currentIso?: string,
) {
if (currentIso && isSeventeenthOfMay(currentIso)) {
return 100;
}

let score = 0;

score += calculateTemperature(temperature);
Expand Down Expand Up @@ -117,6 +122,14 @@ export function calculateUtepilsScoreWithoutTime(
}

export function getVerdict(score: number) {
if (score == 100 && isSeventeenthOfMay(new Date().toISOString())) {
return {
title: "Gratulerer med dagen 🇳🇴 ",
subtitle: "Utepils er obligatorisk!",
emoji: "🇳🇴🥂",
};
}

if (score >= 75) {
return {
title: "UTEPILS! 🍻",
Expand Down
13 changes: 12 additions & 1 deletion src/lib/time.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const OSLO_TIMEZONE = "Europe/Oslo";
export const TIMEZONE = OSLO_TIMEZONE;

export function getOsloDayKey(date: Date): string {
return date.toLocaleDateString("sv-SE", {
Expand All @@ -24,4 +25,14 @@ export function formatOsloTime(date: Date): string {
});
}

export const TIMEZONE = OSLO_TIMEZONE;
export function isSeventeenthOfMay(dateInput: string | Date) {
const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;

const osloDate = new Intl.DateTimeFormat("en-CA", {
timeZone: "Europe/Oslo",
month: "2-digit",
day: "2-digit",
}).format(date);

return osloDate === "05-17";
}