-// HebrewCalendar.cs
+// System.Globalization.HebrewCalendar.cs
//
// (C) Ulrich Kunitz 2002
//
using System;
using System.IO;
+using System.Runtime.InteropServices;
/// <summary>
/// This is the Hebrew calendar.
/// </para>
/// </remarks>
[Serializable]
-[MonoTODO ("Fix serialization compatibility with MS.NET")]
+[MonoLimitation ("Serialization format not compatible with.NET")]
public class HebrewCalendar : Calendar {
/// <summary>
/// Constructor.
public HebrewCalendar() {
M_AbbrEraNames = new string[] {"A.M."};
M_EraNames = new string[] {"Anno Mundi"};
- if (M_TwoDigitYearMax == 99)
- M_TwoDigitYearMax = 5790;
+ if (twoDigitYearMax == 99)
+ twoDigitYearMax = 5790;
}
/// <summary>
}
}
- int twoDigitYearMax = 5790;
-
public override int TwoDigitYearMax
{
get {
return twoDigitYearMax;
}
set {
+ CheckReadOnly ();
M_ArgumentInRange ("value", value, M_MinYear, M_MaxYear);
twoDigitYearMax = value;
era));
}
-#if false
- //
- // The following routines are commented out as they do not appear on the .NET Framework 1.1
- //
-
- /// <summary>
- /// Overridden. Adds days to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// days.
- /// </param>
- /// <param name="days">The number of days to add.</param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="days"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddDays(DateTime time, int days) {
- DateTime t = base.AddDays(time, days);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Adds hours to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// hours.
- /// </param>
- /// <param name="hours">The number of hours to add.</param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="hours"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddHours(DateTime time, int hours) {
- DateTime t = base.AddHours(time, hours);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Adds milliseconds to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// milliseconds.
- /// </param>
- /// <param name="milliseconds">The number of milliseconds given as
- /// double to add. Keep in mind the 100 nanosecond resolution of
- /// <see cref="T:System.DateTime"/>.
- /// </param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="milliseconds"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddMilliseconds(DateTime time,
- double milliseconds)
- {
- DateTime t = base.AddMilliseconds(time, milliseconds);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Adds minutes to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// minutes.
- /// </param>
- /// <param name="minutes">The number of minutes to add.</param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="minutes"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddMinutes(DateTime time, int minutes) {
- DateTime t = base.AddMinutes(time, minutes);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Adds seconds to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// seconds.
- /// </param>
- /// <param name="seconds">The number of seconds to add.</param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="seconds"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddSeconds(DateTime time, int seconds) {
- DateTime t = base.AddSeconds(time, seconds);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Adds weeks to a given date.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> to which to add
- /// weeks.
- /// </param>
- /// <param name="weeks">The number of weeks to add.</param>
- /// <returns>A new <see cref="T:System.DateTime"/> value, that
- /// results from adding <paramref name="weeks"/> to the specified
- /// DateTime.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> return value is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override DateTime AddWeeks(DateTime time, int weeks) {
- DateTime t = base.AddWeeks(time, weeks);
- M_CheckDateTime(t);
- return t;
- }
-
- /// <summary>
- /// Overridden. Gives the hour of the specified time.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> that specifies the
- /// time.
- /// </param>
- /// <returns>An integer that gives the hour of the specified time,
- /// starting with 0.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> parameter is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override int GetHour(DateTime time) {
- M_CheckDateTime(time);
- return base.GetHour(time);
- }
-
- /// <summary>
- /// Overridden. Gives the milliseconds in the current second
- /// of the specified time.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> that specifies the
- /// time.
- /// </param>
- /// <returns>An integer that gives the milliseconds in the seconds
- /// of the specified time, starting with 0.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> parameter is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override double GetMilliseconds(DateTime time) {
- M_CheckDateTime(time);
- return base.GetMilliseconds(time);
- }
-
- /// <summary>
- /// Overridden. Gives the minute of the specified time.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> that specifies the
- /// time.
- /// </param>
- /// <returns>An integer that gives the minute of the specified time,
- /// starting with 0.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> parameter is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override int GetMinute(DateTime time) {
- M_CheckDateTime(time);
- return base.GetMinute(time);
- }
-
- /// <summary>
- /// Overridden. Gives the second of the specified time.
- /// </summary>
- /// <param name="time">The
- /// <see cref="T:System.DateTime"/> that specifies the
- /// time.
- /// </param>
- /// <returns>An integer that gives the second of the specified time,
- /// starting with 0.</returns>
- /// <exception cref="T:System.ArgumentOutOfRangeException">
- /// The exception is thrown if the
- /// <see cref="T:System.DateTime"/> parameter is not in the years
- /// between 5343 A.M. and 6000 A.M., inclusive.
- /// </exception>
- public override int GetSecond(DateTime time) {
- M_CheckDateTime(time);
- return base.GetMinute(time);
- }
-#endif
/// <summary>
/// Overrideden. Adds months to a given date.
/// <remarks>
/// <para>
/// In .NET the month counting starts with the Hebrew month Tishri.
- /// Calendrical Calculations starts with the month Tisan. So we must
+ /// Calendrical Calculations starts with the month Nisan. So we must
/// map here.
/// </para>
/// </remarks>
public override int GetDaysInMonth(int year, int month, int era) {
M_CheckYME(year, month, ref era);
int ccmonth = M_CCMonth(month, year);
- int rd1 = CCHebrewCalendar.fixed_from_dmy(1, ccmonth, year);
- int rd2 = CCHebrewCalendar.fixed_from_dmy(1, ccmonth+1, year);
- return rd2 - rd1;
+ return CCHebrewCalendar.last_day_of_month(ccmonth, year);
}
/// <summary>
return HebrewEra;
}
+ public override int GetLeapMonth (int year, int era)
+ {
+ return IsLeapMonth (year, 7, era) ? 7 : 0;
+ }
+
/// <summary>
/// Overridden. Gives the number of the month of the specified
/// date.
/// is out of range.
/// </exception>
public override DateTime ToDateTime(int year, int month, int day,
- int hour, int minute, int second, int milliseconds,
+ int hour, int minute, int second, int millisecond,
int era)
{
M_CheckYMDE(year, month, day, ref era);
- M_CheckHMSM(hour, minute, second, milliseconds);
+ M_CheckHMSM(hour, minute, second, millisecond);
int ccm = M_CCMonth(month, year);
int rd = CCHebrewCalendar.fixed_from_dmy(day, ccm, year);
return CCFixed.ToDateTime(rd,
- hour, minute, second, milliseconds);
+ hour, minute, second, millisecond);
}
public override int ToFourDigitYear (int year)
{
- M_ArgumentInRange ("year", year, 0, 99);
+ M_ArgumentInRange ("year", year, 0, M_MaxYear - 1);
int baseExtra = this.twoDigitYearMax % 100;
int baseCentury = this.twoDigitYearMax - baseExtra;
+ if (year >= 100)
+ return year;
if (year <= baseExtra)
return baseCentury + year;
else
return baseCentury + year - 100;
}
-#if NET_2_0
+#if !NET_2_1
public override CalendarAlgorithmType AlgorithmType {
get {
return CalendarAlgorithmType.LunisolarCalendar;
}
}
+#endif
static DateTime Min = new DateTime (1583, 1, 1, 0, 0, 0);
static DateTime Max = new DateTime (2239, 9, 29, 11, 59, 59);
return Max;
}
}
-#endif
-
} // class HebrewCalendar
} // namespace System.Globalization