dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] pnetlib/runtime/System/Globalization JalaaliCalend


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] pnetlib/runtime/System/Globalization JalaaliCalendar.cs, NONE, 1.1 Calendar.cs, 1.5, 1.6 GregorianCalendar.cs, 1.4, 1.5 HebrewCalendar.cs, 1.6, 1.7 HijriCalendar.cs, 1.3, 1.4 JapaneseCalendar.cs, 1.2, 1.3 JulianCalendar.cs, 1.3, 1.4 KoreanCalendar.cs, 1.2, 1.3 TaiwanCalendar.cs, 1.2, 1.3 ThaiBuddhistCalendar.cs, 1.2, 1.3
Date: Thu, 13 Nov 2003 03:06:53 +0000

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization
In directory subversions:/tmp/cvs-serv20994/runtime/System/Globalization

Modified Files:
        Calendar.cs GregorianCalendar.cs HebrewCalendar.cs 
        HijriCalendar.cs JapaneseCalendar.cs JulianCalendar.cs 
        KoreanCalendar.cs TaiwanCalendar.cs ThaiBuddhistCalendar.cs 
Added Files:
        JalaaliCalendar.cs 
Log Message:


Add the Jalaali calendar; fix some bugs in the Julian and
Hebrew calendars; add the 1.2 MinValue and MaxValue properties.


Index: TaiwanCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/TaiwanCalendar.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** TaiwanCalendar.cs   23 Apr 2003 05:39:49 -0000      1.2
--- TaiwanCalendar.cs   13 Nov 2003 03:06:51 -0000      1.3
***************
*** 73,76 ****
--- 73,99 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       // Return the first day in era 1 as the 
minimum.
+                                       return ToDateTime(1, 1, 1, 0, 0, 0, 0, 
1);
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
+ 
        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)

Index: JapaneseCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/JapaneseCalendar.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** JapaneseCalendar.cs 23 Apr 2003 05:39:49 -0000      1.2
--- JapaneseCalendar.cs 13 Nov 2003 03:06:51 -0000      1.3
***************
*** 85,88 ****
--- 85,111 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       // Return the first day in era 1 as the 
minimum.
+                                       return ToDateTime(1, 1, 1, 0, 0, 0, 0, 
1);
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
+ 
        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)

Index: JulianCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/JulianCalendar.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** JulianCalendar.cs   23 Apr 2003 05:39:49 -0000      1.3
--- JulianCalendar.cs   13 Nov 2003 03:06:51 -0000      1.4
***************
*** 3,7 ****
   *        "System.Globalization.JulianCalendar" class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 3,7 ----
   *        "System.Globalization.JulianCalendar" class.
   *
!  * Copyright (C) 2001, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 34,37 ****
--- 34,41 ----
        private const int DaysPer4Years = (365 * 4 + 1);
  
+       // Jan 1, 0001 AD is Jan 3, 0001 Julian.  This value is used to
+       // adjust day numbers to account for the discrepancy.
+       private const long EpochAdjust = 2;
+ 
        // Constructors.
        public JulianCalendar()
***************
*** 79,82 ****
--- 83,108 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return DateTime.MinValue;
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
+ 
        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)
***************
*** 162,167 ****
        public override int GetDayOfYear(DateTime time)
                        {
!                               long ticks = time.Ticks - 
YearToTicks(GetYear(time));
!                               return (int)((ticks / TimeSpan.TicksPerDay) + 
1);
                        }
        public override int GetMonth(DateTime time)
--- 188,202 ----
        public override int GetDayOfYear(DateTime time)
                        {
!                               // Get the year value.
!                               int year = GetYear(time);
! 
!                               // Convert the tick count into a day value.
!                               long days = time.Ticks / TimeSpan.TicksPerDay;
! 
!                               // Adjust for the difference in epochs.
!                               days += EpochAdjust;
! 
!                               // Return the day number within the year.
!                               return unchecked((int)((days - 
YearToDays(year)) + 1));
                        }
        public override int GetMonth(DateTime time)
***************
*** 201,204 ****
--- 236,242 ----
                                int days = unchecked((int)(time.Ticks / 
TimeSpan.TicksPerDay));
  
+                               // Adjust for the difference in epochs.
+                               days += (int)EpochAdjust;
+ 
                                // Determine the 4-year cycle that contains the 
date.
                                int yearBase = ((days / DaysPer4Years) * 4) + 1;
***************
*** 347,352 ****
                        }
  
!       // Convert a year into a number of ticks.
!       private static long YearToTicks(int year)
                        {
                                --year;
--- 385,390 ----
                        }
  
!       // Convert a Julian year into a day number.
!       private static long YearToDays(int year)
                        {
                                --year;
***************
*** 354,357 ****
--- 392,427 ----
                        }
  
+       // Determine if a Julian date is in range (0001/01/03 - 9999-10-19).
+       private static bool CheckDateRange(int year, int month, int day)
+                       {
+                               if(year == 1 && month == 1)
+                               {
+                                       return (day >= 3 && day <= 31);
+                               }
+                               else if(year == 9999 && month > 10)
+                               {
+                                       return false;
+                               }
+                               else if(year == 9999 && month == 10 && day > 19)
+                               {
+                                       return false;
+                               }
+                               else if(year < 1 || year > 9999 || month < 1 || 
month > 12)
+                               {
+                                       return false;
+                               }
+                               else if(day < 1)
+                               {
+                                       return false;
+                               }
+                               bool isLeap = ((year % 4) == 0);
+                               int daysInMonth = 
DateTime.daysForEachMonth[month - 1];
+                               if(month == 2 && isLeap)
+                               {
+                                       ++daysInMonth;
+                               }
+                               return (day >= 1 && day <= daysInMonth);
+                       }
+ 
        // Convert a particular time into a DateTime value.
        public override DateTime ToDateTime(int year, int month, int day,
***************
*** 366,371 ****
                                long result;
                                bool isLeap;
!                               if(year >= 1 && year <= 9999 &&
!                                  month >= 1 && month <= 12)
                                {
                                        isLeap = ((year % 4) == 0);
--- 436,440 ----
                                long result;
                                bool isLeap;
!                               if(CheckDateRange(year, month, day))
                                {
                                        isLeap = ((year % 4) == 0);
***************
*** 379,383 ****
                                                unchecked
                                                {
!                                                       result = 
YearToTicks(year);
                                                        result +=
                                                                
(long)(DateTime.daysBeforeMonth[month - 1]);
--- 448,452 ----
                                                unchecked
                                                {
!                                                       result = 
YearToDays(year);
                                                        result +=
                                                                
(long)(DateTime.daysBeforeMonth[month - 1]);
***************
*** 386,389 ****
--- 455,459 ----
                                                                ++result;
                                                        }
+                                                       result -= EpochAdjust;
                                                        return new DateTime
                                                                  ((result + 
(long)(day - 1)) *

Index: Calendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/Calendar.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Calendar.cs 1 Jun 2003 11:07:36 -0000       1.5
--- Calendar.cs 13 Nov 2003 03:06:51 -0000      1.6
***************
*** 3,7 ****
   *        "System.Globalization.Calendar" class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 3,7 ----
   *        "System.Globalization.Calendar" class.
   *
!  * Copyright (C) 2001, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 55,58 ****
--- 55,90 ----
                                }
                        }
+ 
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public virtual DateTime MinValue
+                       {
+                               get
+                               {
+                                       return DateTime.MinValue;
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public virtual DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+       // Helper method for getting the maximum DateTime value for subclasses.
+       internal DateTime GetMaxValue(int maxYear)
+                       {
+                               DateTime value;
+                               int month = GetMonthsInYear(maxYear, 
CurrentEra);
+                               int day = GetDaysInMonth(maxYear, month, 
CurrentEra);
+                               value = ToDateTime(maxYear, month, day, 0, 0, 
0, 0, CurrentEra);
+                               return new DateTime(value.Ticks + 
TimeSpan.TicksPerDay - 1);
+                       }
+ 
+ #endif
  
        // Internal version of the default "Add*" methods.

Index: HebrewCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/HebrewCalendar.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** HebrewCalendar.cs   17 Sep 2003 06:45:34 -0000      1.6
--- HebrewCalendar.cs   13 Nov 2003 03:06:51 -0000      1.7
***************
*** 3,7 ****
   *        "System.Globalization.HebrewCalendar" class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 3,7 ----
   *        "System.Globalization.HebrewCalendar" class.
   *
!  * Copyright (C) 2001, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 35,39 ****
        private const int MinYear = 5343;
        private const int MaxYear = 6000;
!       private const int Year1AD = 3760;
  
        // There are 1080 "parts" per hour.
--- 35,43 ----
        private const int MinYear = 5343;
        private const int MaxYear = 6000;
! 
!       // Gregorian 0001/01/01 is Hebrew 3761/10/18.  This constant
!       // indicates the number of days to use to offset a Gregorian
!       // day number to turn it into a Hebrew day number.
!       private const long Year1ADDays = 1373428;
  
        // There are 1080 "parts" per hour.
***************
*** 104,107 ****
--- 108,133 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return ToDateTime(MinYear, 1, 1, 0, 
HebrewEra);
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return GetMaxValue(MaxYear);
+                               }
+                       }
+ 
+ #endif
+ 
        // Determine if a year value is a Hebrew leap year.
        private static bool IsHebrewLeapYear(int year)
***************
*** 119,122 ****
--- 145,149 ----
  
        // Get the absolute day number that starts a particular year.
+       // Based on the algorithm used by 
"http://www.funaba.org/en/calendar.html";.
        private static long StartOfYear(int year)
                        {
***************
*** 273,277 ****
                                // Get the day of the year.
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - 
StartOfYear(Year1AD);
                                int day = (int)((time.Ticks / 
TimeSpan.TicksPerDay) - yearDays);
  
--- 300,304 ----
                                // Get the day of the year.
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - Year1ADDays;
                                int day = (int)((time.Ticks / 
TimeSpan.TicksPerDay) - yearDays);
  
***************
*** 296,300 ****
                        {
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - 
StartOfYear(Year1AD);
                                return (int)(((time.Ticks /
                                                                
TimeSpan.TicksPerDay) - yearDays) + 1);
--- 323,327 ----
                        {
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - Year1ADDays;
                                return (int)(((time.Ticks /
                                                                
TimeSpan.TicksPerDay) - yearDays) + 1);
***************
*** 304,308 ****
                                // Get the day of the year.
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - 
StartOfYear(Year1AD);
                                int day = (int)((time.Ticks / 
TimeSpan.TicksPerDay) - yearDays);
  
--- 331,335 ----
                                // Get the day of the year.
                                int year = GetYear(time);
!                               long yearDays = StartOfYear(year) - Year1ADDays;
                                int day = (int)((time.Ticks / 
TimeSpan.TicksPerDay) - yearDays);
  
***************
*** 323,327 ****
                                // Get the absolute day number for "time".
                                long day = time.Ticks / TimeSpan.TicksPerDay;
!                               day += StartOfYear(Year1AD);
  
                                // Perform a range check on MinYear and MaxYear.
--- 350,354 ----
                                // Get the absolute day number for "time".
                                long day = time.Ticks / TimeSpan.TicksPerDay;
!                               day += Year1ADDays;
  
                                // Perform a range check on MinYear and MaxYear.
***************
*** 525,529 ****
                                // We do this by calculating the number of days 
since
                                // 1 January 0001 AD, which is Hebrew 
01/01/3760.
!                               long days = StartOfYear(year) - 
StartOfYear(Year1AD) + day - 1;
                                int[] table = GetMonthTable(year);
                                int posn;
--- 552,556 ----
                                // We do this by calculating the number of days 
since
                                // 1 January 0001 AD, which is Hebrew 
01/01/3760.
!                               long days = StartOfYear(year) - Year1ADDays + 
day - 1;
                                int[] table = GetMonthTable(year);
                                int posn;

Index: ThaiBuddhistCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/ThaiBuddhistCalendar.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** ThaiBuddhistCalendar.cs     23 Apr 2003 05:39:49 -0000      1.2
--- ThaiBuddhistCalendar.cs     13 Nov 2003 03:06:51 -0000      1.3
***************
*** 73,76 ****
--- 73,98 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return DateTime.MinValue;
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
+ 
        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)

Index: KoreanCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/KoreanCalendar.cs,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** KoreanCalendar.cs   23 Apr 2003 05:39:49 -0000      1.2
--- KoreanCalendar.cs   13 Nov 2003 03:06:51 -0000      1.3
***************
*** 73,76 ****
--- 73,98 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return DateTime.MinValue;
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
+ 
        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)

Index: GregorianCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/GregorianCalendar.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** GregorianCalendar.cs        23 Apr 2003 05:39:49 -0000      1.4
--- GregorianCalendar.cs        13 Nov 2003 03:06:51 -0000      1.5
***************
*** 3,7 ****
   *        "System.Globalization.GregorianCalendar" class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 3,7 ----
   *        "System.Globalization.GregorianCalendar" class.
   *
!  * Copyright (C) 2001, 2003  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
***************
*** 97,100 ****
--- 97,122 ----
                                }
                        }
+ 
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return DateTime.MinValue;
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return DateTime.MaxValue;
+                               }
+                       }
+ 
+ #endif
  
        // Add a time period to a DateTime value.

--- NEW FILE: JalaaliCalendar.cs ---
/*
 * JalaaliCalendar.cs - Implementation of the
 *        "System.Globalization.JalaaliCalendar" class.
 *
 * Copyright (C) 2003  Southern Storm Software, Pty Ltd.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

namespace System.Globalization
{

#if !ECMA_COMPAT && CONFIG_FRAMEWORK_1_2

// This Jalaali calendar implementation is based on the algorithm used by
// "http://www.funaba.org/en/calendar.html";.

public class JalaaliCalendar : Calendar
{
        // The Jalaali era.
        public const int JalaaliEra = 1;

        // Useful constants.
        private const int DefaultTwoDigitMax = 1408;    // guessed value - TODO
        private const int MinYear = 1;                          // Minimum 
Jalaali year.
        private const int MaxYear = 9377;                       // Maximum 
Jalaali year.
        private const long JalaaliYearOne = 226894;     // Day number of 
1/1/0001 J.
        private static readonly DateTime MinDate =
                        new DateTime(622, 3, 21);                       // 
Gregorian for 1/1/0001 J.

        // Number of days in each month of the year.  The last month will
        // have 30 days in a leap year.
        private static readonly int[] daysInMonth =
                        {31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29};

        // Number of days before each month.
        private static readonly int[] daysBeforeMonth =
                        {0,
                         31,
                         31 + 31,
                         31 + 31 + 31,
                         31 + 31 + 31 + 31,
                         31 + 31 + 31 + 31 + 31,
                         31 + 31 + 31 + 31 + 31 + 31,
                         31 + 31 + 31 + 31 + 31 + 31 + 30,
                         31 + 31 + 31 + 31 + 31 + 31 + 30 + 30,
                         31 + 31 + 31 + 31 + 31 + 31 + 30 + 30 + 30,
                         31 + 31 + 31 + 31 + 31 + 31 + 30 + 30 + 30 + 30,
                         31 + 31 + 31 + 31 + 31 + 31 + 30 + 30 + 30 + 30 + 30};

        // Constructors.
        public JalaaliCalendar() {}

        // Get a list of eras for the calendar.
        public override int[] Eras
                        {
                                get
                                {
                                        int[] eras = new int [1];
                                        eras[0] = JalaaliEra;
                                        return eras;
                                }
                        }

        // Set the last year of a 100-year range for 2-digit processing.
        public override int TwoDigitYearMax
                        {
                                get
                                {
                                        int value = base.TwoDigitYearMax;
                                        if(value != -1)
                                        {
                                                return value;
                                        }
                                        else
                                        {
                                                // Set the default value.
                                                base.TwoDigitYearMax = 
DefaultTwoDigitMax;
                                                return DefaultTwoDigitMax;
                                        }
                                }
                                set
                                {
                                        if(value < 100 || value > 9999)
                                        {
                                                throw new 
ArgumentOutOfRangeException
                                                        ("year", 
_("ArgRange_Year"));
                                        }
                                        base.TwoDigitYearMax = value;
                                }
                        }

        // Get the minimum DateTime value supported by this calendar.
        public override DateTime MinValue
                        {
                                get
                                {
                                        return MinDate;
                                }
                        }

        // Get the maximum DateTime value supported by this calendar.
        public override DateTime MaxValue
                        {
                                get
                                {
                                        return GetMaxValue(MaxYear);
                                }
                        }

        // Convert a Jalaali year value into an offset in days since 1/1/0001 
AD.
        private static long YearToDays(int year)
                        {
                                return 365 * (year - 1) +
                                       ((21 + (8 * year)) / 33) +
                                           JalaaliYearOne;
                        }

        // Pull apart a DateTime value into year, month, and day.
        private static void PullDateApart(DateTime time, out int year,
                                                                          out 
int month, out int day)
                        {
                                // Validate the time range.
                                if(time < MinDate)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("time", 
_("Arg_DateTimeRange"));
                                }

                                // Get the absolute day number for the date.
                                long absolute = (time.Ticks / 
TimeSpan.TicksPerDay) + 1;

                                // Extract the year value.
                                int approx = (int)((absolute - JalaaliYearOne) 
/ 366);
                                int temp, y;
                                temp = 0;
                                y = approx;
                                while(absolute >= (YearToDays(y + 1) + 1))
                                {
                                        ++temp;
                                        ++y;
                                }
                                year = y;

                                // Extract the year component from the absolute 
date.
                                absolute -= YearToDays(year);

                                // Determine the month and day values.
                                month = 1;
                                while(month < 12 && absolute > 
daysInMonth[month - 1])
                                {
                                        absolute -= daysInMonth[month - 1];
                                        ++month;
                                }
                                day = (int)absolute;
                        }

        // Recombine a DateTime value from its components.
        private DateTime RecombineDate(int year, int month, int day, long ticks)
                        {
                                int limit = GetDaysInMonth(year, month, 
JalaaliEra);
                                if(day < 1 || day > limit)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("day", _("ArgRange_Year"));
                                }
                                long days;
                                days = YearToDays(year) + daysBeforeMonth[month 
- 1] + day - 1;
                                if(days < 0)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("time", 
_("Arg_DateTimeRange"));
                                }
                                return new DateTime(days * TimeSpan.TicksPerDay 
+ ticks);
                        }

        // Add a time period to a DateTime value.
        public override DateTime AddMonths(DateTime time, int months)
                        {
                                int year, month, day;
                                PullDateApart(time, out year, out month, out 
day);
                                if(months > 0)
                                {
                                        year += months / 12;
                                        month += months % 12;
                                        if(month > 12)
                                        {
                                                ++year;
                                                month -= 12;
                                        }
                                }
                                else if(months < 0)
                                {
                                        months = -months;
                                        year -= months / 12;
                                        month -= months % 12;
                                        if(month < 1)
                                        {
                                                --year;
                                                month += 12;
                                        }
                                }
                                int limit = GetDaysInMonth(year, month, 
JalaaliEra);
                                if(day > limit)
                                {
                                        day = limit;
                                }
                                return RecombineDate(year, month, day,
                                                                         
time.Ticks % TimeSpan.TicksPerDay);
                        }
        public override DateTime AddYears(DateTime time, int years)
                        {
                                return AddMonths(time, years * 12);
                        }

        // Extract the components from a DateTime value.
        public override int GetDayOfMonth(DateTime time)
                        {
                                int year, month, day;
                                PullDateApart(time, out year, out month, out 
day);
                                return day;
                        }
        public override System.DayOfWeek GetDayOfWeek(DateTime time)
                        {
                                return time.DayOfWeek;
                        }
        public override int GetDayOfYear(DateTime time)
                        {
                                int year, month, day;
                                PullDateApart(time, out year, out month, out 
day);
                                return daysBeforeMonth[month - 1] + day;
                        }
        public override int GetMonth(DateTime time)
                        {
                                int year, month, day;
                                PullDateApart(time, out year, out month, out 
day);
                                return month;
                        }
        public override int GetYear(DateTime time)
                        {
                                int year, month, day;
                                PullDateApart(time, out year, out month, out 
day);
                                return year;
                        }

        // Get the number of days in a particular month.
        public override int GetDaysInMonth(int year, int month, int era)
                        {
                                if(era != CurrentEra && era != JalaaliEra)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidEra"));
                                }
                                if(year < 1 || year > MaxYear)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("year", _("ArgRange_Year"));
                                }
                                if(month < 1 || month > 12)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("month", _("ArgRange_Month"));
                                }
                                if(month < 12)
                                {
                                        return daysInMonth[month - 1];
                                }
                                else if(IsLeapYear(year, era))
                                {
                                        return 30;
                                }
                                else
                                {
                                        return 29;
                                }
                        }

        // Get the number of days in a particular year.
        public override int GetDaysInYear(int year, int era)
                        {
                                if(year < MinYear || year > MaxYear)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("year", _("ArgRange_Year"));
                                }
                                if(era != CurrentEra && era != JalaaliEra)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidEra"));
                                }
                                if(IsLeapYear(year))
                                {
                                        return 366;
                                }
                                else
                                {
                                        return 365;
                                }
                        }

        // Get the era for a specific DateTime value.
        public override int GetEra(DateTime time)
                        {
                                return JalaaliEra;
                        }

        // Get the number of months in a specific year.
        public override int GetMonthsInYear(int year, int era)
                        {
                                if(year < MinYear || year > MaxYear)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("year", _("ArgRange_Year"));
                                }
                                if(era != CurrentEra && era != JalaaliEra)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidEra"));
                                }
                                return 12;
                        }

        // Determine if a particular day is a leap day.
        public override bool IsLeapDay(int year, int month, int day, int era)
                        {
                                if(day < 1 || day > GetDaysInMonth(year, month, 
era))
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("day", _("ArgRange_Day"));
                                }
                                if(DateTime.IsLeapYear(year) && month == 12 && 
day == 30)
                                {
                                        return true;
                                }
                                else
                                {
                                        return false;
                                }
                        }

        // Determine if a particular month is a leap month.
        public override bool IsLeapMonth(int year, int month, int era)
                        {
                                if(month < 1 || month > 12)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("month", _("ArgRange_Month"));
                                }
                                return (IsLeapYear(year, era) && month == 12);
                        }

        // Determine if a particular year is a leap year.
        public override bool IsLeapYear(int year, int era)
                        {
                                if(year < MinYear || year > MaxYear)
                                {
                                        throw new ArgumentOutOfRangeException
                                                ("year", _("ArgRange_Year"));
                                }
                                if(era != CurrentEra && era != JalaaliEra)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidEra"));
                                }
                            return (((29 + (8 * year)) % 33) < 8);
                        }

        // Convert a particular time into a DateTime value.
        public override DateTime ToDateTime(int year, int month, int day,
                                                                                
int hour, int minute, int second,
                                                                                
int millisecond, int era)
                        {
                                if(era != CurrentEra && era != JalaaliEra)
                                {
                                        throw new 
ArgumentException(_("Arg_InvalidEra"));
                                }
                                return RecombineDate(year, month, day,
                                                                     (new 
TimeSpan(hour, minute, second,
                                                                                
                   millisecond)).Ticks);
                        }

        // Convert a two-digit year value into a four-digit year value.
        public override int ToFourDigitYear(int year)
                        {
                                return base.ToFourDigitYear(year);
                        }

}; // class JalaaliCalendar

#endif // !ECMA_COMPAT && CONFIG_FRAMEWORK_1_2

}; // namespace System.Globalization

Index: HijriCalendar.cs
===================================================================
RCS file: 
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Globalization/HijriCalendar.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** HijriCalendar.cs    22 Aug 2003 06:21:52 -0000      1.3
--- HijriCalendar.cs    13 Nov 2003 03:06:51 -0000      1.4
***************
*** 166,169 ****
--- 166,191 ----
                        }
  
+ #if CONFIG_FRAMEWORK_1_2
+ 
+       // Get the minimum DateTime value supported by this calendar.
+       public override DateTime MinValue
+                       {
+                               get
+                               {
+                                       return new DateTime(MinTicks);
+                               }
+                       }
+ 
+       // Get the maximum DateTime value supported by this calendar.
+       public override DateTime MaxValue
+                       {
+                               get
+                               {
+                                       return GetMaxValue(MaxYear);
+                               }
+                       }
+ 
+ #endif
+ 
        // Convert a year value into an absolute number of days.
        private long YearToDays(int year)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]