提交 014673d1 编写于 作者: Y Youssef Victor

fix: Fix CalendarView selecting next day due to not respecting current time zone

上级 64fb74e4
......@@ -13,6 +13,22 @@ namespace Uno.UI.Tests.Windows_Globalization
[TestClass]
public class When_Calendar
{
[TestMethod]
public void When_DateTimeOffset_Is_Next_Day_If_Converted_To_Utc()
{
var calendar = new WG.Calendar();
var offset = new DateTimeOffset(year: 2023, month: 5, day: 1, hour: 21, minute: 0, second: 0, TimeSpan.FromHours(-5));
calendar.SetDateTime(offset);
// calendar.Day must be 1 here to match WinUI, **and also** not break CalendarView selection of "Today"
Assert.AreEqual(1, calendar.Day);
Assert.AreEqual(2, offset.UtcDateTime.Day);
var comparer = new DirectUI.DateComparer();
comparer.SetCalendarForComparison(calendar);
var result = comparer.CompareDay(offset, new DateTimeOffset(year: 2023, month: 5, day: 1, hour: 4, minute: 0, second: 0, TimeSpan.FromHours(0)));
Assert.AreEqual(0, result);
}
[TestMethod]
public void When_Gregorian_FixedDate()
{
......
......@@ -103,10 +103,7 @@ namespace DirectUI
global::System.Diagnostics.Debug.Assert(m_spCalendar is { });
lhs = lhs.ToUniversalTime(); // UNO
rhs = rhs.ToUniversalTime(); // UNO
long delta = lhs.Ticks - rhs.Ticks;
long delta = lhs.ToUniversalTime().Ticks - rhs.ToUniversalTime().Ticks;
if (delta < 0)
{
delta = -delta;
......
......@@ -190,28 +190,28 @@ namespace Windows.Globalization
#region Read / Write _time
public int Era
{
get => _calendar.GetEra(_time.UtcDateTime);
get => _calendar.GetEra(_time.DateTime);
[NotImplemented]
set => global::Windows.Foundation.Metadata.ApiInformation.TryRaiseNotImplemented("Windows.Globalization.Calendar", "int Calendar.Era");
}
public int Year
{
get => _calendar.GetYear(_time.UtcDateTime);
get => _calendar.GetYear(_time.DateTime);
set => AddYears(value - Year);
}
public int Month
{
get => _calendar.GetMonth(_time.UtcDateTime);
get => _calendar.GetMonth(_time.DateTime);
set => AddMonths(value - Month);
}
public global::Windows.Globalization.DayOfWeek DayOfWeek => (global::Windows.Globalization.DayOfWeek)_calendar.GetDayOfWeek(_time.UtcDateTime);
public global::Windows.Globalization.DayOfWeek DayOfWeek => (global::Windows.Globalization.DayOfWeek)_calendar.GetDayOfWeek(_time.DateTime);
public int Day
{
get => _calendar.GetDayOfMonth(_time.UtcDateTime);
get => _calendar.GetDayOfMonth(_time.DateTime);
set => AddDays(value - Day);
}
......@@ -219,7 +219,7 @@ namespace Windows.Globalization
{
get
{
var hour = _calendar.GetHour(_time.UtcDateTime);
var hour = _calendar.GetHour(_time.DateTime);
if (hour < 12 || _clock == ClockIdentifiers.TwentyFourHour)
{
......@@ -236,13 +236,13 @@ namespace Windows.Globalization
public int Minute
{
get => _calendar.GetMinute(_time.UtcDateTime);
get => _calendar.GetMinute(_time.DateTime);
set => AddMinutes(value - Minute);
}
public int Second
{
get => _calendar.GetSecond(_time.UtcDateTime);
get => _calendar.GetSecond(_time.DateTime);
set => AddSeconds(value - Second);
}
......@@ -281,7 +281,7 @@ namespace Windows.Globalization
public int Nanosecond
{
get => (int)(_calendar.GetMilliseconds(_time.UtcDateTime) * 1000);
get => (int)(_calendar.GetMilliseconds(_time.DateTime) * 1000);
set => AddNanoseconds(value - Nanosecond);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册