Hello,
We use the DateTimeOffset class to persist date/time values in our software. On the client (usually in a XamDataGrid) we would like to have the time displayed as a local time without the offset. To do that I used the following XAML-Code:
<igDP:Field Name="CreatedOn" Label="{l:LocText Erowa.EMC:Terms:CreatedOn}" > <igDP:Field.Settings> <igDP:FieldSettings> <igDP:FieldSettings.EditorStyle> <Style TargetType="igEditors:XamDateTimeEditor"> <Setter Property="Format" Value="G" /> </Style> </igDP:FieldSettings.EditorStyle> </igDP:FieldSettings> </igDP:Field.Settings> </igDP:Field>
Now I have a problem when the persisted DateTimeOffset values are stored with different time-offsets. It looks like the offset is simply ignored what results in wrong displayed timestamps.
What can I do to get the correct timestamps?
Regards,Martin
Hello Martin,
I have been looking into you description and I cannot seem to understand what exactly are you trying to achieve. Would you please attach a sample project that illustrates what you are doing and if possible a screenshot of the end result you are striving to reach.
Thanks in advance. Looking forward to hearing from you.
Hello Petar,
I created a sample to show you the problem. The main window contains two grids, both displaying the same data. The upper grid displays the native data, the lower grid formats the DateTimeOffset so that it doesn't show the offset value anymore (<Setter Property"Format" Value="G" />).
What I expected was that if I format the DateTimeOffset, the formatter would not only hide the offset but calculate the correct local time.
I.e. 06:27:00 +00:00 => 07:27:00 (local here is +01:00)
I hope this sample helps you to understand my problem now.
Thank you for the sample project that clarifies everything. I have been looking through it and it appears that the issue is not coming from the formatting, but rather from the inability of the XamDateTimeEditor to edit DateTimeOffset values. As you can see in the upper XamDataGrid the XamDateTimeEditor isn’t automatically set to the “DateTime” Field. If you want you can use the XamDateTimeEditor to display/edit the DateTime value of the DateTimeOffset class like so:
<igDP:UnboundField Label="Unbound DateTime" BindingPath="DateTime.DateTime" Width="150">
<igDP:Field.Settings>
<igDP:FieldSettings>
<igDP:FieldSettings.EditorStyle>
<Style TargetType="igEditors:XamDateTimeEditor">
<Setter Property="Format" Value="G" />
<Setter Property="Mask" Value="{}{date} {longtime}" />
</Style>
</igDP:FieldSettings.EditorStyle>
</igDP:FieldSettings>
</igDP:Field.Settings>
</igDP:UnboundField>
Please let me know, if you require any further assistance on the matter, or if I have misunderstood you in any way.
Thank you for your reply. This solution is a bit better, but it still ignores the given offset. As you may see in the sample both values have the same time but in different timezones.
What I miss now is that both time values were now displayed in the local timezone.
=> 07:27 +01:00 and 06:27 +00:00 should both be displayed as 07:27 (local timezone)
Hi Martin,
You can also set the UnboundField to point to the LocalDateTime or UtcDateTime properties of the DateTimeOffset class:
<igDP:UnboundField Label="Unbound DateTime" BindingPath="DateTime.LocalDateTime”…
or
<igDP:UnboundField Label="Unbound DateTime" BindingPath="DateTime.UtcDateTime" …
Please let me know if this is what you needed.
Hi Petar,
As a consequence of your answers we will change our software to use DateTime values on the client. We can easy implement the conversion to the server side used DateTimeOffset in the WCF access layer.
Once again, thank you for your help.
This is exactly what should not happen due to a control issue. It's responsibility of Infragistics to make the control compliant with MS data types. Not have the customer rewrite, add, or modify server side, client side, or backend processes to accommodate a misfire on Infragistics engineering department.