-// Calendar.cs
+// System.Globalization.Calendar.cs
//
// (C) Ulrich Kunitz 2002
//
using System;
using System.IO;
+using System.Runtime.InteropServices;
/// <remarks>
/// The class serves as a base class for calendar classes.
/// </remarks>
[Serializable]
-public abstract class Calendar
-#if NET_2_0
- : ICloneable
-#endif
+[ComVisible (true)]
+public abstract class Calendar : ICloneable
{
/// <value>An protected integer property that gives the number of
/// days in a week. It might be overridden.</value>
/// </value>
public abstract int[] Eras { get; }
- bool is_readonly;
+ [NonSerialized]
+ bool m_isReadOnly;
-#if NET_2_0
+#if !MOONLIGHT
[System.Runtime.InteropServices.ComVisible(false)]
public virtual CalendarAlgorithmType AlgorithmType {
get {
return CalendarAlgorithmType.Unknown;
}
}
+#endif
[System.Runtime.InteropServices.ComVisible(false)]
public virtual DateTime MaxSupportedDateTime {
}
// LAMESPEC: huh, why not Calendar but Object?
+ [ComVisible (false)]
public virtual object Clone ()
{
Calendar c = (Calendar) MemberwiseClone ();
- c.is_readonly = false;
+ c.m_isReadOnly = false;
return c;
}
-#endif
-#if NET_2_0
- public bool IsReadOnly {
- get { return is_readonly; }
+ [ComVisible (false)]
+ public virtual int GetLeapMonth (int year)
+ {
+ return GetLeapMonth (year, GetEra (ToDateTime (year, 1, 1, 0, 0, 0, 0)));
}
- public static Calendar ReadOnly (Calendar source)
+ [ComVisible (false)]
+ public virtual int GetLeapMonth (int year, int era)
{
- if (source.is_readonly)
- return source;
- Calendar c = (Calendar) source.Clone ();
- c.is_readonly = true;
- return c;
+ int max = GetMonthsInYear (year, era);
+ for (int i = 1; i <= max; i++)
+ if (IsLeapMonth (year, i, era))
+ return i;
+ return 0;
}
-#else
- internal bool IsReadOnly {
- get { return false; }
+
+ [ComVisible (false)]
+ public bool IsReadOnly {
+ get { return m_isReadOnly; }
}
- internal static Calendar ReadOnly (Calendar source)
+ [ComVisible (false)]
+ public static Calendar ReadOnly (Calendar calendar)
{
- return source;
+ if (calendar.m_isReadOnly)
+ return calendar;
+ Calendar c = (Calendar) calendar.Clone ();
+ c.m_isReadOnly = true;
+ return c;
}
-#endif
internal void CheckReadOnly ()
{
- if (is_readonly)
+ if (m_isReadOnly)
throw new InvalidOperationException ("This Calendar is read-only.");
}
/// <see cref="P:TwoDigitYearMax"/>
/// property.
/// </summary>
- internal int M_TwoDigitYearMax;
+ [NonSerialized]
+ internal int twoDigitYearMax;
/// <summary>
/// Private field containing the maximum year for the calendar.
/// </summary>
+ [NonSerialized]
private int M_MaxYearValue = 0;
/// <value>
/// <exception cref="T:ArgumentOutOfRangeException">
/// The exception will be thrown, if the year is not valid.
/// </exception>
- internal abstract void M_CheckYE(int year, ref int era);
+ internal virtual void M_CheckYE(int year, ref int era)
+ {
+ //
+ // By default, we do nothing.
+ //
+ // This used to be an abstract method in Mono's implementation,
+ // but that means that end-user code could not create their
+ // own calendars.
+ //
+ // Binaries would also crash in this condition.
+ }
/// <value>
/// <para>The property gives the maximum value for years with two
/// <para>It might be overridden.</para>
/// </value>
public virtual int TwoDigitYearMax {
- get { return M_TwoDigitYearMax; }
+ get { return twoDigitYearMax; }
set {
CheckReadOnly ();
M_ArgumentInRange("year", value, 100, M_MaxYear);
int era = CurrentEra;
M_CheckYE(value, ref era);
- M_TwoDigitYearMax = value;
+ twoDigitYearMax = value;
}
}
/// is out of range.
/// </exception>
public virtual DateTime ToDateTime(int year, int month, int day,
- int hour, int minute, int second, int milliseconds)
+ int hour, int minute, int second, int millisecond)
{
- return ToDateTime(year, month, day, hour, minute, second,
- milliseconds, CurrentEra);
+ return ToDateTime (year, month, day, hour, minute, second,
+ millisecond, CurrentEra);
}
/// is out of range.
/// </exception>
public abstract 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);
/// <summary>
/// in the ctors of the derived classes, if it is 99.
/// </remarks>
protected Calendar() {
- M_TwoDigitYearMax = 99;
+ twoDigitYearMax = 99;
}
/// <summary>Protected field storing the abbreviated era names.
/// </summary>
+ [NonSerialized]
internal string[] M_AbbrEraNames;
/// <summary>Protected field storing the era names.
/// </summary>
+ [NonSerialized]
internal string[] M_EraNames;
/// <value>
M_EraNames = (string[])value.Clone();
}
}
-} // class Calendar
+
+#pragma warning disable 649
+ internal int m_currentEraValue; // Unused, by MS serializes this
+#pragma warning restore 649
+}
-} // namespace System.Globalization
+}