Skip to content

Commit

Permalink
fix(Calendar): Fix Calendar.YearAsString() and `Calendar.YearAsTrun…
Browse files Browse the repository at this point in the history
…catedString()`
  • Loading branch information
jeromelaban committed Jan 4, 2021
1 parent 1f1ad99 commit 4a31447
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
29 changes: 16 additions & 13 deletions src/Uno.UI.Tests/Windows_Globalization/When_Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,6 @@ public void When_Gregorian_FixedDate_AddHour()
);
}


[TestMethod]
public void When_Gregorian_FixedDate_AddDay()
{
Expand Down Expand Up @@ -489,14 +488,16 @@ public void When_Gregorian_FixedDate_AddYear()
}

[TestMethod]
public void When_Gregorian_FixedDate_Format_12h()
[DataRow(2020, "Thursday")]
[DataRow(2021, "Saturday")]
public void When_Gregorian_FixedDate_Format_12h(int year, string dayOfWeek)
{
ValidateFormat(culture: "en-US",
calendar: WG.CalendarIdentifiers.GregorianValue,
clock: WG.ClockIdentifiers.TwelveHour,
date: new DateTimeOffset(2020, 01, 02, 23, 04, 05, 00, TimeSpan.Zero),
yearAsPaddedString: "2020",
yearAsString: "2020",
date: new DateTimeOffset(year, 01, 02, 23, 04, 05, 00, TimeSpan.Zero),
yearAsPaddedString: year.ToString(CultureInfo.InvariantCulture),
yearAsString: year.ToString(CultureInfo.InvariantCulture),
monthAsPaddedNumericString: "01",
monthAsSoloString: "Jan",
monthAsString: "Jan",
Expand All @@ -511,19 +512,21 @@ public void When_Gregorian_FixedDate_Format_12h()
secondAsString: "5",
nanosecondAsPaddedString: "00",
nanosecondAsString: "0",
dayOfWeekAsSoloString: "Thursday",
dayOfWeekAsString: "Thursday");
dayOfWeekAsSoloString: dayOfWeek,
dayOfWeekAsString: dayOfWeek);
}

[TestMethod]
public void When_Gregorian_FixedDate_Format_24h()
[DataRow(2020, "Thursday")]
[DataRow(2021, "Saturday")]
public void When_Gregorian_FixedDate_Format_24h(int year, string dayOfWeek)
{
ValidateFormat(culture: "en-US",
calendar: WG.CalendarIdentifiers.GregorianValue,
clock: WG.ClockIdentifiers.TwentyFourHourValue,
date: new DateTimeOffset(2020, 01, 02, 23, 04, 05, 00, TimeSpan.Zero),
yearAsPaddedString: "2020",
yearAsString: "2020",
date: new DateTimeOffset(year, 01, 02, 23, 04, 05, 00, TimeSpan.Zero),
yearAsPaddedString: year.ToString(CultureInfo.InvariantCulture),
yearAsString: year.ToString(CultureInfo.InvariantCulture),
monthAsPaddedNumericString: "01",
monthAsSoloString: "Jan",
monthAsString: "Jan",
Expand All @@ -538,8 +541,8 @@ public void When_Gregorian_FixedDate_Format_24h()
secondAsString: "5",
nanosecondAsPaddedString: "00",
nanosecondAsString: "0",
dayOfWeekAsSoloString: "Thursday",
dayOfWeekAsString: "Thursday");
dayOfWeekAsSoloString: dayOfWeek,
dayOfWeekAsString: dayOfWeek);
}

private void Validate(
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UWP/Globalization/Calendar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ public string EraAsString(int idealLength)
=> throw new global::System.NotImplementedException("The member string Calendar.EraAsString(int idealLength) is not implemented in Uno.");

public string YearAsString()
=> DateTimeOffset.Now.Year.ToString(_resolvedCulture);
=> _time.Year.ToString(_resolvedCulture);

public string YearAsTruncatedString(int remainingDigits)
=> DateTimeOffset.Now.ToString("yy", _resolvedCulture);
=> _time.ToString("yy", _resolvedCulture);

public string YearAsPaddedString(int minDigits)
=> _time.Year.ToString(new string('0', minDigits), _resolvedCulture);
Expand Down

0 comments on commit 4a31447

Please sign in to comment.