10 internal static long PersianEpoch =
new DateTime(622, 3, 22).
Ticks / 864000000000
L;
12 private const int ApproximateHalfYear = 180;
14 internal const int DatePartYear = 0;
16 internal const int DatePartDayOfYear = 1;
18 internal const int DatePartMonth = 2;
20 internal const int DatePartDay = 3;
22 internal const int MonthsPerYear = 12;
24 internal static int[] DaysToMonth =
new int[13]
41 internal const int MaxCalendarYear = 9378;
43 internal const int MaxCalendarMonth = 10;
45 internal const int MaxCalendarDay = 13;
51 private const int DEFAULT_TWO_DIGIT_YEAR_MAX = 1410;
65 internal override int BaseCalendarID => 1;
67 internal override int ID => 22;
71 public override int[]
Eras =>
new int[1]
84 if (twoDigitYearMax == -1)
86 twoDigitYearMax =
Calendar.GetSystemTwoDigitYearSetting(ID, 1410);
88 return twoDigitYearMax;
93 if (value < 99 || value > 9378)
97 twoDigitYearMax = value;
101 private long GetAbsoluteDatePersian(
int year,
int month,
int day)
103 if (year >= 1 && year <= 9378 && month >= 1 && month <= 12)
105 int num = DaysInPreviousMonths(month) + day - 1;
106 int num2 = (int)(365.242189 * (
double)(year - 1));
107 long num3 = CalendricalCalculationsHelper.PersianNewYearOnOrBefore(PersianEpoch + num2 + 180);
113 internal static void CheckTicksRange(
long ticks)
115 if (ticks < minDate.Ticks || ticks > maxDate.
Ticks)
117 throw new ArgumentOutOfRangeException(
"time",
string.
Format(CultureInfo.InvariantCulture, Environment.GetResourceString(
"ArgumentOutOfRange_CalendarRange"), minDate, maxDate));
121 internal static void CheckEraRange(
int era)
125 throw new ArgumentOutOfRangeException(
"era", Environment.GetResourceString(
"ArgumentOutOfRange_InvalidEraValue"));
129 internal static void CheckYearRange(
int year,
int era)
132 if (year < 1 || year > 9378)
134 throw new ArgumentOutOfRangeException(
"year",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, 9378));
138 internal static void CheckYearMonthRange(
int year,
int month,
int era)
140 CheckYearRange(year, era);
141 if (year == 9378 && month > 10)
143 throw new ArgumentOutOfRangeException(
"month",
string.
Format(CultureInfo.CurrentCulture, Environment.GetResourceString(
"ArgumentOutOfRange_Range"), 1, 10));
145 if (month < 1 || month > 12)
147 throw new ArgumentOutOfRangeException(
"month", Environment.GetResourceString(
"ArgumentOutOfRange_Month"));
151 private static int MonthFromOrdinalDay(
int ordinalDay)
154 for (i = 0; ordinalDay > DaysToMonth[i]; i++)
160 private static int DaysInPreviousMonths(
int month)
163 return DaysToMonth[month];
166 internal int GetDatePart(
long ticks,
int part)
168 CheckTicksRange(ticks);
169 long num = ticks / 864000000000
L + 1;
170 long num2 = CalendricalCalculationsHelper.PersianNewYearOnOrBefore(num);
171 int num3 = (int)Math.Floor((
double)(num2 - PersianEpoch) / 365.242189 + 0.5) + 1;
176 int num4 = (int)(num - CalendricalCalculationsHelper.GetNumberOfDays(
ToDateTime(num3, 1, 1, 0, 0, 0, 0, 1)));
181 int num5 = MonthFromOrdinalDay(num4);
186 int result = num4 - DaysInPreviousMonths(num5);
191 throw new InvalidOperationException(Environment.GetResourceString(
"InvalidOperation_DateTimeParsing"));
203 if (months < -120000 || months > 120000)
207 int datePart = GetDatePart(time.
Ticks, 0);
208 int datePart2 = GetDatePart(time.
Ticks, 2);
209 int num = GetDatePart(time.
Ticks, 3);
210 int num2 = datePart2 - 1 + months;
213 datePart2 = num2 % 12 + 1;
214 datePart += num2 / 12;
218 datePart2 = 12 + (num2 + 1) % 12;
219 datePart += (num2 - 11) / 12;
222 if (num > daysInMonth)
226 long ticks = GetAbsoluteDatePersian(datePart, datePart2, num) * 864000000000
L + time.
Ticks % 864000000000
L;
249 return GetDatePart(time.
Ticks, 3);
266 return GetDatePart(time.
Ticks, 1);
278 CheckYearMonthRange(year, month, era);
279 if (month == 10 && year == 9378)
283 int num = DaysToMonth[month] - DaysToMonth[month - 1];
299 CheckYearRange(year, era);
302 return DaysToMonth[9] + 13;
317 CheckTicksRange(time.
Ticks);
327 return GetDatePart(time.
Ticks, 2);
338 CheckYearRange(year, era);
352 return GetDatePart(time.
Ticks, 0);
364 public override bool IsLeapDay(
int year,
int month,
int day,
int era)
367 if (day < 1 || day > daysInMonth)
386 CheckYearRange(year, era);
399 CheckYearMonthRange(year, month, era);
412 CheckYearRange(year, era);
417 return GetAbsoluteDatePersian(year + 1, 1, 1) - GetAbsoluteDatePersian(year, 1, 1) == 366;
432 public override DateTime ToDateTime(
int year,
int month,
int day,
int hour,
int minute,
int second,
int millisecond,
int era)
435 if (day < 1 || day > daysInMonth)
439 long absoluteDatePersian = GetAbsoluteDatePersian(year, month, day);
440 if (absoluteDatePersian >= 0)
442 return new DateTime(absoluteDatePersian * 864000000000
L +
Calendar.TimeToTicks(hour, minute, second, millisecond));
460 return base.ToFourDigitYear(year);
override int GetDayOfMonth(DateTime time)
Returns the day of the month in the specified T:System.DateTime object.
override DateTime AddMonths(DateTime time, int months)
Returns a T:System.DateTime object that is offset the specified number of months from the specified T...
Represents time in divisions, such as weeks, months, and years.
override int GetMonthsInYear(int year, int era)
Returns the number of months in the specified year of the specified era.
override bool IsLeapYear(int year, int era)
Determines whether the specified year in the specified era is a leap year.
The exception that is thrown when the value of an argument is outside the allowable range of values a...
override int TwoDigitYearMax
Gets or sets the last year of a 100-year range that can be represented by a 2-digit year.
Represents an instant in time, typically expressed as a date and time of day. To browse the ....
override int GetYear(DateTime time)
Returns the year in the specified T:System.DateTime object.
override DayOfWeek GetDayOfWeek(DateTime time)
Returns the day of the week in the specified T:System.DateTime object.
override int ToFourDigitYear(int year)
Converts the specified year to a four-digit year representation.
Provides information about, and means to manipulate, the current environment and platform....
override int GetLeapMonth(int year, int era)
Returns the leap month for a specified year and era.
override int GetEra(DateTime time)
Returns the era in the specified T:System.DateTime object.
override bool IsLeapDay(int year, int month, int day, int era)
Determines whether the specified date is a leap day.
override CalendarAlgorithmType AlgorithmType
Gets a value indicating whether the current calendar is solar-based, lunar-based, or lunisolar-based.
static readonly DateTime MaxValue
Represents the largest possible value of T:System.DateTime. This field is read-only.
override DateTime MaxSupportedDateTime
Gets the latest date and time supported by the T:System.Globalization.PersianCalendar class.
override DateTime AddYears(DateTime time, int years)
Returns a T:System.DateTime object that is offset the specified number of years from the specified T:...
Format character that affects the layout of text or the operation of text processes,...
override int GetDayOfYear(DateTime time)
Returns the day of the year in the specified T:System.DateTime object.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
override int GetDaysInMonth(int year, int month, int era)
Returns the number of days in the specified month of the specified year and era.
static readonly int PersianEra
Represents the current era. This field is constant.
Represents the Persian calendar.
CalendarAlgorithmType
Specifies whether a calendar is solar-based, lunar-based, or lunisolar-based.
Specifies that the class can be serialized.
override bool IsLeapMonth(int year, int month, int era)
Determines whether the specified month in the specified year and era is a leap month.
override int GetMonth(DateTime time)
Returns the month in the specified T:System.DateTime object.
override DateTime ToDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era)
Returns a T:System.DateTime object that is set to the specified date, time, and era.
Provides information about a specific culture (called a locale for unmanaged code development)....
override int [] Eras
Gets the list of eras in a T:System.Globalization.PersianCalendar object.
DayOfWeek
Specifies the day of the week.
override DateTime MinSupportedDateTime
Gets the earliest date and time supported by the T:System.Globalization.PersianCalendar class.
long Ticks
Gets the number of ticks that represent the date and time of this instance.
override int GetDaysInYear(int year, int era)
Returns the number of days in the specified year of the specified era.