Skip to content

Commit

Permalink
Parse File Date with UTC, Front side restore offset due to Prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
johnny-t06 committed May 1, 2024
1 parent 0358d91 commit efa5614
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/components/senior/DisplaySenior.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ const DisplaySenior = (props: DisplayProps) => {
seniorId: senior.id,
});
};
const seniorFiles = senior.Files.map((file) => {
const userTimeZoneOffset = new Date().getTimezoneOffset();
const newDate = new Date(file.date.getTime() + userTimeZoneOffset * 60000);
const { date, ...other } = file;
return { date: newDate, ...other };
});

return (
<div className="flex flex-col gap-y-6">
Expand Down Expand Up @@ -79,7 +85,7 @@ const DisplaySenior = (props: DisplayProps) => {
setFileEdit={canAddFile ? setFileEdit : undefined}
/>
)}
elements={senior.Files.sort(
elements={seniorFiles.sort(
(fileA, fileB) => fileA.date.getTime() - fileB.date.getTime()
)}
search={(file, filter) => formatFileDate(file.date).includes(filter)}
Expand All @@ -88,7 +94,7 @@ const DisplaySenior = (props: DisplayProps) => {
<AddFile
seniorId={senior.id}
seniorFolder={senior.folder}
files={senior.Files}
files={seniorFiles}
key={addFileId}
editFile={editFile}
setEditFile={setFileEdit}
Expand Down
3 changes: 1 addition & 2 deletions src/server/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const seniorSchema = z.object({
export const File = z.object({
date: z.string().transform((val) => {
const date = new Date(val);
date.setHours(0, 0, 0, 0);
date.toISOString();
date.setUTCHours(0, 0, 0, 0);
return date;
}),
filetype: z.string(),
Expand Down

0 comments on commit efa5614

Please sign in to comment.