From c713b68504799a41afa1a8bf40da97c197139399 Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Thu, 6 Mar 2025 09:39:36 -0800 Subject: [PATCH 1/3] Convert to PST --- .../components/History/HistoryListItem.tsx | 31 ++++++++++--------- Keas.Mvc/ClientApp/src/util/dates.ts | 10 ++++-- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx b/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx index 31e4d4a30..01c537840 100644 --- a/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx +++ b/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx @@ -5,28 +5,29 @@ import { useContext } from 'react'; import { Context } from '../../Context'; interface IProps { - history: IHistory; - showLink?: boolean; + history: IHistory; + showLink?: boolean; } const HistoryListItem = (props: IProps) => { - const context = useContext(Context); + const context = useContext(Context); return ( - {DateUtil.formatExpiration(props.history.actedDate)} - {props.history.description} - - {props.showLink && props.history.link != null &&( - ... - )} - + {DateUtil.formatDate(props.history.actedDate, true)} + {props.history.description} + + {props.showLink && props.history.link != null && ( + + ... + + )} + ); }; - export default HistoryListItem; diff --git a/Keas.Mvc/ClientApp/src/util/dates.ts b/Keas.Mvc/ClientApp/src/util/dates.ts index 8e60666c3..2086e735b 100644 --- a/Keas.Mvc/ClientApp/src/util/dates.ts +++ b/Keas.Mvc/ClientApp/src/util/dates.ts @@ -2,12 +2,18 @@ import { format, min } from 'date-fns'; import { IHasExpiration } from '../models/Shared'; export class DateUtil { - public static formatDate(date: Date): string { + public static formatDate(date: Date, convertToPST: boolean = false): string { if (date === null) { return ''; } - return format(new Date(date), 'MM/dd/yyyy'); + let dateToFormat = new Date(date); + if (convertToPST) { + // Convert from UTC to PST (UTC-8) + dateToFormat = new Date(dateToFormat.getTime() - 8 * 60 * 60 * 1000); + } + + return format(dateToFormat, 'MM/dd/yyyy'); } public static formatExpiration(expiration: Date): string { From c4cdee5d2e1bfe04afbf3a779312c48b8723b0d0 Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Thu, 6 Mar 2025 11:24:41 -0800 Subject: [PATCH 2/3] use built in methods, don't use parameter --- .../components/History/HistoryListItem.tsx | 2 +- Keas.Mvc/ClientApp/src/util/dates.ts | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx b/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx index 01c537840..88c517dab 100644 --- a/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx +++ b/Keas.Mvc/ClientApp/src/components/History/HistoryListItem.tsx @@ -13,7 +13,7 @@ const HistoryListItem = (props: IProps) => { const context = useContext(Context); return ( - {DateUtil.formatDate(props.history.actedDate, true)} + {DateUtil.formatDateFromUtc(props.history.actedDate)} {props.history.description} {props.showLink && props.history.link != null && ( diff --git a/Keas.Mvc/ClientApp/src/util/dates.ts b/Keas.Mvc/ClientApp/src/util/dates.ts index 2086e735b..641e901d6 100644 --- a/Keas.Mvc/ClientApp/src/util/dates.ts +++ b/Keas.Mvc/ClientApp/src/util/dates.ts @@ -2,17 +2,32 @@ import { format, min } from 'date-fns'; import { IHasExpiration } from '../models/Shared'; export class DateUtil { - public static formatDate(date: Date, convertToPST: boolean = false): string { + public static formatDate(date: Date): string { + if (date === null) { + return ''; + } + + return format(date, 'MM/dd/yyyy'); + } + + public static formatDateFromUtc(date: Date): string { if (date === null) { return ''; } let dateToFormat = new Date(date); - if (convertToPST) { - // Convert from UTC to PST (UTC-8) - dateToFormat = new Date(dateToFormat.getTime() - 8 * 60 * 60 * 1000); + + let str = date.toString(); + if (!str.endsWith('Z')) { + str += 'Z'; } + dateToFormat = new Date( + new Date(str).toLocaleString('en-US', { + timeZone: 'America/Los_Angeles' + }) + ); + return format(dateToFormat, 'MM/dd/yyyy'); } From b9b51f7e3279bccc1c1107670f0db4fff3fccbbe Mon Sep 17 00:00:00 2001 From: Jason Sylvestre Date: Thu, 6 Mar 2025 11:30:45 -0800 Subject: [PATCH 3/3] cleanup --- Keas.Mvc/ClientApp/src/util/dates.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Keas.Mvc/ClientApp/src/util/dates.ts b/Keas.Mvc/ClientApp/src/util/dates.ts index 641e901d6..842604dd0 100644 --- a/Keas.Mvc/ClientApp/src/util/dates.ts +++ b/Keas.Mvc/ClientApp/src/util/dates.ts @@ -7,7 +7,7 @@ export class DateUtil { return ''; } - return format(date, 'MM/dd/yyyy'); + return format(new Date(date), 'MM/dd/yyyy'); } public static formatDateFromUtc(date: Date): string { @@ -15,20 +15,17 @@ export class DateUtil { return ''; } - let dateToFormat = new Date(date); - let str = date.toString(); if (!str.endsWith('Z')) { str += 'Z'; } - dateToFormat = new Date( + return format( new Date(str).toLocaleString('en-US', { timeZone: 'America/Los_Angeles' - }) + }), + 'MM/dd/yyyy' ); - - return format(dateToFormat, 'MM/dd/yyyy'); } public static formatExpiration(expiration: Date): string {