Hi,
In my project I have a sfSchedule like below:
<SfSchedule @ref="scheduler" TValue="Activity" Height="650px" @bind-SelectedDate="@CurrentDate" Timezone="@GetCurrentTimezone()" Readonly="true">
<ScheduleEvents TValue="Activity" ActionCompleted="OnActionCompleted" DataBound="OnDataBound" EventRendered="OnEventRendered"></ScheduleEvents>
<ScheduleViews>
<ScheduleView Option="View.WorkWeek"></ScheduleView>
<ScheduleView Option="View.Month"></ScheduleView>
</ScheduleViews>
<ScheduleEventSettings TValue="Activity">
<SfDataManager Url=@GetAddress() Adaptor="Adaptors.WebApiAdaptor"></SfDataManager>
<ScheduleField Id="ID">
<FieldSubject Name="Subject"></FieldSubject>
<FieldLocation Name="Location"></FieldLocation>
<FieldDescription Name="Description"></FieldDescription>
<FieldStartTime Name="Start"></FieldStartTime>
<FieldEndTime Name="Finish"></FieldEndTime>
</ScheduleField>
</ScheduleEventSettings>
</SfSchedule>
No matter what Timezone I assign to the Scheduler it displays events in UTC.
Info:
Start and End are stored as DateTime UTC on server.
Using Syncfusion.Blazor19.2.0.44 and Blazor 5.0.5
Have tried:
ODatav4Adaptor and WebApiAdaptor
Assignment of StartTimezone and EndTimezone
Changing Start and End to LocalTime() in the DataBound, ActionCompleted and EventRendered events.
But no luck so far.
Any hints on how to get the schedulers Timezone to show the events in local time?
Best regards
Jens
|
public List<EventData> GetODataV4(string StartDate, string EndDate)
{
DateTime start = DateTime.Parse(StartDate);
DateTime end = DateTime.Parse(EndDate);
var data = db.EventData.Where(evt => evt.StartTime >= start && evt.EndTime <= end).ToList();
TimeZone curTimeZone = TimeZone.CurrentTimeZone;
var timezone = TimeZoneInfo.FindSystemTimeZoneById(curTimeZone.StandardName);
for (var i = 0; i < data.Count; i++)
{
if (timezone != null)
{
DateTime startTime = Convert.ToDateTime(data[i].StartTime);
DateTime endTime = Convert.ToDateTime(data[i].EndTime);
startTime = DateTime.SpecifyKind(startTime, DateTimeKind.Utc);
endTime = DateTime.SpecifyKind(endTime, DateTimeKind.Utc);
data[i].StartTime = TimeZoneInfo.ConvertTime(startTime, timezone);
data[i].EndTime = TimeZoneInfo.ConvertTime(endTime, timezone);
}
}
return data; } |
|
optionsBuilder.UseSqlServer("Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=D:\\EJ2\\July8th\\Incident\\F166967\\ScheduleCRUD\\blazor-scheduler-crud\\Restful_Services\\App_Data\\ScheduleData.mdf;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework;Integrated Security=True"); |
Hi Satheesh,
Thanks for the sample and explanation. I have got it running.
As I understand your solution, the basic steps are:
In the controller you make use of a new entity "EventData" in which you convert the utc start and end to the timezone of the client
If that is correct I can see it is doable, but quite som work and error handling remains:
If I have missed the point, please let me know.
Otherwise it would be a nice addition to the sfSchedule if the TimeZone handling was included (given that the stored datetime values always are in UTC).
Best regards,
Jens