2007-06-01 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Fri, 1 Jun 2007 16:40:20 +0000 (16:40 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Fri, 1 Jun 2007 16:40:20 +0000 (16:40 -0000)
* Calendar.cs DateTimeFormatInfo.cs : 2.0 API fixes.
* CalendricalCalculations.cs : fixed AddMonth() and AddYears() to
  consider that the max days in the target month (for AddYears()
  leap year month could matter). Fixed bug #81783.

* CalendarTest.cs : test for bug #81783 and AddYears() for leap year
  (similar issue).

svn path=/trunk/mcs/; revision=78429

mcs/class/corlib/System.Globalization/Calendar.cs
mcs/class/corlib/System.Globalization/CalendricalCalculations.cs
mcs/class/corlib/System.Globalization/ChangeLog
mcs/class/corlib/System.Globalization/DateTimeFormatInfo.cs
mcs/class/corlib/Test/ChangeLog
mcs/class/corlib/Test/System.Globalization/CalendarTest.cs
mcs/class/corlib/Test/System.Globalization/ChangeLog

index e07b05f4bf88ca12ff23031717f958b23d7ba08e..da3eb3a0a7bc3fb47c15e6499322524ab7ac37e7 100644 (file)
@@ -30,11 +30,15 @@ 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]
+#if NET_2_0
+[ComVisible (true)]
+#endif
 public abstract class Calendar
 #if NET_2_0
        : ICloneable
@@ -152,19 +156,36 @@ public abstract class Calendar
        }
 
        // LAMESPEC: huh, why not Calendar but Object?
+       [ComVisible (false)]
        public virtual object Clone ()
        {
                Calendar c = (Calendar) MemberwiseClone ();
                c.m_isReadOnly = false;
                return c;
        }
+
+       [MonoTODO]
+       [ComVisible (false)]
+       public virtual int GetLeapMonth (int year)
+       {
+               throw new NotImplementedException ();
+       }
+
+       [MonoTODO]
+       [ComVisible (false)]
+       public virtual int GetLeapMonth (int year, int era)
+       {
+               throw new NotImplementedException ();
+       }
 #endif
 
 #if NET_2_0
+       [ComVisible (false)]
        public bool IsReadOnly {
                get { return m_isReadOnly; }
        }
 
+       [ComVisible (false)]
        public static Calendar ReadOnly (Calendar source)
        {
                if (source.m_isReadOnly)
index 9ad2520373d9cb0eb395ca3f4fbe05491410ee5c..e7e0f9e5c5b02655bff2b8ba49f0c1e3cd51fe7e 100644 (file)
@@ -672,6 +672,9 @@ internal class CCGregorianCalendar {
                int day, month, year;
                dmy_from_fixed(out day, out month, out year, rd);
                month += months;
+               int maxday = GetDaysInMonth (year, month);
+               if (day > maxday)
+                       day = maxday;
                rd = fixed_from_dmy(day, month, year);
                System.DateTime t = CCFixed.ToDateTime(rd);
                return t.Add(time.TimeOfDay);
@@ -695,6 +698,9 @@ internal class CCGregorianCalendar {
                int day, month, year;
                dmy_from_fixed(out day, out month, out year, rd);
                year += years;
+               int maxday = GetDaysInMonth (year, month);
+               if (day > maxday)
+                       day = maxday;
                rd = fixed_from_dmy(day, month, year);
                System.DateTime t = CCFixed.ToDateTime(rd);
                return t.Add(time.TimeOfDay);
index 7315b232e3cb26c606ad701aefe4422be685dc4b..1ad6fe72b319f1a62fd46ed1949db005b03b6233 100644 (file)
@@ -1,3 +1,10 @@
+2007-06-01  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Calendar.cs DateTimeFormatInfo.cs : 2.0 API fixes.
+       * CalendricalCalculations.cs : fixed AddMonth() and AddYears() to
+         consider that the max days in the target month (for AddYears()
+         leap year month could matter). Fixed bug #81783.
+
 2007-05-25  Atsushi Enomoto  <atsushi@ximian.com>
 
        * IdnMapping.cs : new 2.0 class.
index 53bdd7ee5e1dc72859995dbc8de0353fbb29854b..2f41441526d5f9d97e52fdb71d9ccc99d010731e 100644 (file)
@@ -32,6 +32,7 @@
 
 using System;
 using System.Collections;
+using System.Runtime.InteropServices;
 using System.Threading;
 
 namespace System.Globalization
@@ -48,6 +49,9 @@ namespace System.Globalization
 #endif
 
        [Serializable]
+#if NET_2_0
+       [ComVisible (true)]
+#endif
        public sealed class DateTimeFormatInfo : ICloneable, IFormatProvider {
                private static readonly string MSG_READONLY = "This instance is read only";
                private static readonly string MSG_ARRAYSIZE_MONTH = "An array with exactly 13 elements is needed";
@@ -765,22 +769,26 @@ namespace System.Globalization
 
 #if NET_2_0
                [MonoTODO ("NotImplemented")]
+               [ComVisible (false)]
                public string [] AbbreviatedMonthGenitiveNames {
                        get { throw new NotImplementedException (); }
                        set { throw new NotImplementedException (); }
                }
 
                [MonoTODO ("NotImplemented")]
+               [ComVisible (false)]
                public string [] MonthGenitiveNames {
                        get { throw new NotImplementedException (); }
                        set { throw new NotImplementedException (); }
                }
 
                [MonoTODO ("NotImplemented")]
-               public string [] NativeCalendarName {
+               [ComVisible (false)]
+               public string NativeCalendarName {
                        get { throw new NotImplementedException (); }
                }
 
+               [ComVisible (false)]
                public string [] ShortestDayNames {
                        get {
                                return shortDayNames;
@@ -801,6 +809,7 @@ namespace System.Globalization
                        }
                }
 
+               [ComVisible (false)]
                public string GetShortestDayName (DayOfWeek dayOfWeek)
                {
                        int index = (int) dayOfWeek;
@@ -811,6 +820,7 @@ namespace System.Globalization
                }
 
                [MonoTODO ("NotImplemented")]
+               [ComVisible (false)]
                public void SetAllDateTimePatterns (string [] patterns, char format)
                {
                        throw new NotImplementedException ();
index 631a60b5c0f3350c4527d1d3737391159751fff2..31ee84cde7726b879e224e21962fab5b4c66b6fe 100644 (file)
@@ -1,4 +1,8 @@
-2007-03-14  Eyal Alaluf <eyala@mainsoft.com>
+2007-05-31  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Makefile : missing EXTRA_DISTFILES.
+
+2007-03-14     Eyal Alaluf <eyala@mainsoft.com>
 
        * Mark tests as not working under TargetJvm
 
@@ -78,7 +82,7 @@
 
        * corlib_test.args: Added EventBuilderTest.cs.  
 
-2003-06-01  Pedro Martínez Juliá  <yoros@wanadoo.es>
+2003-06-01  Pedro Martinez Julia  <yoros@wanadoo.es>
 
        * corlib_test.args: Added SingleFormatterTest.cs
 
index 6aaa18f89b3a08c6fa094bbc341d02acf371c9fc..e6fad68e0082d2bff3830a3333b332a5a5f3f1d4 100644 (file)
@@ -540,6 +540,28 @@ public class CalendarTest : TestCase {
                AssertEquals (29, days);
        }
 
+       [Test] // bug #81783
+       public void GregorianAddMonth ()
+       {
+               GregorianCalendar c = new GregorianCalendar ();
+               DateTime d = new DateTime (2007, 5, 31);
+               DateTime prev = c.AddMonths (d, -1);
+               AssertEquals ("prev", 4, prev.Month);
+               DateTime next = c.AddMonths (d, 1);
+               AssertEquals ("next", 6, next.Month);
+       }
+
+       [Test]
+       public void AddYearOnLeapYear ()
+       {
+               GregorianCalendar c = new GregorianCalendar ();
+               DateTime d = new DateTime (2004, 2, 29);
+               DateTime prev = c.AddYears (d, -1);
+               AssertEquals ("prev", 2, prev.Month);
+               DateTime next = c.AddYears (d, 1);
+               AssertEquals ("next", 2, next.Month);
+       }
+
        /* UK TODO: breaks with current DateTime implementation.
         * I've a newer one that works, but that requires to much changes.
         * for now.
index a969571dc2b6e2a2e7f52421cdc5f1be45425d97..b32e1ea00836efa5443271f69611a17b8f639613 100644 (file)
@@ -1,3 +1,8 @@
+2007-06-01  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * CalendarTest.cs : test for bug #81783 and AddYears() for leap year
+         (similar issue).
+
 2007-05-25  Atsushi Enomoto  <atsushi@ximian.com>
 
        * IdnMappingTest.cs : new test.