We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Timezone in Scheduler; slight confusion

Hi, I'm afraid that I've got difficulties understanding timezones in the Scheduler.

My scheduler is set up with a fixed timezone (Europe/Berlin). As such, there is an offset of +2 from UTC in Daylight Saving time (active now). I refer to this as CEST (Central European Summer time).
The server's timezone (not that it really matters, I guess), is UTC.

A client that connects with the client timezone in CEST creates an appointment from 22:00 to 23:00. When the Batch method of the Crud module is hit on the server, StartTime and EndTime are converted to UTC - 22:00 will become 20:00 in the POST, and 23:00 will become 21:00. This is also how the values are stored in the database.

What I find confusing is that upon GET, that appointment is now displayed in the scheduler as 20:00 to 21:00. Is the correction for TimeZone one-way?
The StartTime in the appointment after submit is
  1. StartTimeTue Apr 02 2019 20:00:00 GMT+0200 (Central European Summer Time)

9 Replies

NR Nevitha Ravi Syncfusion Team April 3, 2019 12:21 PM UTC

Hi Stefan, 

Greetings from Syncfusion Support. 

By default, the startTime and endTime of the appointments are calculated and processed in UTC time at server side. We can achieve your requirement of having same start and end time for appointments in both client and server side by adding the following code snippet in startup.cs file of the application. 
        public void ConfigureServices(IServiceCollection services) 
        { 
            services.AddDbContext<ScheduleDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ScheduleDataConnection"))); 
            services.AddMvc(); 
            services.AddMvc() 
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver()) 
                .AddJsonOptions(opt => opt.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat) 
                .AddJsonOptions(opt => opt.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local); 
        } 

And we have prepared sample for your reference which can be downloaded from the following location. 

Please check the sample and let us know if you need any further assistance on this. 

Regards, 
Nevitha 



ST Stefan April 3, 2019 06:55 PM UTC

Thank you Nevitha
the Serializer Options appear to do the trick. Might be an idea to add this to the manual?

Whilst discussing serializer options, I've also had to change the loop handling in order to get the Scheduler to work properly; maybe something to make a note of in the manual as well? Although I can't remember exactly where and what went wrong. So in total it now looks like this:

         services.AddMvc()
                .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
                .AddJsonOptions(options =>
                {
                    options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    options.SerializerSettings.DateFormatHandling = DateFormatHandling.MicrosoftDateFormat;
                    options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local;
                });




NR Nevitha Ravi Syncfusion Team April 4, 2019 12:57 PM UTC

Hi Stefan, 

Thanks for you update. 

Yes we have the plan to add this in our UG documentation which will be refreshed in live by April end. We have checked with our previous code and it works fine at all cases at our end. Could you please revert us the following details to check further on this. 

  • Purpose of adding the below line in your application.
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
  • Whether you have faced any issue without adding this line, if yes please share the issue details.
 
Regards, 
Nevitha 



ST Stefan April 5, 2019 07:54 AM UTC

Hi Nevitha
re:
  • Purpose of adding the below line in your application.
    options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; 
  • Whether you have faced any issue without adding this line, if yes please share the issue details.
It is possible to set up resources and groups which are self-referencing - so a resource can contain a list of other resources, which in turn have a reference to it's parent or similar.
One may find themselves confronted with a JsonSerializationException: Self referencing loop detected with type '..type..'

In my particular software, I'm also serializing claims in order to decide which user may book particular resources. Without the loop handling set to ignore, it will throw an exception:
JsonSerializationException: Self referencing loop detected with type 'System.Security.Claims.Claim'
Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CheckForCircularReference(JsonWriter writer, object value, JsonProperty property, JsonContract contract, JsonContainerContract containerContract, JsonProperty containerProperty)

So this is probably not required for everyone, but it can be an obstacle with multi-level groups.


VD Vinitha Devi Murugan Syncfusion Team April 9, 2019 12:26 PM UTC

Hi Stefan, 
 
We have checked the below code with multiple level resource grouping it works fine at our end. We have modified previously provided sample with multiple resource for your reference which can be downloaded from the following location. 
 
 
        public void ConfigureServices(IServiceCollection services)  
        {  
            services.AddDbContext<ScheduleDataContext>(options => options.UseSqlServer(Configuration.GetConnectionString("ScheduleDataConnection")));  
            services.AddMvc();  
            services.AddMvc()  
                .AddJsonOptions(options => options.SerializerSettings.ContractResolver = newDefaultContractResolver())  
                .AddJsonOptions(opt => opt.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat)  
                .AddJsonOptions(opt => opt.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local);  
        }  
 
 
So we will add this details in our UG as mentioned earlier, which will be refreshed at April end. 
 
Regards, 
M.Vinitha devi. 



PA PamTheOK November 25, 2022 07:11 PM UTC

Hi @Nevitha Ravi,

I tried the code sample you provided, but its throwing following error-

error CS1061: 'JsonOptions' does not contain a definition for 'SerializerSettings' and no accessible extension method 'SerializerSettings' accepting a first argument of type 'JsonOptions' could be found (are you missing a using directive or an assembly reference?)


I have also added the following package with the mentioned version-

<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />

can you please help??



RV Ravikumar Venkatesan Syncfusion Team November 28, 2022 12:12 PM UTC

PamTheOK, We checked our shared sample at our end and it works as expected. We suspect that you are using the provided solution on the core sample project which uses the .net core version greater than 2. You can resolve the problem by installing the NuGet package “Microsoft.AspNetCore.Mvc.NewtonsoftJson” and use the solution as shown in the below code snippet. Refer to the below link for more details.


https://stackoverflow.com/questions/55666826/where-did-imvcbuilder-addjsonoptions-go-in-net-core-3-0

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ej2-core-schedule-net-core-61810707327


[Program.cs]

builder.Services.AddMvc().AddNewtonsoftJson(x => { x.SerializerSettings.ContractResolver = new DefaultContractResolver(); })

    .AddNewtonsoftJson(x => x.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat)

    .AddNewtonsoftJson(x => x.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local);



PA PamTheOK December 1, 2022 07:26 PM UTC

Hi Venkatesh, 
The above code worked for me, thanks for it.

But one weird thing that I noticed is after using the code snippet in my code, I am getting all the API responses in Pascal Case, where as earlier it was Camel Case. and due to this change my data from other API is not loading on the page despite of getting data from API.

attaching screenshots link for reference-

https://drive.google.com/drive/folders/1X9qDjWyVANydoT2S7RNaydwPH0mQZYUL?usp=share_link



RV Ravikumar Venkatesan Syncfusion Team December 2, 2022 03:12 PM UTC

PamTheOK, You can resolve the problem by removing the highlighted line in the snip.



Loader.
Live Chat Icon For mobile
Up arrow icon