-
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
src/app/api/file/[fileId]/route.ts
Outdated
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 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.
src/app/api/file/route.ts
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well!
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 comment
The 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 { date, ...other }
. Alternatively, since there's not too much logic here, it wouldn't be bad style to write the map function in one-line.
senior.Files.map((file) => ({ ...file, date: new Date(# Your logic)})
@@ -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 comment
The 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!
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.
Changes are great! Thank you for getting it in so quickly. My only comment is to extract the logic for offsetting timezone into a helper function - feel free to merge if you don't think it's worth the time!
src/app/api/file/[fileId]/route.ts
Outdated
|
||
const formatted_date = moment(fileData.date).format("L"); | ||
const newDate = new Date( | ||
fileData.date.getTime() + new Date().getTimezoneOffset() * 60000 |
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.
Should we extract the logic into a helper function, since it's reused quite a bit?
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.
Yea definitely needed, added!
Description
File Date Object now is set to 0:00 UTC. On prisma retrieval, we offset with local time to get the Date Object back to 0:00 UTC
Issues
Fixes Add File Date offset error due to Prisma conversion of Date Object to local timezone.
Screenshots
Test
Test with a new Senior because of possible stale data in DB. Add files, delete files, edit files, and checked associated google docs.
Possible Downsides
Additional Documentations