-
Notifications
You must be signed in to change notification settings - Fork 0
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
changed date field to store ISOstring and date format #179
Changes from 4 commits
adc3560
0358d91
efa5614
f3ed216
15730bb
cc249ee
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 |
---|---|---|
|
@@ -65,7 +65,11 @@ export const POST = withSession(async (request) => { | |
|
||
const parentID = foundSenior.folder; | ||
|
||
const formatted_date = moment(fileData.date).format("L"); | ||
const userTimeZoneOffset = new Date().getTimezoneOffset(); | ||
const newDate = new Date( | ||
fileData.date.getTime() + userTimeZoneOffset * 60000 | ||
); | ||
const formatted_date = moment(newDate).format("L"); | ||
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. Here as well! |
||
|
||
const fileMetadata = { | ||
name: [formatted_date], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 }; | ||
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. nit: I think it's cleaner to do return { ...file, date: newDate } instead of de-structuring senior.Files.map((file) => ({ ...file, date: new Date(# Your logic)}) |
||
}); | ||
|
||
return ( | ||
<div className="flex flex-col gap-y-6"> | ||
|
@@ -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)} | ||
|
@@ -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} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +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.setUTCHours(0, 0, 0, 0); | ||
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. Since this bug was quite tricky to find, I would add the link we used here! |
||
return date; | ||
}), | ||
filetype: z.string(), | ||
|
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.
Moment.js does a similar conversion to local time zone error to Prisma, therefore I added an offset such that the Google Docs name matches.