-
Notifications
You must be signed in to change notification settings - Fork 0
fix: standardize date/time formats across app #84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { format } from "date-fns"; | ||
|
|
||
| /** "Mar 6, 2026" */ | ||
| export function formatDate(date: Date | string): string { | ||
| return format(new Date(date), "MMM d, yyyy"); | ||
| } | ||
|
|
||
| /** "1557" */ | ||
| export function formatTime(date: Date | string): string { | ||
| return format(new Date(date), "HHmm"); | ||
| } | ||
|
|
||
| /** "Mar 6, 2026 1557" */ | ||
| export function formatDateTime(date: Date | string): string { | ||
| return format(new Date(date), "MMM d, yyyy HHmm"); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| import { Resend } from "resend"; | ||
| import { format } from "date-fns"; | ||
| import { type Monitor, type MonitorChange } from "@shared/schema"; | ||
| import { authStorage } from "../replit_integrations/auth/storage"; | ||
| import { type UserTier } from "@shared/models/auth"; | ||
|
|
@@ -258,12 +259,12 @@ export async function sendDigestEmail(monitor: Monitor, changes: MonitorChange[] | |
| const recipientEmail = emailOverride || user.notificationEmail || user.email; | ||
|
|
||
| const changesTextList = changes.map((c, i) => { | ||
| const dateStr = new Date(c.detectedAt).toLocaleString("en-US"); | ||
| const dateStr = format(new Date(c.detectedAt), "MMM d, yyyy HHmm"); | ||
| return ` ${i + 1}. [${dateStr}]\n Old: ${sanitizePlainText(c.oldValue)}\n New: ${sanitizePlainText(c.newValue)}`; | ||
| }).join("\n\n"); | ||
|
|
||
| const changesHtmlList = changes.map((c) => { | ||
| const dateStr = new Date(c.detectedAt).toLocaleString("en-US"); | ||
| const dateStr = format(new Date(c.detectedAt), "MMM d, yyyy HHmm"); | ||
|
Comment on lines
+262
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Date formatting changes are safe and preserve XSS protections. The Minor maintainability note: The format string ♻️ Optional: Extract shared format constantCreate a shared constant (e.g., in export const DATE_TIME_FORMAT = "MMM d, yyyy HHmm";Then import and use in both locations: -import { format } from "date-fns";
+import { format } from "date-fns";
+import { DATE_TIME_FORMAT } from "@shared/constants";-const dateStr = format(new Date(c.detectedAt), "MMM d, yyyy HHmm");
+const dateStr = format(new Date(c.detectedAt), DATE_TIME_FORMAT);🤖 Prompt for AI Agents |
||
| return ` | ||
| <tr> | ||
| <td style="padding: 8px; border: 1px solid #ddd;">${escapeHtml(dateStr)}</td> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Consider adding null/undefined guard to prevent silent failures.
new Date(null)returns Unix epoch (Jan 1, 1970), andnew Date(undefined)returnsInvalid Date. Since callers may pass nullable timestamps (e.g.,lastUsedAtin ApiKeysPanel), a defensive check would prevent unexpected output if the null guard is accidentally removed at call sites.export function formatDate(date: Date | string): string { + if (date == null) { + throw new Error("formatDate received null or undefined"); + } return format(new Date(date), "MMM d, yyyy"); }Alternatively, update the type signature to
Date | string | null | undefinedand return a fallback like"—".🤖 Prompt for AI Agents