Skip to content

Commit 02bd530

Browse files
committed
DateTimeAccurate now renders more compactly (no , after date)
1 parent b01bbff commit 02bd530

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

apps/webapp/app/components/primitives/DateTime.tsx

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,11 @@ export const SmartDateTime = ({ date, previousDate = null, hour12 = true }: Date
196196
? formatSmartDateTime(realDate, userTimeZone, locales, hour12)
197197
: formatTimeOnly(realDate, userTimeZone, locales, hour12);
198198

199-
return <span suppressHydrationWarning>{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}</span>;
199+
return (
200+
<span suppressHydrationWarning>
201+
{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}
202+
</span>
203+
);
200204
};
201205

202206
// Helper function to check if two dates are on the same day
@@ -270,14 +274,18 @@ const DateTimeAccurateInner = ({
270274
return hideDate
271275
? formatTimeOnly(realDate, displayTimeZone, locales, hour12)
272276
: realPrevDate
273-
? isSameDay(realDate, realPrevDate)
274-
? formatTimeOnly(realDate, displayTimeZone, locales, hour12)
275-
: formatDateTimeAccurate(realDate, displayTimeZone, locales, hour12)
276-
: formatDateTimeAccurate(realDate, displayTimeZone, locales, hour12);
277+
? isSameDay(realDate, realPrevDate)
278+
? formatTimeOnly(realDate, displayTimeZone, locales, hour12)
279+
: formatDateTimeAccurate(realDate, displayTimeZone, locales, hour12)
280+
: formatDateTimeAccurate(realDate, displayTimeZone, locales, hour12);
277281
}, [realDate, displayTimeZone, locales, hour12, hideDate, previousDate]);
278282

279283
if (!showTooltip)
280-
return <span suppressHydrationWarning>{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}</span>;
284+
return (
285+
<span suppressHydrationWarning>
286+
{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}
287+
</span>
288+
);
281289

282290
const tooltipContent = (
283291
<TooltipContent
@@ -290,7 +298,11 @@ const DateTimeAccurateInner = ({
290298

291299
return (
292300
<SimpleTooltip
293-
button={<span suppressHydrationWarning>{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}</span>}
301+
button={
302+
<span suppressHydrationWarning>
303+
{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}
304+
</span>
305+
}
294306
content={tooltipContent}
295307
side="right"
296308
asChild={true}
@@ -326,9 +338,13 @@ function formatDateTimeAccurate(
326338
locales: string[],
327339
hour12: boolean = true
328340
): string {
329-
const formattedDateTime = new Intl.DateTimeFormat(locales, {
341+
const datePart = new Intl.DateTimeFormat(locales, {
330342
month: "short",
331343
day: "numeric",
344+
timeZone,
345+
}).format(date);
346+
347+
const timePart = new Intl.DateTimeFormat(locales, {
332348
hour: "numeric",
333349
minute: "numeric",
334350
second: "numeric",
@@ -338,7 +354,7 @@ function formatDateTimeAccurate(
338354
hour12,
339355
}).format(date);
340356

341-
return formattedDateTime;
357+
return `${datePart} ${timePart}`;
342358
}
343359

344360
export const DateTimeShort = ({ date, hour12 = true }: DateTimeProps) => {
@@ -347,7 +363,11 @@ export const DateTimeShort = ({ date, hour12 = true }: DateTimeProps) => {
347363
const realDate = typeof date === "string" ? new Date(date) : date;
348364
const formattedDateTime = formatDateTimeShort(realDate, userTimeZone, locales, hour12);
349365

350-
return <span suppressHydrationWarning>{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}</span>;
366+
return (
367+
<span suppressHydrationWarning>
368+
{formattedDateTime.replace(/\s/g, String.fromCharCode(32))}
369+
</span>
370+
);
351371
};
352372

353373
function formatDateTimeShort(

0 commit comments

Comments
 (0)