From 5217ee4aab22ca106814cd505417cc5ca1054516 Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 17 Apr 2024 17:33:12 +0100 Subject: [PATCH] add last updated to mojang status embed --- package.json | 1 + pnpm-lock.yaml | 7 +++++++ src/app/(pages)/mojang/page.tsx | 2 ++ src/common/time-utils.ts | 11 +++++++++++ src/common/utils.ts | 12 +++++++++--- 5 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/common/time-utils.ts diff --git a/package.json b/package.json index 40f2ea8..dd2e6ed 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "clsx": "^2.1.0", "lucide-react": "^0.368.0", "mcutils-library": "^1.2.1", + "moment": "^2.30.1", "next": "14.2.1", "next-themes": "^0.3.0", "react": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e7f51f2..2cdca15 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ dependencies: mcutils-library: specifier: ^1.2.1 version: 1.2.1(@babel/core@7.24.4)(@types/node@20.12.7) + moment: + specifier: ^2.30.1 + version: 2.30.1 next: specifier: 14.2.1 version: 14.2.1(@babel/core@7.24.4)(react-dom@18.2.0)(react@18.2.0) @@ -3596,6 +3599,10 @@ packages: resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} engines: {node: '>=16 || 14 >=14.17'} + /moment@2.30.1: + resolution: {integrity: sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==} + dev: false + /ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} diff --git a/src/app/(pages)/mojang/page.tsx b/src/app/(pages)/mojang/page.tsx index 2d72758..25974ed 100644 --- a/src/app/(pages)/mojang/page.tsx +++ b/src/app/(pages)/mojang/page.tsx @@ -2,6 +2,7 @@ import { Card } from "@/app/components/card"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/app/components/ui/table"; import { generateEmbed } from "@/common/embed"; import { capitalizeFirstLetter } from "@/common/string-utils"; +import { formatTime } from "@/common/time-utils"; import { cn } from "@/common/utils"; import { CachedEndpointStatus, getMojangEndpointStatus } from "mcutils-library"; import { Metadata } from "next"; @@ -55,6 +56,7 @@ export async function generateMetadata(): Promise { return `**${url}**: ${formatStatus(status)}`; }) .join("\n"); + description += `\n\nUpdated: ${formatTime(new Date())}`; return generateEmbed({ title: "Mojang Status", diff --git a/src/common/time-utils.ts b/src/common/time-utils.ts new file mode 100644 index 0000000..65979fa --- /dev/null +++ b/src/common/time-utils.ts @@ -0,0 +1,11 @@ +import moment from "moment"; + +/** + * Formats the time + * + * @param time the time to format + * @returns the formatted time + */ +export function formatTime(time: Date): string { + return moment(time).format("lll"); +} diff --git a/src/common/utils.ts b/src/common/utils.ts index d084cca..8639f42 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -1,6 +1,12 @@ -import { type ClassValue, clsx } from "clsx" -import { twMerge } from "tailwind-merge" +import { clsx, type ClassValue } from "clsx"; +import { twMerge } from "tailwind-merge"; +/** + * Merge class values together + * + * @param inputs the class values + * @returns the merged class values + */ export function cn(...inputs: ClassValue[]) { - return twMerge(clsx(inputs)) + return twMerge(clsx(inputs)); }