Scheduler timezone="UTC" and current time indicator with local time.

Hello.
I need to configure the scheduler with timeZone = UTC to save the same time entered in the client in the database (the server is not in the same zone).
I have followed the steps detailed in:
https://ej2.syncfusion.com/aspnetcore/documentation/schedule/timezone/#display-events-on-same-time-everywhere-with-no-time-difference

This causes that the "current-indicator" in TODAY is also present in UTC time (in my case 2 hours minus)

Can you modify it for the client to show the local time without the offset?

Thank you very much.


1 Reply 1 reply marked as answer

HB Hareesh Balasubramanian Syncfusion Team June 2, 2021 05:03 PM UTC

Hi Guillermo,

 

Greetings from Syncfusion Support..!

 

We have validated your shared query at our end and let you know that by default, when we set “UTC” as timezone for the scheduler then the current time indicator will show the current time for UTC only. If you need to get the local time for the current time indicator, you need to remove the timezone property for the Scheduler, then the current time indicator will take the system timezone.

 

To achieve your requirement "load the appointments for the Scheduler at the same time for all client time" you can update the appointment timing in universal time in backend. And for the same we have prepared a CRUD sample, which can be downloaded from the following link.

 

Sample: https://www.syncfusion.com/downloads/support/forum/165996/ze/Sample363403232

 

Server side snippets:

        [HttpPost]

        public List<ScheduleEvent> LoadData([FromBody] Params param)

        {

            List<ScheduleEvent> data = _context.ScheduleEvents.ToList().Where(app => (app.StartTime >= param.StartDate && app.StartTime <= param.EndDate) || (app.RecurrenceRule != null && app.RecurrenceRule != "")).ToList();  // Here filtering the events based on the start and end date value.

            return data;

        }

 

        [HttpPost]

        public List<ScheduleEvent> UpdateData([FromBody] EditParams param)

        {

            if (param.action == "insert" || (param.action == "batch" && param.added.Count > 0)) // this block of code will execute while inserting the appointments

            {

                foreach (var apps in param.added)

                {

                    var value = (param.action == "insert") ? param.value : apps;

                    int intMax = _context.ScheduleEvents.ToList().Count > 0 ? _context.ScheduleEvents.ToList().Max(p => p.Id) : 1;

                    DateTime startTime = Convert.ToDateTime(value.StartTime);

                    DateTime endTime = Convert.ToDateTime(value.EndTime);

                    ScheduleEvent appointment = new ScheduleEvent()

                    {

                        Id = intMax + 1,

                        StartTime = startTime.ToUniversalTime(),

                        EndTime = endTime.ToUniversalTime(),

                        Subject = value.Subject,

                        IsAllDay = value.IsAllDay,

                        StartTimezone = value.StartTimezone,

                        EndTimezone = value.EndTimezone,

                        RecurrenceRule = value.RecurrenceRule,

                        RecurrenceID = value.RecurrenceID,

                        RecurrenceException = value.RecurrenceException,

                        Description = value.Description,

                        ApplicationType = value.ApplicationType

                    };

                    _context.ScheduleEvents.Add(appointment);

                }

                _context.SaveChanges();

            }

            if (param.action == "update" || (param.action == "batch" && param.changed.Count > 0)) // this block of code will execute while removing the appointment

            {

                var value = (param.action == "update") ? param.value : param.changed[0];

                var filterData = _context.ScheduleEvents.Where(c => c.Id == Convert.ToInt32(value.Id));

                if (filterData.Count() > 0)

                {

                    DateTime startTime = Convert.ToDateTime(value.StartTime);

                    DateTime endTime = Convert.ToDateTime(value.EndTime);

                    ScheduleEvent appointment = _context.ScheduleEvents.Single(A => A.Id == Convert.ToInt32(value.Id));

                    appointment.StartTime = startTime.ToUniversalTime();

                    appointment.EndTime = endTime.ToUniversalTime();

                    appointment.StartTimezone = value.StartTimezone;

                    appointment.EndTimezone = value.EndTimezone;

                    appointment.Subject = value.Subject;

                    appointment.IsAllDay = value.IsAllDay;

                    appointment.RecurrenceRule = value.RecurrenceRule;

                    appointment.RecurrenceID = value.RecurrenceID;

                    appointment.RecurrenceException = value.RecurrenceException;

                    appointment.Description = value.Description;

                    appointment.ApplicationType = value.ApplicationType;

                }

                _context.SaveChanges();

            }

            if (param.action == "remove" || (param.action == "batch" && param.deleted.Count > 0)) // this block of code will execute while updating the appointment

            {

                if (param.action == "remove")

                {

                    int key = Convert.ToInt32(param.key);

                    ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == key).FirstOrDefault();

                    if (appointment != null) _context.ScheduleEvents.Remove(appointment);

                }

                else

                {

                    foreach (var apps in param.deleted)

                    {

                        ScheduleEvent appointment = _context.ScheduleEvents.Where(c => c.Id == apps.Id).FirstOrDefault();

                        if (apps != null) _context.ScheduleEvents.Remove(appointment);

                    }

                }

                _context.SaveChanges();

            }

            return _context.ScheduleEvents.ToList();

        }

 

Kindly try the above solution and get back to us if you need any further assistance.

 

Regards,

Hareesh


Marked as answer
Loader.
Up arrow icon