diff --git a/frontend/src/components/WeatherData.tsx b/frontend/src/components/WeatherData.tsx index 665d42d..458a993 100644 --- a/frontend/src/components/WeatherData.tsx +++ b/frontend/src/components/WeatherData.tsx @@ -1,5 +1,6 @@ import React from "react"; import { Sunrise, Sunset } from "lucide-react"; +import { getDateTime } from "../utils/utils"; const WeatherData: React.FC = () => { const weatherRaw = localStorage.getItem("weather"); @@ -75,6 +76,11 @@ const WeatherData: React.FC = () => { : "--:--"} +
+ + Last updated: {getDateTime()} + +
diff --git a/frontend/src/utils/utils.ts b/frontend/src/utils/utils.ts new file mode 100644 index 0000000..4b572af --- /dev/null +++ b/frontend/src/utils/utils.ts @@ -0,0 +1,24 @@ +export const getDateTime = () => { + const now = new Date(); + const day = now.getDate(); + const month = now.toLocaleString("en-GB", { month: "long" }); + const hours = now.getHours().toString().padStart(2, "0"); + const minutes = now.getMinutes().toString().padStart(2, "0"); + + // Ordinal suffix + const getOrdinal = (n: number) => { + if (n > 3 && n < 21) return "th"; + switch (n % 10) { + case 1: + return "st"; + case 2: + return "nd"; + case 3: + return "rd"; + default: + return "th"; + } + }; + + return `${day}${getOrdinal(day)} ${month}, ${hours}:${minutes}`; +};