From a4481dcfe988edbeeda8cb8ef0e1b414e13baa35 Mon Sep 17 00:00:00 2001 From: dhaanisi Date: Mon, 23 Feb 2026 21:35:36 +0530 Subject: [PATCH] Add Discord timestamp tool with copy + reverse conversion --- public/locales/en/time.json | 9 +++ .../tools/time/discord-timestamp/index.tsx | 72 +++++++++++++++++++ .../tools/time/discord-timestamp/meta.ts | 15 ++++ .../tools/time/discord-timestamp/service.ts | 16 +++++ .../tools/time/discord-timestamp/types.ts | 7 ++ src/pages/tools/time/index.ts | 4 +- 6 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 src/pages/tools/time/discord-timestamp/index.tsx create mode 100644 src/pages/tools/time/discord-timestamp/meta.ts create mode 100644 src/pages/tools/time/discord-timestamp/service.ts create mode 100644 src/pages/tools/time/discord-timestamp/types.ts diff --git a/public/locales/en/time.json b/public/locales/en/time.json index 1b12044..955dca3 100644 --- a/public/locales/en/time.json +++ b/public/locales/en/time.json @@ -119,5 +119,14 @@ "description": "Convert a formatted time duration (HH:MM:SS) into a decimal hour value.", "shortDescription": "Convert human time to decimal time", "longDescription": "Convert a formatted time string (HH:MM:SS or HH:MM) into its decimal-hour equivalent. Hours can be any positive number, while minutes and seconds accept values from 0-59 and can be single or double digits (e.g., '12:5' or '12:05'). This function interprets hours, minutes, and seconds, then calculates the total duration as a single decimal value. It is useful for productivity tracking, payroll calculations, time-based billing, data analysis, or any workflow that requires converting human-readable time into a numerical format that can be easily summed, compared, or processed. For example, '03:26:00' becomes 3.43 hours, and '12:5' becomes 12.08 hours." + }, + "discordTimestamp": { + "name": "Discord Timestamp Generator", + "description": "Generate Discord formatted timestamps from date and time", + "shortDescription": "Generate Discord timestamps", + "toolInfo": { + "title": "What is a Discord Timestamp", + "description": "Discord timestamps allow you to display dynamic dates and times that automatically adjust to each user's local timezone. This tool converts a date and time into the special Discord timestamp format." + } } } diff --git a/src/pages/tools/time/discord-timestamp/index.tsx b/src/pages/tools/time/discord-timestamp/index.tsx new file mode 100644 index 0000000..c0ee38e --- /dev/null +++ b/src/pages/tools/time/discord-timestamp/index.tsx @@ -0,0 +1,72 @@ +import { useState } from 'react'; + +function convertInput(input: string) { + const trimmed = input.trim(); + + // Case 1: Discord timestamp → normal date + const match = trimmed.match(/^$/); + if (match) { + const unix = Number(match[1]); + const date = new Date(unix * 1000); + if (!isNaN(date.getTime())) { + return date.toISOString().replace('T', ' ').slice(0, 16); + } + } + + // Case 2: normal date → Discord timestamp + const date = new Date(trimmed); + if (isNaN(date.getTime())) return 'Invalid date/time'; + const unix = Math.floor(date.getTime() / 1000); + return ``; +} + +export default function DiscordTimestamp() { + const [value, setValue] = useState(''); + const [copied, setCopied] = useState(false); + + const result = value ? convertInput(value) : ''; + + const handleCopy = async () => { + if (!result || result === 'Invalid date/time') return; + try { + await navigator.clipboard.writeText(result); + setCopied(true); + setTimeout(() => setCopied(false), 1200); + } catch (e) { + console.error('Copy failed', e); + } + }; + + return ( +
+