Client date and server date confusion - date

I am working on a website in ASP.NET where e-mails can be scheduled for the future. But the problem is with the date difference between server and client.
As the server is in India, a USA user can schedule a date after today's date, as their time zone is different. Then this e-mail will never be sent, as the date has already been passed here.
Please suggest me how to deal with this matter.

Use UTC time instead of local time.
Here's a link to an article in case you need more information:
https://web.archive.org/web/20201202215446/http://www.4guysfromrolla.com/articles/081507-1.aspx

use UTC time and convert all times to it before you set the schedule.

Related

Best practices for handling timezone on API filters

We save all our datetime data on database in UTC (a timestamp with time zone column in postgresql).
Assuming "America/Sao_Paulo" timezone, if a user saves an event "A" to the database at 2021-08-24 22:00:00 (local time) this will be converted to UTC and saved as 2021-08-25 01:00:00.
So, we are wondering what would be the best way (here "the best way" refers to the developer experience) to consume an API where is possible to filter events by start and end date.
Imagine the following situation: the user is on the website and needs to generate a report with all events that happened on 2021-08-24 (local time America/Sao_Paulo). For this, the user fills start and end date both with 2021-08-24.
If the website forwards this request directly to the API, the server will receive the same date provided by the user and some outcomes can happen:
If the server does not apply any transformation at all, the data returned will not contain the event "A" — by the user perspective, this is wrong.
The server can assume that the date is in UTC and transform start date to 2021-08-24 00:00:00 and end date to 2021-08-24 23:59:59. Then, apply the timezone of the user, generating: 2021-08-24 03:00:00 and 2021-08-25 02:59:59. Filtering the database now would bring the expected event "A".
The API itself could expected a start and end datetime in UTC. This way, the developer can apply the user timezone on client side and then forward to server (2021-08-24T03:00:00Z and 2021-08-25T02:59:59Z).
The API itself could expected a start and end datetime either in UTC or in with the supplied offset (2021-08-24T00:00:00-03:00 and 2021-08-24T23:59:59-03:00). Github does it this way.
What got us thinking was that a lot of APIs accept only a date part on a range filter (like the github API). So, are those APIs filtering the data in the client timezone or they assume the client knows the equivalent UTC date that they should filter by (we could not find any documentation that explains how github deals with an incoming date only filter)?
For us, makes more sense the date filter consider the timezone of the client and not leave to them the burden to know the equivalent UTC datetime of the saved event. But this complicates a bit the filtering logic.
To facilitate the filter logic, we thought that maybe have another column on database to also save the local datetime of the event (or only the local date) would be interesting. Is this a valid approach? Do you know any drawbacks?
*We know that on a database perspective, it is recommended to save datetime in UTC (not always, as showed here) but in our case this seems to only make things more difficult when handling API consumption.
*It is importante to know that, when saving an event, the user cannot provide when it happens, we always assume the event happens in the moment it is being saved.

Date gets converted to utc automatically upon sending to frontend

I'm receiving a date from a node.js backend in flutter. The date is converted to the users timezone in node.js.
For some reason, flutter automatically converts it to utc. How can I receive the dateTime as is and not have flutter convert it?
Background: The way it works is flutter first sends a dateTime to the
backend already converted to utc so that it can be stored in the db in
utc. then anytime the backend sends back a date, it converts it to the
timezone the user was in when signing up. (not sure if this is a good
way of doing time conversion...)
UPDATE:
Seems like DateTime.parse always converts to utc... Any way to stop that behavior?
If you're using DateTime.parse, it says in the documentation that the way to handle the changing of time-zone is by providing an optional time-zone offset part in your date.
DateTime.parse("2020-09-21T14:00:00") // 2020-09-21 14:00:00.000
DateTime.parse("2020-09-21T14:00:00-1230") // 2020-09-22 02:30:00.000Z
Check out the documentation here https://api.flutter.dev/flutter/dart-core/DateTime/parse.html

What is the appointment date timezone in HL7 Scheduling SIU S12 request?

Currently I am working with the HL7 and mirth part for the new appointment booking. So when I parse the HL7 data in mirth for SIU S12 request, I am getting the date in YYYYMMDDHHmmss fomat in SCH category.
Can any one have an idea about in which timezone it is coming in request? Is that come in the locale timezone from which the request is actually sent?
Thanks in advance for the help!!!
A few possibilities:
The time zone is local to the sender of the message. This is likely but you should check with the sender! With the advent of cloud and remotely hosted systems the appointment could be in GMT+6 but the server is in GMT-5 and it won't be immediately clear if the time zone is defaulted to the appointment location or the server location
The time zone doesn't matter. If I make an appointment with my doctor at 8 AM on Tuesday then that appointment is still at 8 AM on Tuesday. The software can store that time and date WITHOUT the timezone and still represent the data correctly. This is NOT the case if you're driving alerts or notifications off of the appointment.
Infer the time zone from other clues in the message. Does the MSH segment have timestamps with the zone?

Sendgrid timezone

I'm sending emails using the Sendgrid API, & I wanna use the "send_at" where I must convert the date to timestamp first..
Well, what timezone shall I use? & is there any other way avoiding the convertion to timestamp?
The Sendgrid API has the send_at parameter which is a UNIX timestamp format.
Here is an example for using the send_at email header:
{
"send_at": 1409348513
}
To schedule a send request for a large batch of emails use the send_at parameter which will send all emails at approximately the same time.
Timezone issues with scheduling emails, please remember that you have the option to specify a timezone when you schedule the email to go out.
If you don’t specify the timezone, it will default to current Pacific Time (UTC-7 or UTC-8, depending on your daylight savings time).
In order to specify the timezone assigned to the user you can call the following API:
Post Url:
https://api.sendgrid.com/api/timezone/edit.json
Post Data: api_user=your_sendgrid_username&api_key=your_sendgrid_password&timezone=America/New_York
The following API updates the timezone assigned to the user.

Why the date of an email is in local Android time using JavaMail?

I've written a simple mail client that uses JavaMail to read emails.
When I get the Date of a message, it's expressed in the local time of my Android configuration.
For instance Message-->Date.getString() will give me a different time depending of my Android time zone configuration. However, the date of the message is on the server, right? So the Android time zone configuration should not affect anything.
Are Android and JavaMail secretely pass my time zone configuration to the server so that I receive a Date expressed indeed into my locale zone?
Well, that's not annoying I prefer this anyway, but I'm out of curiosity... why?!
The server returns the date/time with the timezone so that the correct UTC/GMT time is stored in the Date object. The Date.toString() method returns the date in the local timezone.