1 // Licensed to the .NET Foundation under one or more agreements.
2 // The .NET Foundation licenses this file to you under the MIT license.
3 // See the LICENSE file in the project root for more information.
7 namespace System
.Globalization
9 public partial class HijriCalendar
: Calendar
11 private int GetHijriDateAdjustment()
13 if (_hijriAdvance
== int.MinValue
)
15 // Never been set before. Use the system value from registry.
16 _hijriAdvance
= GetAdvanceHijriDate();
21 private const string InternationalRegKey
= "Control Panel\\International";
22 private const string HijriAdvanceRegKeyEntry
= "AddHijriDate";
24 /*=================================GetAdvanceHijriDate==========================
25 **Action: Gets the AddHijriDate value from the registry.
30 ** The HijriCalendar has a user-overidable calculation. That is, use can set a value from the control
31 ** panel, so that the calculation of the Hijri Calendar can move ahead or backwards from -2 to +2 days.
33 ** The valid string values in the registry are:
34 ** "AddHijriDate-2" => Add -2 days to the current calculated Hijri date.
35 ** "AddHijriDate" => Add -1 day to the current calculated Hijri date.
36 ** "" => Add 0 day to the current calculated Hijri date.
37 ** "AddHijriDate+1" => Add +1 days to the current calculated Hijri date.
38 ** "AddHijriDate+2" => Add +2 days to the current calculated Hijri date.
39 ============================================================================*/
40 private static int GetAdvanceHijriDate()
42 using (RegistryKey
? key
= Registry
.CurrentUser
.OpenSubKey(InternationalRegKey
))
44 // Abort if we didn't find anything
50 object? value = key
.GetValue(HijriAdvanceRegKeyEntry
);
57 string? str
= value.ToString();
58 if (string.Compare(str
, 0, HijriAdvanceRegKeyEntry
, 0, HijriAdvanceRegKeyEntry
.Length
, StringComparison
.OrdinalIgnoreCase
) == 0)
60 if (str
!.Length
== HijriAdvanceRegKeyEntry
.Length
)
66 int advance
= int.Parse(str
.AsSpan(HijriAdvanceRegKeyEntry
.Length
), provider
: CultureInfo
.InvariantCulture
);
67 if ((advance
>= MinAdvancedHijri
) && (advance
<= MaxAdvancedHijri
))
69 hijriAdvance
= advance
;
72 // If we got garbage from registry just ignore it.
73 // hijriAdvance = 0 because of declaraction assignment up above.
74 catch (ArgumentException
) { }
75 catch (FormatException
) { }
76 catch (OverflowException
) { }