-
Notifications
You must be signed in to change notification settings - Fork 494
Description
Is there an existing issue for this?
- I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
DateTimeOffsetConverter does not use TimeZoneInfo of DateTime to get the utc offset. Instead it uses the TimeZoneInfo of the current system time zone.
This is wrong because the system time zone can differ from the selected date time zone.
E.g
In germany we have winter time (GMT +1) from october to march and summer time (GMT +2) from april to september.
Let's say we are in germany and it's 1st feburary. The system time zone is GMT +1.
Using your sample project
- pick 15th march => offset is 1
- pick 15th july => offset is 1
This is wrong because the offset for 15th july should be 2 since it's summer time and not winter even though I'm currently in winter time.
I can create a PR for this but I don't know how to test this since we have to configure the system time zone right?
Expected Behavior
Get utc offset for the particular DateTime
var offset = localDateTime.Kind switch
{
DateTimeKind.Local => TimeZoneInfo.Local.GetUtcOGetffset(value),
DateTimeKind.Utc => TimeZoneInfo.Utc.GetUtcOffset(value),
_ => TimeSpan.Zero,
};
Steps To Reproduce
Simple repro steps
- Set system time zone to germany
- Specify the
DateTime.Kindin the converter
var localDateTime = DateTime.SpecifyKind(value, DateTimeKind.Local);
var offset = localDateTime.Kind switch
{
DateTimeKind.Local => DateTimeOffset.Now.Offset,
DateTimeKind.Utc => DateTimeOffset.UtcNow.Offset,
_ => TimeSpan.Zero,
};
- Open your
DateTimeOffsetConverterPage- Select 15th march
- Offset +1
- Select 15th july
- Offset +1
- Select 15th march
Link to public reproduction project repository
https://github.com/CommunityToolkit/Maui/tree/main/samples
Environment
- .NET MAUI CommunityToolkit: Main
- OS:
- .NET MAUI:9.0.40Anything else?
No response