Home:ALL Converter>How to store future dates for scheduling in mongoDB considering daylight saving times

How to store future dates for scheduling in mongoDB considering daylight saving times

Ask Time:2020-03-24T05:08:22         Author:Ehtesham

Json Formatter

Here is my scenario

my API takes a local datetime which is the latest time users (in the same region) can submit their work.

I want to save the datetime in local time along with timezone, that way I can apply the timezone offset to convert to UTC before sending the date to the client. This should work even if the DST changes after saving the date.

But MongoDB only saves the dates in UTC format at least in with java-mongo where it converts the local time to UTC before saving to the database. I am not able to store my date without converting it first to UTC.

So, my second approach is to get the local date from request convert it into UTC based on timeZone information that I already have. This approach would work fine unless in a scenario where daylight saving hours changed after saving the date but before that date expired.

e.g. local date got from the client is 2020-03-28 00:00 who is in +4 UTC. I convert it to UTC and stores it as 2020-03-28T20:00:00Z. But if the daylight saving changes within that period the users can get one more hour to submit their work.

So, my question is how can I handle such a scenario if I store the date in UTC, or suggest something else.

Author:Ehtesham,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/60821558/how-to-store-future-dates-for-scheduling-in-mongodb-considering-daylight-saving
yy