14 internal static readonly
DateTime calendarMinValue =
new DateTime(1868, 9, 8);
16 internal static volatile EraInfo[] japaneseEraInfo;
18 private const string c_japaneseErasHive =
"System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras";
20 private const string c_japaneseErasHivePermissionList =
"HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras";
22 internal static volatile Calendar s_defaultInstance;
24 internal GregorianCalendarHelper helper;
26 private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 99;
35 return calendarMinValue;
61 internal override int ID => 3;
65 public override int[]
Eras => helper.Eras;
75 if (twoDigitYearMax == -1)
77 twoDigitYearMax =
Calendar.GetSystemTwoDigitYearSetting(ID, 99);
79 return twoDigitYearMax;
84 if (value < 99 || value > helper.MaxYear)
88 twoDigitYearMax = value;
92 internal static EraInfo[] GetEraInfo()
94 if (japaneseEraInfo ==
null)
96 japaneseEraInfo = GetErasFromRegistry();
97 if (japaneseEraInfo ==
null)
99 japaneseEraInfo =
new EraInfo[4]
101 new EraInfo(4, 1989, 1, 8, 1988, 1, 8011,
"平成",
"平",
"H"),
102 new EraInfo(3, 1926, 12, 25, 1925, 1, 64,
"昭和",
"昭",
"S"),
103 new EraInfo(2, 1912, 7, 30, 1911, 1, 15,
"大正",
"大",
"T"),
104 new EraInfo(1, 1868, 1, 1, 1867, 1, 45,
"明治",
"明",
"M")
108 return japaneseEraInfo;
111 [SecuritySafeCritical]
112 private static EraInfo[] GetErasFromRegistry()
115 EraInfo[] array =
null;
121 RegistryKey registryKey =
RegistryKey.GetBaseKey(
RegistryKey.HKEY_LOCAL_MACHINE).OpenSubKey(
"System\\CurrentControlSet\\Control\\Nls\\Calendars\\Japanese\\Eras", writable:
false);
122 if (registryKey ==
null)
126 string[] valueNames = registryKey.GetValueNames();
127 if (valueNames !=
null && valueNames.Length != 0)
129 array =
new EraInfo[valueNames.Length];
130 for (
int i = 0; i < valueNames.Length; i++)
132 EraInfo eraFromValue = GetEraFromValue(valueNames[i], registryKey.GetValue(valueNames[i]).ToString());
133 if (eraFromValue !=
null)
135 array[num] = eraFromValue;
149 catch (UnauthorizedAccessException)
157 Array.Resize(ref array, num);
158 Array.Sort(array, CompareEraRanges);
159 for (
int j = 0; j < array.Length; j++)
161 array[j].era = array.Length - j;
164 array[0].maxEraYear = 9999 - array[0].yearOffset;
168 array[j].maxEraYear = array[j - 1].yearOffset + 1 - array[j].yearOffset;
174 private static int CompareEraRanges(EraInfo a, EraInfo b)
176 return b.ticks.CompareTo(a.ticks);
179 private static EraInfo GetEraFromValue(
string value,
string data)
181 if (value ==
null || data ==
null)
185 if (value.Length != 10)
189 if (!
Number.TryParseInt32(value.Substring(0, 4),
NumberStyles.None, NumberFormatInfo.InvariantInfo, out
int result) || !
Number.TryParseInt32(value.Substring(5, 2),
NumberStyles.None, NumberFormatInfo.InvariantInfo, out
int result2) || !
Number.TryParseInt32(value.Substring(8, 2),
NumberStyles.None, NumberFormatInfo.InvariantInfo, out
int result3))
193 string[] array = data.Split(
'_');
194 if (array.Length != 4)
198 if (array[0].Length == 0 || array[1].Length == 0 || array[2].Length == 0 || array[3].Length == 0)
202 return new EraInfo(0, result, result2, result3, result - 1, 1, 0, array[0], array[1], array[3]);
205 internal static Calendar GetDefaultInstance()
207 if (s_defaultInstance ==
null)
211 return s_defaultInstance;
226 helper =
new GregorianCalendarHelper(
this, GetEraInfo());
252 return helper.
AddYears(time, years);
266 return helper.GetDaysInMonth(year, month, era);
278 return helper.GetDaysInYear(year, era);
286 return helper.GetDayOfMonth(time);
294 return helper.GetDayOfWeek(time);
302 return helper.GetDayOfYear(time);
314 return helper.GetMonthsInYear(year, era);
328 return helper.GetWeekOfYear(time, rule, firstDayOfWeek);
337 return helper.GetEra(time);
345 return helper.GetMonth(time);
353 return helper.GetYear(time);
368 public override bool IsLeapDay(
int year,
int month,
int day,
int era)
370 return helper.IsLeapDay(year, month, day, era);
383 return helper.IsLeapYear(year, era);
395 return helper.GetLeapMonth(year, era);
409 return helper.IsLeapMonth(year, month, era);
431 public override DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era)
433 return helper.
ToDateTime(year, month, day, hour, minute, second, millisecond, era);
447 if (year > helper.MaxYear)
454 internal static string[] EraNames()
456 EraInfo[] eraInfo = GetEraInfo();
457 string[] array =
new string[eraInfo.Length];
458 for (
int i = 0; i < eraInfo.Length; i++)
460 array[i] = eraInfo[eraInfo.Length - i - 1].eraName;
465 internal static string[] AbbrevEraNames()
467 EraInfo[] eraInfo = GetEraInfo();
468 string[] array =
new string[eraInfo.Length];
469 for (
int i = 0; i < eraInfo.Length; i++)
471 array[i] = eraInfo[eraInfo.Length - i - 1].abbrevEraName;
476 internal static string[] EnglishEraNames()
478 EraInfo[] eraInfo = GetEraInfo();
479 string[] array =
new string[eraInfo.Length];
480 for (
int i = 0; i < eraInfo.Length; i++)
482 array[i] = eraInfo[eraInfo.Length - i - 1].englishEraName;
487 internal override bool IsValidYear(
int year,
int era)
489 return helper.IsValidYear(year, era);
override int GetWeekOfYear(DateTime time, CalendarWeekRule rule, DayOfWeek firstDayOfWeek)
Returns the week of the year that includes the date in the specified T:System.DateTime.
DateTime AddYears(int value)
Returns a new T:System.DateTime that adds the specified number of years to the value of this instance...
The exception that is thrown as a wrapper around the exception thrown by the class initializer....
override int GetDaysInMonth(int year, int month, int era)
Returns the number of days in the specified month in the specified year in the specified era.
Represents time in divisions, such as weeks, months, and years.
override int [] Eras
Gets the list of eras in the T:System.Globalization.JapaneseCalendar.
Controls the ability to access registry variables. This class cannot be inherited.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year in the specified era.
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
Calendar()
Initializes a new instance of the T:System.Globalization.Calendar class.
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime.
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date in the specified era is a leap day.
override bool IsLeapMonth(int year, int month, int era)
Determines whether the specified month in the specified year in the specified era is a leap month.
override DateTime AddYears(DateTime time, int years)
Returns a T:System.DateTime that is the specified number of years away from the specified T:System....
override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
Returns a T:System.DateTime that is set to the specified date and time in the specified era.
IPermission AddPermission(IPermission perm)
Adds a specified permission to the T:System.Security.PermissionSet.
NumberStyles
Determines the styles permitted in numeric string arguments that are passed to the Parse and TryParse...
Indicates that the F:System.Globalization.NumberStyles.AllowLeadingWhite, F:System....
Provides information about, and means to manipulate, the current environment and platform....
Represents a collection that can contain many different types of permissions.
override CalendarAlgorithmType AlgorithmType
Gets a value that indicates whether the current calendar is solar-based, lunar-based,...
Represents the Japanese calendar.
DateTime AddMonths(int months)
Returns a new T:System.DateTime that adds the specified number of months to the value of this instanc...
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
The exception that is thrown when an I/O error occurs.
override int GetLeapMonth(int year, int era)
Calculates the leap month for a specified year and era.
Format character that affects the layout of text or the operation of text processes,...
override DateTime AddMonths(DateTime time, int months)
Returns a T:System.DateTime that is the specified number of months away from the specified T:System....
DateTime IConvertible. ToDateTime(IFormatProvider provider)
Returns the current T:System.DateTime object.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime.
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
The exception that is thrown when one of the arguments provided to a method is not valid.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the current T:System.Globalization.JapaneseCalendar obje...
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime.
CalendarWeekRule
Defines different rules for determining the first week of the year.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
JapaneseCalendar()
Initializes a new instance of the T:System.Globalization.JapaneseCalendar class.
Specifies that the class can be serialized.
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year in the specified era.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides information about a specific culture (called a locale for unmanaged code development)....
override int ToFourDigitYear(int year)
Converts the specified year to a four-digit year by using the P:System.Globalization....
RegistryPermissionAccess
Specifies the permitted access to registry keys and values.
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime.
The exception that is thrown when a security error is detected.
DayOfWeek
Specifies the day of the week.
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the current T:System.Globalization.JapaneseCalendar object...
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.