Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Nullable: all calendars (#23469)
Browse files Browse the repository at this point in the history
* calendar

* nullable: all calendars

* fix likely corert error
  • Loading branch information
krwq authored and safern committed Mar 28, 2019
1 parent 5b00a73 commit 90f5615
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;
using System.Runtime.Serialization;

Expand Down Expand Up @@ -322,7 +323,7 @@ public virtual int GetDaysInYear(int year)
/// Get the list of era values.
/// </summary>
/// <returns>The int array of the era names supported in this calendar or null if era is not used.</returns>
public abstract int[] Eras { get; }
public abstract int[]? Eras { get; }

// Returns the hour part of the specified DateTime. The returned value is an
// integer between 0 and 23.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;

namespace System.Globalization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Buffers.Binary;
using System.Diagnostics;
using System.Text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
public static partial class CharUnicodeInfo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <remarks>
Expand Down Expand Up @@ -255,7 +256,7 @@ protected override int DaysInYearBeforeMinSupportedYear

internal override DateTime MaxDate => s_maxDate;

internal override EraInfo[] CalEraInfo => null;
internal override EraInfo[]? CalEraInfo => null;

internal override int GetYearInfo(int lunarYear, int index)
{
Expand Down Expand Up @@ -307,6 +308,6 @@ internal override CalendarId BaseCalendarID
}
}

public override int[] Eras => new int[] { ChineseEra };
public override int[]? Eras => new int[] { ChineseEra };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
public abstract class EastAsianLunisolarCalendar : Calendar
Expand Down Expand Up @@ -69,7 +70,7 @@ public int GetTerrestrialBranch(int sexagenaryYear)

internal abstract int MinCalendarYear { get; }
internal abstract int MaxCalendarYear { get; }
internal abstract EraInfo[] CalEraInfo { get; }
internal abstract EraInfo[]? CalEraInfo { get; }
internal abstract DateTime MinDate { get; }
internal abstract DateTime MaxDate { get; }

Expand All @@ -78,7 +79,7 @@ public int GetTerrestrialBranch(int sexagenaryYear)

internal int MinEraCalendarYear(int era)
{
EraInfo[] eraInfo = CalEraInfo;
EraInfo[]? eraInfo = CalEraInfo;
if (eraInfo == null)
{
return MinCalendarYear;
Expand Down Expand Up @@ -108,7 +109,7 @@ internal int MinEraCalendarYear(int era)

internal int MaxEraCalendarYear(int era)
{
EraInfo[] eraInfo = CalEraInfo;
EraInfo[]? eraInfo = CalEraInfo;
if (eraInfo == null)
{
return MaxCalendarYear;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <remarks>
Expand Down Expand Up @@ -267,7 +268,7 @@ public override int GetDaysInYear(int year, int era)

public override int GetEra(DateTime time) => ADEra;

public override int[] Eras => new int[] { ADEra };
public override int[]? Eras => new int[] { ADEra };

/// <summary>
/// Returns the month part of the specified DateTime.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;

namespace System.Globalization
Expand Down Expand Up @@ -695,7 +696,7 @@ public override int GetDaysInYear(int year, int era)

public override int GetEra(DateTime time) => HebrewEra;

public override int[] Eras => new int[] { HebrewEra };
public override int[]? Eras => new int[] { HebrewEra };

public override int GetMonth(DateTime time)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
public partial class HijriCalendar : Calendar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using Internal.Win32;

namespace System.Globalization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using Internal.Runtime.Augments;

namespace System.Globalization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <remarks>
Expand Down Expand Up @@ -353,7 +354,7 @@ public override int GetEra(DateTime time)
return HijriEra;
}

public override int[] Eras => new int[] { HijriEra };
public override int[]? Eras => new int[] { HijriEra };

public override int GetMonth(DateTime time)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Collections.Generic;
using System.Diagnostics;

namespace System.Globalization
{
public partial class JapaneseCalendar : Calendar
{
private static EraInfo[] GetJapaneseEras()
private static EraInfo[]? GetJapaneseEras()
{
if (GlobalizationMode.Invariant)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;

using Internal.Win32;
Expand All @@ -27,11 +28,11 @@ public partial class JapaneseCalendar : Calendar
// . is a delimiter, but the value of . doesn't matter.
// '_' marks the space between the japanese era name, japanese abbreviated era name
// english name, and abbreviated english names.
private static EraInfo[] GetJapaneseEras()
private static EraInfo[]? GetJapaneseEras()
{
// Look in the registry key and see if we can find any ranges
int iFoundEras = 0;
EraInfo[] registryEraRanges = null;
EraInfo[]? registryEraRanges = null;

try
{
Expand All @@ -51,7 +52,7 @@ private static EraInfo[] GetJapaneseEras()
for (int i = 0; i < valueNames.Length; i++)
{
// See if the era is a valid date
EraInfo era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());
EraInfo? era = GetEraFromValue(valueNames[i], key.GetValue(valueNames[i]).ToString());

// continue if not valid
if (era == null) continue;
Expand Down Expand Up @@ -143,7 +144,7 @@ private static int CompareEraRanges(EraInfo a, EraInfo b)
// . is a delimiter, but the value of . doesn't matter.
// '_' marks the space between the japanese era name, japanese abbreviated era name
// english name, and abbreviated english names.
private static EraInfo GetEraFromValue(string value, string data)
private static EraInfo? GetEraFromValue(string? value, string? data)
{
// Need inputs
if (value == null || data == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;

using Internal.Runtime.Augments;
Expand All @@ -10,7 +11,7 @@ namespace System.Globalization
{
public partial class JapaneseCalendar : Calendar
{
private static EraInfo[] GetJapaneseEras()
private static EraInfo[]? GetJapaneseEras()
{
int erasCount = WinRTInterop.Callbacks.GetJapaneseEraCount();
if (erasCount < 4)
Expand All @@ -25,8 +26,8 @@ private static EraInfo[] GetJapaneseEras()
{
DateTimeOffset dateOffset;

string eraName;
string abbreviatedEraName;
string? eraName;
string? abbreviatedEraName;

if (!GetJapaneseEraInfo(i, out dateOffset, out eraName, out abbreviatedEraName))
{
Expand All @@ -36,7 +37,7 @@ private static EraInfo[] GetJapaneseEras()
DateTime dt = new DateTime(dateOffset.Ticks);

eras[erasCount - i] = new EraInfo(i, dt.Year, dt.Month, dt.Day, dt.Year - 1, 1, lastMaxYear - dt.Year + 1,
eraName, abbreviatedEraName, GetJapaneseEnglishEraName(i)); // era #4 start year/month/day, yearOffset, minEraYear
eraName!, abbreviatedEraName!, GetJapaneseEnglishEraName(i)); // era #4 start year/month/day, yearOffset, minEraYear

lastMaxYear = dt.Year;
}
Expand All @@ -54,9 +55,9 @@ private static string GetJapaneseEnglishEraName(int era)
return era <= s_JapaneseErasEnglishNames.Length ? s_JapaneseErasEnglishNames[era - 1] : " ";
}

private static bool GetJapaneseEraInfo(int era, out DateTimeOffset dateOffset, out string eraName, out string abbreviatedEraName)
private static bool GetJapaneseEraInfo(int era, out DateTimeOffset dateOffset, out string? eraName, out string? abbreviatedEraName)
{
return WinRTInterop.Callbacks.GetJapaneseEraInfo(era, out dateOffset, out eraName, out abbreviatedEraName);
return WinRTInterop.Callbacks.GetJapaneseEraInfo(era, out dateOffset, out eraName, out abbreviatedEraName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <summary>
Expand Down Expand Up @@ -43,7 +44,7 @@ public partial class JapaneseCalendar : Calendar

// Using a field initializer rather than a static constructor so that the whole class can be lazy
// init.
private static volatile EraInfo[] s_japaneseEraInfo;
private static volatile EraInfo[]? s_japaneseEraInfo;

// m_EraInfo must be listed in reverse chronological order. The most recent era
// should be the first element.
Expand All @@ -68,24 +69,16 @@ public partial class JapaneseCalendar : Calendar
internal static EraInfo[] GetEraInfo()
{
// See if we need to build it
if (s_japaneseEraInfo == null)
{
s_japaneseEraInfo = GetJapaneseEras();

return s_japaneseEraInfo ??
(s_japaneseEraInfo = GetJapaneseEras()) ??
// See if we have to use the built-in eras
if (s_japaneseEraInfo == null)
(s_japaneseEraInfo = new EraInfo[]
{
s_japaneseEraInfo = new EraInfo[]
{
new EraInfo(4, 1989, 1, 8, 1988, 1, GregorianCalendar.MaxYear - 1988, "\x5e73\x6210", "\x5e73", "H"),
new EraInfo(3, 1926, 12, 25, 1925, 1, 1989 - 1925, "\x662d\x548c", "\x662d", "S"),
new EraInfo(2, 1912, 7, 30, 1911, 1, 1926 - 1911, "\x5927\x6b63", "\x5927", "T"),
new EraInfo(1, 1868, 1, 1, 1867, 1, 1912 - 1867, "\x660e\x6cbb", "\x660e", "M")
};
}
}

return s_japaneseEraInfo;
new EraInfo(4, 1989, 1, 8, 1988, 1, GregorianCalendar.MaxYear - 1988, "\x5e73\x6210", "\x5e73", "H"),
new EraInfo(3, 1926, 12, 25, 1925, 1, 1989 - 1925, "\x662d\x548c", "\x662d", "S"),
new EraInfo(2, 1912, 7, 30, 1911, 1, 1926 - 1911, "\x5927\x6b63", "\x5927", "T"),
new EraInfo(1, 1868, 1, 1, 1867, 1, 1912 - 1867, "\x660e\x6cbb", "\x660e", "M")
});
}

internal static volatile Calendar s_defaultInstance;
Expand Down Expand Up @@ -220,7 +213,7 @@ public override int ToFourDigitYear(int year)
}


public override int[] Eras => _helper.Eras;
public override int[]? Eras => _helper.Eras;

/// <summary>
/// Return the various era strings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <remarks>
Expand Down Expand Up @@ -142,7 +143,7 @@ protected override int DaysInYearBeforeMinSupportedYear

internal override DateTime MaxDate => s_maxDate;

internal override EraInfo[] CalEraInfo => JapaneseCalendar.GetEraInfo();
internal override EraInfo[]? CalEraInfo => JapaneseCalendar.GetEraInfo();

internal override int GetYearInfo(int lunarYear, int index)
{
Expand Down Expand Up @@ -216,6 +217,6 @@ public JapaneseLunisolarCalendar()

internal override CalendarId ID => CalendarId.JAPANESELUNISOLAR;

public override int[] Eras => _helper.Eras;
public override int[]? Eras => _helper.Eras;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
namespace System.Globalization
{
/// <summary>
Expand Down Expand Up @@ -266,7 +267,7 @@ public override int GetMonth(DateTime time)
return GetDatePart(time.Ticks, DatePartMonth);
}

public override int[] Eras => new int[] { JulianEra };
public override int[]? Eras => new int[] { JulianEra };

public override int GetMonthsInYear(int year, int era)
{
Expand Down
Loading

0 comments on commit 90f5615

Please sign in to comment.