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 == Int32.MinValue)
15 // Never been set before. Use the system value from registry.
16 _hijriAdvance = GetAdvanceHijriDate();
18 return (_hijriAdvance);
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()
43 Microsoft.Win32.RegistryKey key = null;
47 // Open in read-only mode.
48 key = RegistryKey.GetBaseKey(RegistryKey.HKEY_CURRENT_USER).OpenSubKey(InternationalRegKey, false);
50 //If this fails for any reason, we'll just return 0.
51 catch (ObjectDisposedException) { return 0; }
52 catch (ArgumentException) { return 0; }
58 Object value = key.InternalGetValue(HijriAdvanceRegKeyEntry, null, false, false);
63 String str = value.ToString();
64 if (String.Compare(str, 0, HijriAdvanceRegKeyEntry, 0, HijriAdvanceRegKeyEntry.Length, StringComparison.OrdinalIgnoreCase) == 0)
66 if (str.Length == HijriAdvanceRegKeyEntry.Length)
72 int advance = Int32.Parse(str.AsSpan().Slice(HijriAdvanceRegKeyEntry.Length), provider:CultureInfo.InvariantCulture);
73 if ((advance >= MinAdvancedHijri) && (advance <= MaxAdvancedHijri))
75 hijriAdvance = advance;
78 // If we got garbage from registry just ignore it.
79 // hijriAdvance = 0 because of declaraction assignment up above.
80 catch (ArgumentException) { }
81 catch (FormatException) { }
82 catch (OverflowException) { }
91 return (hijriAdvance);