Timezone confusion with switching CEST to CET - datetime

I'm currently building a system where you can create normal appointments and recurring appointments like in Microsoft Outlook. The database stores the datetime values as UTC without the timezone. When creating recurring appointments, I store the start time in a separate column. Now my problem:
When a user creates a recurring appointment starting on 2021-10-01T20:00:00+02:00 (it will be stored as 2021-10-01T18:00:00Z in the database) and ending on 2021-11-30T21:30:00+02:00 (it will be stored as 2021-11-30T19:30:00Z in the database) recurring every wednesday and friday a week. So the duration of the appointments is 1 hour and 30 minutes.
If I now query all appointments in the timespan between 2021-10-01 and 2021-11-30 and the timezone of my local device is CEST (Central European Summer Time (UTC+0200)) or CEDT (Central European Daylight Time (UTC+0200)), all appointments are starting at 20:00 and ending at 21:30. If I query all above appointments one month later (after CEST is switchted to CET (Central European Time (UTC+0100)), all appointments are starting at 19:00 and ending at 20:30 because of the timezone of my local device but I want the appointments to always start at the time it was initially created (In this example always from 20:00 to 21:30.
What is the best approach for this? Should I store the timezone in which the appointment is created and convert it to this timezone at query time?

Related

Recurrence event with RRULE plugin Timezone issue daylight saving time

The problem occurs when you have an event, which starts for example on October 23 11:45, repeats every day, with no end date
Once October 30 reaches, this event starts to be shown from 10:45 (Because in my country daylight saving time happens on a night from 29 to 30 October)
Is there are any way to prevent this behaviour ?
What I tried already: use tzid on RRULE plugin which I'm using for recurrence
Changing timezone of fullcalendar itself (per parameter) is not an option for me
I'll attach fullcalendar representation of this problem
I'm expecting to see that event starting at 11:45 and not 10:45
Event series before savings day
Event series after savings day
You can notice how hour chagned

Business hours for specific Dates in full calendar

I am using fullcalendar to let users book an appointment with clients at specific availability set by the clients. So have to disable the fullcalendar when the client is not available. Currently I am able to set multiple business hours for whole calendar i.e. all the years and months.
But I am not able set for specific chunks of date ranges. I need to set different business hours for different date ranges in full calendar. For example from 5th Jan 2016 to 25th Jan 2016 i want to set business hours 08:00 AM to 06:00 PM after that date I want to set business hours 09:00 AM to 08:00 PM for 1st Feb to 15th Feb. Remaining Date should be disabled for creating event for whole year and above specified date and time should be enabled to create event.
I tried many options but it seems there aren't enough options to fulfill my requirement. So calling for some help if someone can.

google calendar time not showing correct start and end time

I am constructing a link (programmatically) to create a google calendar link. I found that when I pass it a date in the following format
....&dates=20151005T170000Z/20151007T190000Z&....
where I'd expect it to show 5:00 PM to 7:00 PM, it instead shows 1:00 PM to 3:00 PM
Here is the full link:
`https://www.google.com/calendar/render?action=TEMPLATE&text=The+Annual+%20Event&dates=20151005T170000Z/20151007T190000Z&sprop=website:turnaround.org&location=Fairmont+Scottsdale+Princess+7575+East+Princess+Drive+Scottsdale,+AZ+United+States&details&website=https://example.com&pli=1&sf=true&output=xml#eventpage_6'
My only thought would be that its a timezone issue, but I don't see that anywhere in the url.
You are passing the time zone as Z
20151005T170000Z <-- here at the end of the date/time
The letter Z ("Zulu") indicates Greenwich Mean Time (GMT) or Coordinated Universal Time (see UTC±00:00). They are used in conjunction with military time: for instance, 6:00 a.m. in zone UTC−5 is written "0600R" and spoken "zero six hundred Romeo".
And
https://support.google.com/calendar/answer/37064?hl=en
Google Calendar uses Coordinated Universal Time (UTC) to help avoid issues with daylight savings time.
When events are created, they're converted into UTC, but you'll always see them in your local time.
If an area switches their time zone, events created before we knew about the change might be in the wrong time zone.
So make sure all times are in UTC time or don't put a Z on the time and instead add the &ctz=TIMEZONE to the URL.

When is it ok to store datetimes as local time rathen than UTC?

This is a question similar to this one.
I'm really tempted to store datetimes in my app as local time rather than as UTC (which is considered a best practice). In the app I have a number of events happening, each assigned to a given location. Always when I display them to the user, I want to show the local time of the event. I.e.:
====================================================================================
Event time (with TZ) | As UTC | As local time | To be displayed |
====================================================================================
2014-01-15 22:30 GMT | 2014-01-15 22:30 | 2014-01-15 22:30 | 2014-01-15 22:30 |
2014-01-15 23:30 GMT+1 | 2014-01-15 22:30 | 2014-01-15 23:30 | 2014-01-15 23:30 |
2014-01-16 00:30 GMT+2 | 2014-01-15 22:30 | 2014-01-16 00:30 | 2014-01-16 00:30 |
====================================================================================
If I decide to store the event times in UTC:
it will be difficult to display them (because with each event I need to have the event's timezone and format the date for that timezone).
it will be very difficult to query them (i.e. if I want to show all events that happened on 2014-01-15 local time I need for each event to compare that event's time with what '2014-01-15' means in that event's timezone. Not sure if this is even possible in SQL...)
If I decide to store the event times as local times:
I will not be able to compare times of events for different locations (but this is ok for me)
Since in the vast majority of cases in the app I'm interested in the local time (usually displaying the, so called "television time") and there aren't many cases where I'm creating new datetime objects (for which I need the location timezone), I believe saving datetimes as local time is justified in this case.
Do you think it is? What are other downsides of storing local times?
Thanks in advance for your attention and help.
The most commonly overlooked case of when not to use UTC is for scheduling of future times - especially in recurrence patterns.
Imagine if you're alarm clock was scheduled by UTC. Say you set it for 7:00 AM daily. On the day after a DST transition, you'd either wake up at 6:00 AM or 8:00 AM depending on which direction the transition was.
Also, the rules by which we determine time zone offsets and daylight saving time changes get updated all the time! So you can't take some future local time and convert it to UTC without also retaining the local time itself. Otherwise, when things change, you won't have an original source of truth and again all your times will be off.
I've posted on this many times before.
Of course, once the event has occurred, then you certainly want to record the time either at UTC, or using a DateTimeOffset.
Another common use case is for dates without times, especially birth dates and other anniversary dates. These should always just be stored as year, month, day (such as in a date field type in most databases) - with no conversion between time zones or UTC.
Regarding your specific points:
If I decide to store the event times in UTC ... it will be difficult to display them...
That is quite easy actually. Almost every programming environment can do this easily. The only place this is difficult is in JavaScript for non-local time zones, and there are libraries to cope with that.
If I decide to store the event times in UTC ... it will be very difficult to query them (i.e. if I want to show all events that happened on 2014-01-15 local time I need for each event to compare that event's time with what '2014-01-15' means in that event's timezone. Not sure if this is even possible in SQL...)
That is true. Everybody's "today" is different. If you need data tied to a floating "day" then that is another case for not storing in UTC. However, a DateTimeOffset would give you the advantages of both.
If I decide to store the event times as local times ... I will not be able to compare times of events for different locations (but this is ok for me)
It's more than that. A local DateTime without an Offset may be ambiguous to to daylight saving time fall-back transitions. So you could have a single local value that you can't distinguish which of two points in time it corresponds to.
Regarding "television time" - reserve that concept for things that are truly "floating". Example: A company has offices all over the world that all start at 8:00 AM. That's a floating time.

Send a Meeting Request with System.Net.Mail

I am using this example code to send a meeting request. I am having a problem: every time I use the code, the meeting time is always the wrong time.
For example: DTSTART:20120710T143000Z gives an appointment in Outlook Tuesday, July 10, 2012 4:30 PM-5:30 PM when it should give Tuesday, July 10, 2012 2:30 PM-3:30 PM. Why is that happening?
Our local time is UTC/GMT +3 (Jordan Standard Time) in the summer and UTC/GMT +2 in the winter. Every time I make an appointment through outlook it is always the right time.
The start time you place in your appointment should be a UTC time. I suspect you are a inserting local (Jordan) time. This explains the two hour difference, because afaik UTC does not take daylight saving time into account.
SO resources:
Convert somebody's local time to the UTC time
Daylight saving time and time zone best practices
Convert UTC/GMT time to local time

Resources