Merge pull request #303 from ermshiperete/5278
[mono.git] / mcs / class / corlib / System.Globalization / Calendar.cs
index c4d27e01f53c5683a24c29a4017f23a858cde635..9cbb0225b057b0026fc6764a774dcea910ab31d6 100644 (file)
@@ -1,4 +1,4 @@
-// Calendar.cs
+// System.Globalization.Calendar.cs
 //
 // (C) Ulrich Kunitz 2002
 //
@@ -30,15 +30,14 @@ namespace System.Globalization {
 
 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>
@@ -127,15 +126,16 @@ public abstract class Calendar
        public abstract int[] Eras { get; }
 
        [NonSerialized]
-       bool is_readonly;
+       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 {
@@ -152,41 +152,48 @@ public abstract class Calendar
        }
 
        // 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.");
        }
 
@@ -196,7 +203,7 @@ public abstract class Calendar
        /// property.
        /// </summary>
        [NonSerialized]
-       internal int M_TwoDigitYearMax;
+       internal int twoDigitYearMax;
        
 
        /// <summary>
@@ -227,7 +234,17 @@ public abstract class Calendar
        /// <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
@@ -237,13 +254,13 @@ public abstract class Calendar
        /// <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;
                }
        }
 
@@ -867,10 +884,10 @@ public abstract class Calendar
        /// 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);
        }
 
 
@@ -904,7 +921,7 @@ public abstract class Calendar
        /// 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>
@@ -947,7 +964,7 @@ public abstract class Calendar
        /// 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.
@@ -1010,6 +1027,10 @@ public abstract class Calendar
                        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
+}