Skip to content
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

Merged
merged 6 commits into from
May 2, 2024

Conversation

johnny-t06
Copy link
Collaborator

@johnny-t06 johnny-t06 commented May 1, 2024

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

Copy link

vercel bot commented May 1, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
the-legacy-project2 🔄 Building (Inspect) Visit Preview May 1, 2024 0:20am

const newDate = new Date(
fileData.date.getTime() + userTimeZoneOffset * 60000
);
const formatted_date = moment(newDate).format("L");
Copy link
Collaborator Author

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.

const newDate = new Date(
fileData.date.getTime() + userTimeZoneOffset * 60000
);
const formatted_date = moment(newDate).format("L");
Copy link
Collaborator Author

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 };
Copy link
Collaborator

@nickbar01234 nickbar01234 May 1, 2024

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);
Copy link
Collaborator

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!

Copy link
Collaborator

@nickbar01234 nickbar01234 left a 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!


const formatted_date = moment(fileData.date).format("L");
const newDate = new Date(
fileData.date.getTime() + new Date().getTimezoneOffset() * 60000
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea definitely needed, added!

@johnny-t06 johnny-t06 merged commit 407c7aa into main May 2, 2024
4 checks passed
@johnny-t06 johnny-t06 deleted the johnny/addFileDate-Change branch May 2, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants