| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- // ::MONO
- //
- // System.Globalization.JulianCalendar.cs
- //
- // Copyright (C) Wictor Wilén 2001 ([email protected])
- //
- // Contributors:
- //
- // Revisions
- // 2001-09-14: First draft
- // 2001-09-15: First release
- //
- //
- // TODO: testing
- //
- //
- using System;
- namespace System.Globalization
- {
-
- /// <summary>
- /// Summary description for JulianCalendar.
- /// </summary>
- public class JulianCalendar : System.Globalization.Calendar
- {
-
-
- // Public Static (Shared) Fields
- // DONE!
- public static int JulianEra
- {
- get
- {
- return 1;
- }
- }
- // Public Instance Constructors
- // DONE!
- public JulianCalendar()
- {
- }
- // Public Instance Properties
- // DONE!
- public override int[] Eras
- {
- get
- {
- return new int[] {1};
- }
- }
- // DONE!
- public override int TwoDigitYearMax
- {
- get
- {
- return _TwoDigitYearMax;
- }
- set
- {
- _TwoDigitYearMax = value;
- }
- }
- // Public Instance Methods
- // DONE!
- public override DateTime AddMonths ( DateTime time, int months )
- {
- if(months < -120000 || months > 120000)
- throw new System.ArgumentOutOfRangeException();
- DateTime dt = new DateTime(time.Ticks);
- dt = dt.AddMonths(months);
- return dt;
-
- }
- // DONE!
- public override DateTime AddYears ( DateTime time, int years )
- {
- DateTime dt = new DateTime(time.Ticks);
- return dt.AddYears(years);
- }
- // DONE!
- public override int GetDayOfMonth ( DateTime time )
- {
- return time.Day;
- }
- // DONE!
- public override DayOfWeek GetDayOfWeek ( DateTime time )
- {
- return time.DayOfWeek;
- }
- // DONE!
- public override int GetDayOfYear ( DateTime time )
- {
- return time.DayOfYear;
- }
-
- // DONE!
- public override int GetDaysInMonth ( int year, int month, int era )
- {
- if( year < _MinYear || year > _MaxYear ||
- month < _MinMonth || month > _MaxMonth ||
- era != JulianEra)
- throw new System.ArgumentOutOfRangeException();
- if(this.IsLeapYear(year))
- return _DaysInMonthLeap[month];
- else
- return _DaysInMonth[month];
- }
-
- // DONE!
- public override int GetDaysInYear ( int year, int era )
- {
- if(year < _MinYear || year > _MaxYear || era != JulianEra)
- throw new System.ArgumentOutOfRangeException();
- return this.GetDaysInYear(year);
- }
- // DONE!
- public override int GetEra ( DateTime time )
- {
- return JulianEra;
- }
- // DONE!
- public override int GetMonth ( DateTime time )
- {
- return time.Month;
- }
- // DONE!
- public override int GetMonthsInYear ( int year, int era )
- {
- if(year < _MinYear || year > _MaxYear || era != JulianEra)
- throw new System.ArgumentOutOfRangeException();
- return _MaxMonth;
- }
-
- // DONE!
- public override int GetYear ( DateTime time )
- {
- return time.Year;
- }
- // DONE!
- public override bool IsLeapDay ( int year, int month, int day, int era )
- {
- int dim;
- if(day < _MinDay || month < _MinMonth || month > _MaxMonth)
- throw new System.ArgumentOutOfRangeException();
- if(this.IsLeapYear(year,era))
- dim = _DaysInMonthLeap[month-1];
- else
- dim = _DaysInMonth[month-1];
- if( day > dim)
- throw new System.ArgumentOutOfRangeException();
- if( month == 2 && day == 29)
- return true;
-
- return false;
- }
- // DONE!
- public override bool IsLeapMonth ( int year, int month )
- {
- if( year < _MinYear || year > _MaxYear || month < _MinMonth || month > _MaxMonth)
- throw new System.ArgumentException();
- return false;
- }
- // DONE!
- public override bool IsLeapMonth ( int year, int month, int era )
- {
- if( year < _MinYear || year > _MaxYear || month < _MinMonth || month > _MaxMonth || era != JulianEra)
- throw new System.ArgumentException();
- return false;
- }
-
- // DONE!
- public override bool IsLeapYear ( int year, int era )
- {
- if(year < _MinYear || year > _MaxYear || era != JulianEra)
- throw new System.ArgumentOutOfRangeException();
- if(year % 4 == 0)
- return true;
- return false;
- }
-
- // DONE!
- public override DateTime ToDateTime ( int year, int month, int day, int hour, int minute, int second, int millisecond, int era )
- {
- // INFO: year, era and month is checked by GetDaysInMonth()
- int dim;
- dim = GetDaysInMonth(year,month);
- if( day < _MinDay || day > dim ||
- hour < _MinHour || hour > _MaxHour ||
- minute < _MinMinute || minute > _MaxMinute ||
- second < _MinSecond || second > _MaxSecond ||
- millisecond < _MinMillisecond || millisecond > _MaxMillisecond)
- throw new System.ArgumentOutOfRangeException();
- return new DateTime(year,month,day,hour,minute,second,millisecond,this);
- }
-
- // DONE!
- public override int ToFourDigitYear ( int year )
- {
- int y = _TwoDigitYearMax % 100;
- if( year > y )
- y = _TwoDigitYearMax - y - 100 + year;
- else
- y = _TwoDigitYearMax - y + year;
- if( y < _MinYear || y > _MaxYear)
- throw new System.ArgumentException();
- return y;
- }
- }
- }
|