Вопрос

I'm having an issue with the events and the calendar appointments. Long story short, I have a user in Sydney creating an event in Rome (so the UTC of the event will be the Sydney one +10), the user will specify the city and the timezone (Rome +1). When someone decides to join the event in Rome from Moscow (+4) I want him to see the time when the even will happens. So if the even is from 9:00 to 11:00 in Rome time, the user should see 12:00 to 15:00 (+3) in his calendar. My problem is that in the database the date is saved as UTC 9:00 - 11:00 but starting from an offset of +10 (the Sydney one where the user who created the event is), and beside the city and some offset specified by this user I don't know how to fix the date. If i Run an ignorant conversion from UTC i will obtain 3:00 - 5:00AM since Moscow has an offest of +4 while Sydney +10. My idea was to check the localtimezone, get the offset from the data that the user put in to the system (he will specify the city and +1 for example) If i do the subtraction manually (Sydney is +10, Rome is +1 i subtract 9 hours so will be 0:00 to 2:00Am) I convert that time to utc and from there i should be able to move it where i want, but in that case probably the daylightsaving will break the thing since i'm not able to determine if the area where the city is in daylightsavings or not.

Anyone has ideas over this?

Это было полезно?

Решение 2

I found a solution that wasn't exactly clean but it worked. Basically i move the UTC time of my appointment to the location of the meeting. I had the offset and the name of the city. It's not very clean because I'm looking for a contain in the display name of the TimeZoneInfo.

List<TimeZoneInfo> viableTimezones = new List<TimeZoneInfo>();
            foreach (TimeZoneInfo timeZone in timeZones)
            {
                TimeSpan q = new TimeSpan(givenTimespawn);
                if (timeZone.BaseUtcOffset == q && timeZone.DisplayName.Contains(CityVenue))
                {
                    viableTimezones.Add(timeZone);
                }
            }
var endDate = new DateTime(Year, Month, Day, Hour, min, secs );
var actualEndUTC = TimeZoneInfo.ConvertTimeToUtc(endDate, viableTimezones[0]);

If i do this i get the UTC time of the event (the one that i have in the crm needs to be assembled from Date and Time, than moved to the venue location and finally i'm able to recover the UTC time to write that one directly inside the ics file. I discovered that a simple Z at the end (Zulu), gives the UTC value to the calendar appointment that is than moved to the user timezone.

Другие советы

Luckily, CRM handles time zones pretty well.

To start, you need to make sure each user's profile has the appropriate time zone for their home location. This is located in Settings > Options and there is a time zone attribute.

Next, you want to focus on storing the appropriate UTC value of the user's profile. For example, if I want to setup a meeting in New York for 2:00 PM and my profile is New York - then I set it for 2:00 PM. However, If I'm setting up a meeting for 2:00 PM in California, and my CRM profile is New York, then I need to schedule the meeting for 5:00 PM.

So going back to your example about Rome having an event at 9:00 AM. A user from Sydney would need to enter this as a time of 7:00 PM.

To make this intuitive for the user, keep the location drop down "Rome" and have two time fields.

Drop Down - "Rome" which tied to this field provides you with the selection's UTC offset (i.e. +1)

Time Field 1 - Represents the events local time. The user would enter 9:00 AM.

Time Field 2 - This represents the event's time in the user's time zone. You'd query the user's config and determine it's +11 (Sydney). The drop down of Rome would provide you the +1. So from these two, you need to add 10 hours and save 7:00 PM for field 2.

Time Field 2 is what you're actually looking for and will provide people with the correct time of the event in their respective time zone.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top