From 5c7e16f0e6b6cc909c8b78383d2a84e4539eacc7 Mon Sep 17 00:00:00 2001
From: Zsolt Tasnadi
Date: Fri, 20 Mar 2026 12:43:10 +0100
Subject: [PATCH] common datetime display
---
apps/frontend/src/pages/blog.astro | 17 ++-------------
apps/frontend/src/pages/blog/[...slug].astro | 17 ++-------------
apps/frontend/src/pages/catalog.astro | 17 ++++++++-------
apps/frontend/src/pages/code.astro | 7 +++----
apps/frontend/src/pages/howtos.astro | 17 ++-------------
apps/frontend/src/pages/index.astro | 18 ++++++++--------
apps/frontend/src/utils/dateFormat.ts | 22 ++++++++++++++++++++
7 files changed, 49 insertions(+), 66 deletions(-)
create mode 100644 apps/frontend/src/utils/dateFormat.ts
diff --git a/apps/frontend/src/pages/blog.astro b/apps/frontend/src/pages/blog.astro
index b5ebbff..7ff0f71 100644
--- a/apps/frontend/src/pages/blog.astro
+++ b/apps/frontend/src/pages/blog.astro
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
+import { formatDateTime } from '../utils/dateFormat';
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
const WIKIJS_TOKEN = import.meta.env.WEBAPP_WIKIJS_TOKEN;
@@ -107,20 +108,6 @@ try {
error = `Failed to fetch wiki data: ${e.message}`;
}
-function timeAgo(dateStr: string): string {
- const now = new Date();
- const date = new Date(dateStr);
- const diffMs = now.getTime() - date.getTime();
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMins / 60);
- const diffDays = Math.floor(diffHours / 24);
-
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- if (diffDays < 30) return `${diffDays}d ago`;
- return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
-}
function getPermalink(path: string): string {
const slug = path.startsWith('blog/') ? path.replace('blog/', '') : path;
@@ -195,7 +182,7 @@ function getCleanPreview(content: string): string {
New Post
)}
- {timeAgo(page.createdAt)}
+ {formatDateTime(page.createdAt)}
diff --git a/apps/frontend/src/pages/blog/[...slug].astro b/apps/frontend/src/pages/blog/[...slug].astro
index 291877d..d461ab3 100644
--- a/apps/frontend/src/pages/blog/[...slug].astro
+++ b/apps/frontend/src/pages/blog/[...slug].astro
@@ -1,5 +1,6 @@
---
import Layout from '../../layouts/Layout.astro';
+import { formatDateTime } from '../../utils/dateFormat';
export async function getStaticPaths() {
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
@@ -110,20 +111,6 @@ try {
error = e.message;
}
-function timeAgo(dateStr: string): string {
- const now = new Date();
- const date = new Date(dateStr);
- const diffMs = now.getTime() - date.getTime();
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMins / 60);
- const diffDays = Math.floor(diffHours / 24);
-
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- if (diffDays < 30) return `${diffDays}d ago`;
- return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
-}
---
@@ -147,7 +134,7 @@ function timeAgo(dateStr: string): string {
{pageContent.description}
- {timeAgo(pageContent.createdAt)}
+ {formatDateTime(pageContent.createdAt)}
>
)}
diff --git a/apps/frontend/src/pages/catalog.astro b/apps/frontend/src/pages/catalog.astro
index a854edf..0101a58 100644
--- a/apps/frontend/src/pages/catalog.astro
+++ b/apps/frontend/src/pages/catalog.astro
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
+import { formatDateTime } from '../utils/dateFormat';
const BASE = "https://games.teletype.hu";
const API = BASE + "/api/software";
@@ -90,8 +91,8 @@ const softwares = json.softwares;
{stableReleases.map((release: any) => (
| {release.version} |
- {new Date(release.CreatedAt).toLocaleDateString('en-US')} |
- {new Date(release.UpdatedAt).toLocaleDateString('en-US')} |
+ {formatDateTime(release.CreatedAt)} |
+ {formatDateTime(release.UpdatedAt)} |
{release.htmlFolderPath ? (▶ Play) : (▶ Play)}
{release.cartridgePath ? (Download) : (Download)}
@@ -108,8 +109,8 @@ const softwares = json.softwares;
{devReleases.map((release: any) => (
|
| {release.version} |
- {new Date(release.CreatedAt).toLocaleDateString('en-US')} |
- {new Date(release.UpdatedAt).toLocaleDateString('en-US')} |
+ {formatDateTime(release.CreatedAt)} |
+ {formatDateTime(release.UpdatedAt)} |
{release.htmlFolderPath ? (▶ Play) : (▶ Play)}
{release.cartridgePath ? (Download) : (Download)}
@@ -128,8 +129,8 @@ const softwares = json.softwares;
{release.htmlFolderPath ? ( ▶ Play) : ( ▶ Play)}
@@ -146,8 +147,8 @@ const softwares = json.softwares;
{release.htmlFolderPath ? ( ▶ Play) : ( ▶ Play)}
diff --git a/apps/frontend/src/pages/code.astro b/apps/frontend/src/pages/code.astro
index f338ddb..98297c7 100644
--- a/apps/frontend/src/pages/code.astro
+++ b/apps/frontend/src/pages/code.astro
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
+import { formatDateTime } from '../utils/dateFormat';
const GITEA_API_BASE_URL = 'https://git.teletype.hu/api/v1';
const GITEA_TOKEN = import.meta.env.WEBAPP_GITEA_TOKEN;
@@ -152,7 +153,7 @@ const recentCommits = allCommits.slice(0, 20);
{repo.description && {repo.description} }
{repo.language && Language: {repo.language} }
- Updated: {new Date(repo.updated_at).toLocaleDateString('en-US', {year: 'numeric', month: 'short', day: 'numeric'})}
+ Updated: {formatDateTime(repo.updated_at)}
))}
@@ -178,9 +179,7 @@ const recentCommits = allCommits.slice(0, 20);
: {commit.message.split('\n')[0]}
- Authored by {commit.author.name} on {new Date(commit.date).toLocaleDateString('en-US', {
- year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit'
- })}
+ Authored by {commit.author.name} on {formatDateTime(commit.date)}
{commit.sha.substring(0, 7)}
diff --git a/apps/frontend/src/pages/howtos.astro b/apps/frontend/src/pages/howtos.astro
index bd68e48..4af5301 100644
--- a/apps/frontend/src/pages/howtos.astro
+++ b/apps/frontend/src/pages/howtos.astro
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
+import { formatDateTime } from '../utils/dateFormat';
const WIKIJS_BASE_URL = 'https://wiki.teletype.hu';
const WIKIJS_TOKEN = import.meta.env.WEBAPP_WIKIJS_TOKEN;
@@ -77,20 +78,6 @@ try {
error = `Failed to fetch wiki data: ${e.message}`;
}
-function timeAgo(dateStr: string): string {
- const now = new Date();
- const date = new Date(dateStr);
- const diffMs = now.getTime() - date.getTime();
- const diffMins = Math.floor(diffMs / 60000);
- const diffHours = Math.floor(diffMins / 60);
- const diffDays = Math.floor(diffHours / 24);
-
- if (diffMins < 1) return 'just now';
- if (diffMins < 60) return `${diffMins}m ago`;
- if (diffHours < 24) return `${diffHours}h ago`;
- if (diffDays < 30) return `${diffDays}d ago`;
- return date.toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' });
-}
---
@@ -162,7 +149,7 @@ function timeAgo(dateStr: string): string {
New
)}
- {timeAgo(page.updatedAt)}
+ {formatDateTime(page.updatedAt)}
diff --git a/apps/frontend/src/pages/index.astro b/apps/frontend/src/pages/index.astro
index 040efae..366b532 100644
--- a/apps/frontend/src/pages/index.astro
+++ b/apps/frontend/src/pages/index.astro
@@ -1,5 +1,6 @@
---
import Layout from '../layouts/Layout.astro';
+import { formatDateTime } from '../utils/dateFormat';
import fs from 'node:fs';
import path from 'node:path';
import yaml from 'js-yaml';
@@ -43,19 +44,13 @@ try {
name: first.name,
date: first.date,
dateISO: first.dateObj.toISOString(),
- dateText: first.dateObj.toLocaleString('en-US', {
- year: 'numeric', month: 'short', day: 'numeric',
- hour: '2-digit', minute: '2-digit'
- })
+ dateText: formatDateTime(first.dateObj)
};
followingEvents = futureEvents.slice(1).map(e => ({
name: e.name,
date: e.date,
- dateText: e.dateObj.toLocaleString('en-US', {
- year: 'numeric', month: 'short', day: 'numeric',
- hour: '2-digit', minute: '2-digit'
- })
+ dateText: formatDateTime(e.dateObj)
}));
}
}
@@ -567,7 +562,12 @@ const YOUTUBE_CHANNEL_ID = import.meta.env.YOUTUBE_CHANNEL_ID;
function formatDate(iso) {
const d = new Date(iso);
- return d.toLocaleDateString('en-US', { year:'numeric', month:'long', day:'numeric' });
+ const y = d.getFullYear();
+ const m = String(d.getMonth() + 1).padStart(2, '0');
+ const day = String(d.getDate()).padStart(2, '0');
+ const h = String(d.getHours()).padStart(2, '0');
+ const min = String(d.getMinutes()).padStart(2, '0');
+ return `${y}-${m}-${day} ${h}:${min}`;
}
function formatViews(n) {
diff --git a/apps/frontend/src/utils/dateFormat.ts b/apps/frontend/src/utils/dateFormat.ts
new file mode 100644
index 0000000..c9ef195
--- /dev/null
+++ b/apps/frontend/src/utils/dateFormat.ts
@@ -0,0 +1,22 @@
+// Központi dátum formátum konfiguráció
+// A formátum megváltoztatásához csak itt kell módosítani.
+export const DATETIME_FORMAT = 'YYYY-MM-DD HH:mm';
+export const DATE_FORMAT = 'YYYY-MM-DD';
+
+export function formatDateTime(dateStr: string | Date): string {
+ const d = new Date(dateStr as string);
+ const year = d.getFullYear();
+ const month = String(d.getMonth() + 1).padStart(2, '0');
+ const day = String(d.getDate()).padStart(2, '0');
+ const hours = String(d.getHours()).padStart(2, '0');
+ const minutes = String(d.getMinutes()).padStart(2, '0');
+ return `${year}-${month}-${day} ${hours}:${minutes}`;
+}
+
+export function formatDate(dateStr: string | Date): string {
+ const d = new Date(dateStr as string);
+ const year = d.getFullYear();
+ const month = String(d.getMonth() + 1).padStart(2, '0');
+ const day = String(d.getDate()).padStart(2, '0');
+ return `${year}-${month}-${day}`;
+}
|