-//\r
-// System.DateTime.cs\r
-//\r
-// author:\r
-// Marcel Narings (marcel@narings.nl)\r
-//\r
-// (C) 2001 Marcel Narings\r
-\r
-using System;\r
-using System.Globalization;\r
-using System.Runtime.CompilerServices;\r
-\r
-\r
-namespace System\r
-{\r
- /// <summary>\r
- /// The DateTime structure represents dates and time ranging from\r
- /// 1-1-0001 12:00:00 AM to 31-12-9999 23:59:00 Common Era.\r
- /// </summary>\r
- /// \r
- public struct DateTime : IComparable , IFormattable , IConvertible\r
- {\r
- long ticks;\r
-\r
- private const long MaxTicks = 3155378975999999999L;\r
- private const long MinTicks = 0L;\r
- private const int dp400 = 146097;\r
- private const int dp100 = 36524;\r
- private const int dp4 = 1461;\r
- \r
- public static readonly DateTime MaxValue = new DateTime (MaxTicks);\r
- public static readonly DateTime MinValue = new DateTime (MinTicks);\r
- \r
- private enum Which \r
- {\r
- Day,\r
- DayYear,\r
- Month,\r
- Year\r
- };\r
- \r
- private static int[] daysmonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; \r
- private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; \r
-\r
- private static long AbsoluteDays (int year, int month, int day)\r
- {\r
- int[] days;\r
- int temp = 0, m=1 ;\r
- \r
- days = (IsLeapYear(year) ? daysmonthleap : daysmonth);\r
- \r
- while (m < month)\r
- temp += days[m++];\r
- return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));\r
- }\r
-\r
- private int FromTicks(Which what)\r
- {\r
- int num400, num100, num4, numyears; \r
- int M =1;\r
-\r
- int[] days = daysmonth;\r
- int totaldays = (int) (ticks / TimeSpan.TicksPerDay);\r
- \r
- num400 = (totaldays / dp400);\r
- totaldays -= num400 * dp400;\r
- \r
- num100 = (totaldays / dp100);\r
- if (num100 == 4) // leap\r
- num100 = 3;\r
- totaldays -= (num100 * dp100);\r
-\r
- num4 = totaldays / dp4;\r
- totaldays -= (num4 * dp4);\r
-\r
- numyears = totaldays / 365 ;\r
- \r
- if (numyears == 4) //leap\r
- numyears =3 ;\r
- if (what == Which.Year )\r
- return num400*400 + num100*100 + num4*4 + numyears + 1;\r
-\r
- totaldays -= (numyears * 365) ;\r
- if (what == Which.DayYear )\r
- return totaldays + 1;\r
- \r
- if ((numyears==3) && ((num100 == 3) || !(num4 == 24)) ) //31 dec leapyear\r
- days = daysmonthleap;\r
- \r
- while (totaldays >= days[M])\r
- totaldays -= days[M++];\r
-\r
- if (what == Which.Month )\r
- return M;\r
-\r
- return totaldays +1; \r
-\r
-\r
- }\r
-\r
-\r
- // Constructors\r
- \r
- /// <summary>\r
- /// Constructs a DateTime for specified ticks\r
- /// </summary>\r
- /// \r
- public DateTime (long newticks) \r
- {\r
- ticks = newticks;\r
- \r
- if ( newticks < MinValue.ticks || newticks > MaxValue.ticks)\r
- throw new ArgumentOutOfRangeException ();\r
- }\r
-\r
- public DateTime (int year, int month, int day)\r
- : this (year, month, day,0,0,0,0) {}\r
-\r
- public DateTime (int year, int month, int day, int hour, int minute, int second)\r
- : this (year, month, day, hour, minute, second, 0) {}\r
-\r
- public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond)\r
- {\r
- if ( year < 1 || year > 9999 || \r
- month < 1 || month >12 ||\r
- day < 1 || day > DaysInMonth(year, month) ||\r
- hour < 0 || hour > 23 ||\r
- minute < 0 || minute > 59 ||\r
- second < 0 || second > 59 )\r
- throw new ArgumentOutOfRangeException() ;\r
- \r
- ticks = AbsoluteDays(year,month,day) * TimeSpan.TicksPerDay + \r
- hour * TimeSpan.TicksPerHour + \r
- minute * TimeSpan.TicksPerMinute + \r
- second * TimeSpan.TicksPerSecond + \r
- millisecond * TimeSpan.TicksPerMillisecond ; \r
- \r
- if (ticks < MinValue.ticks || ticks > MaxValue.ticks )\r
- throw new ArgumentException() ;\r
- }\r
-\r
- public DateTime (int year, int month, int day, Calendar calendar)\r
- : this (year, month, day, 0, 0, 0, 0, calendar) {}\r
-\r
- \r
- public DateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar)\r
- : this (year, month, day, hour, minute, second, 0, calendar) {}\r
-\r
-\r
- public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)\r
- : this(year, month, day, hour, minute, second, millisecond) \r
- {\r
- if ( calendar == null)\r
- throw new ArgumentNullException();\r
- }\r
-\r
-\r
- /* Properties */\r
- \r
- public DateTime Date \r
- {\r
- get \r
- { \r
- return new DateTime(ticks - (ticks % TimeSpan.TicksPerDay )) ; \r
- }\r
- }\r
- \r
- public int Day\r
- {\r
- get \r
- { \r
- return FromTicks(Which.Day); \r
- }\r
- }\r
-\r
- public DayOfWeek DayOfWeek \r
- {\r
- get \r
- { \r
- return ( (DayOfWeek) (((ticks / TimeSpan.TicksPerDay)+1) % 7) ); \r
- }\r
- }\r
-\r
- public int DayOfYear \r
- {\r
- get \r
- { \r
- return FromTicks(Which.DayYear); \r
- }\r
- }\r
-\r
- public int Hour \r
- {\r
- get \r
- { \r
- return ( (int) ((ticks % TimeSpan.TicksPerDay) / TimeSpan.TicksPerHour) ); \r
- }\r
- }\r
-\r
- public int Millisecond \r
- {\r
- get \r
- { \r
- return ( (int) (ticks % TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) ); \r
- }\r
- }\r
- \r
- public int Minute \r
- {\r
- get \r
- { \r
- return ( (int) (ticks % TimeSpan.TicksPerHour / TimeSpan.TicksPerMinute) ); \r
- }\r
- }\r
-\r
- public int Month \r
- {\r
- get \r
- { \r
- return FromTicks(Which.Month); \r
- }\r
- }\r
-\r
- \r
- [MethodImplAttribute(MethodImplOptions.InternalCall)]\r
- private static extern long GetNow ();\r
-\r
- public static DateTime Now \r
- {\r
- get \r
- { \r
- return new DateTime (GetNow ()); \r
- }\r
- }\r
-\r
- public int Second \r
- {\r
- get \r
- { \r
- return (int) (ticks % TimeSpan.TicksPerMinute / TimeSpan.TicksPerSecond); \r
- }\r
- }\r
-\r
- public long Ticks\r
- { \r
- get \r
- { \r
- return ticks ; \r
- }\r
- }\r
- \r
- public TimeSpan TimeOfDay \r
- {\r
- get \r
- { \r
- return new TimeSpan(ticks % TimeSpan.TicksPerDay );\r
- }\r
- \r
- }\r
-\r
- //TODO implement\r
- public static DateTime Today \r
- {\r
- get \r
- {\r
- return new DateTime (0);\r
- }\r
- }\r
-\r
- //TODO implement\r
- public static DateTime UtcNow \r
- {\r
- get {\r
- return new DateTime (0);\r
- }\r
- }\r
-\r
- public int Year \r
- {\r
- get \r
- { \r
- return FromTicks(Which.Year); \r
- }\r
- }\r
-\r
- /* methods */\r
-\r
- public DateTime Add (TimeSpan ts)\r
- {\r
- long newticks ;\r
-\r
- newticks = ticks + ts.Ticks ;\r
-\r
- if (ts.Ticks < MinTicks || ts.Ticks > MaxTicks || \r
- newticks < MinTicks || newticks > MaxTicks)\r
- throw new ArgumentException ();\r
- \r
- return new DateTime (newticks);\r
- }\r
-\r
- public DateTime AddDays (double days)\r
- {\r
- return AddMilliseconds (days * 86400000);\r
- }\r
- \r
- public DateTime AddTicks (long t)\r
- {\r
- long newticks = ticks + t; \r
-\r
- if (t<MinTicks || t>MaxTicks || newticks<MinTicks || newticks>MaxTicks)\r
- throw new ArgumentException ();\r
-\r
- return new DateTime(newticks);\r
- }\r
-\r
- public DateTime AddHours (double hours)\r
- {\r
- return AddMilliseconds (hours * 3600000);\r
- }\r
-\r
- public DateTime AddMilliseconds (double ms)\r
- {\r
- long msticks, newticks;\r
- \r
- msticks = (long) (ms += ms > 0 ? 0.5 : -0.5) * TimeSpan.TicksPerMillisecond ; \r
- newticks = ticks + msticks ;\r
-\r
- if (msticks < MinTicks || msticks > MaxTicks ||\r
- newticks < MinTicks || newticks > MaxTicks)\r
- throw new ArgumentException ();\r
-\r
- return new DateTime (newticks);\r
- }\r
-\r
- public DateTime AddMinutes (double minutes)\r
- {\r
- return AddMilliseconds (minutes * 60000);\r
- }\r
- \r
- public DateTime AddMonths (int months)\r
- {\r
- int day, month, year, maxday ;\r
- DateTime temp ;\r
-\r
- day = this.Day;\r
- month = this.Month + (months % 12);\r
- year = this.Year + months/12 ;\r
- \r
- if (month < 1)\r
- {\r
- month = 12 + month ;\r
- year -- ;\r
- }\r
- else if (month>12) \r
- {\r
- month = month -12;\r
- year ++;\r
- }\r
- maxday = DaysInMonth(year, month);\r
- if (day > maxday)\r
- day = maxday;\r
-\r
- temp = new DateTime (year, month, day);\r
- return temp.Add (this.TimeOfDay);\r
- }\r
-\r
- public DateTime AddSeconds (double seconds)\r
- {\r
- return AddMilliseconds (seconds*1000);\r
- }\r
-\r
- public DateTime AddYears (int years )\r
- {\r
- return AddMonths(years * 12);\r
- }\r
-\r
- public static int Compare (DateTime t1, DateTime t2)\r
- {\r
- if (t1.ticks < t2.ticks) \r
- return -1;\r
- else if (t1.ticks > t2.ticks) \r
- return 1;\r
- else\r
- return 0;\r
- }\r
-\r
- public int CompareTo (object v)\r
- {\r
- if ( v == null)\r
- return 1;\r
-\r
- if (!(v is System.DateTime))\r
- throw new ArgumentException (Locale.GetText (\r
- "Value is not a System.DateTime"));\r
-\r
- return Compare (this, (DateTime) v);\r
- }\r
-\r
- public static int DaysInMonth (int year, int month)\r
- {\r
- int[] days ;\r
-\r
- if (month < 1 || month >12)\r
- throw new ArgumentOutOfRangeException ();\r
-\r
- days = (IsLeapYear(year) ? daysmonthleap : daysmonth);\r
- return days[month]; \r
- }\r
- \r
- public override bool Equals (object o)\r
- {\r
- if (!(o is System.DateTime))\r
- return false;\r
-\r
- return ((DateTime) o).ticks == ticks;\r
- }\r
-\r
- public static bool Equals (DateTime t1, DateTime t2 )\r
- {\r
- return (t1.ticks == t2.ticks );\r
- }\r
-\r
- // TODO: Implement me.\r
- public static DateTime FromFileTime (long fileTime) \r
- {\r
- return new DateTime (0);\r
- }\r
-\r
- // TODO: Implement me.\r
- public static DateTime FromOADate (double d)\r
- {\r
- return new DateTime(0);\r
- }\r
- \r
- // TODO: Implement me.\r
- public string[] GetDateTimeFormats() \r
- {\r
- return null;\r
- }\r
-\r
- //TODO: implement me \r
- public string[] GetDateTimeFormats( char format )\r
- {\r
- return null;\r
- }\r
- \r
- // TODO: implement me \r
- public string[] GetDateTimeFormats( IFormatProvider provider)\r
- {\r
- return null;\r
- }\r
-\r
- //TODO: implement me \r
- public string[] GetDateTimeFormats(char format,IFormatProvider provider )\r
- {\r
- return null;\r
- }\r
-\r
- public override int GetHashCode ()\r
- {\r
- return (int) ticks;\r
- }\r
-\r
- public TypeCode GetTypeCode ()\r
- {\r
- return TypeCode.DateTime;\r
- }\r
-\r
- public static bool IsLeapYear (int year)\r
- {\r
- return ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ;\r
- }\r
-\r
- public static DateTime Parse (string s)\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- }\r
-\r
- public static DateTime Parse (string s, IFormatProvider fp)\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- }\r
-\r
- public static DateTime Parse (string s, NumberStyles style, IFormatProvider fp)\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- }\r
-\r
- public static DateTime ParseExact(string s, string format, IFormatProvider provider )\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- }\r
-\r
- public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style )\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- \r
- }\r
-\r
- public static DateTime ParseExact( string s, string[] formats, IFormatProvider provider, DateTimeStyles style )\r
- {\r
- // TODO: Implement me\r
- return new DateTime (0);\r
- \r
- }\r
- \r
- public TimeSpan Subtract(DateTime dt )\r
- { \r
- return new TimeSpan(ticks - dt.ticks );\r
- }\r
-\r
- public DateTime Subtract(TimeSpan ts)\r
- { \r
- return new DateTime(ticks - ts.Ticks );\r
- }\r
-\r
- public long ToFileTime()\r
- {\r
- // TODO: Implement me\r
- return 0 ;\r
- }\r
-\r
- public DateTime ToLocalTime()\r
- {\r
- // TODO Implement me \r
- return new DateTime (0);\r
- }\r
-\r
- public string ToLongDateString()\r
- {\r
- // TODO implement me\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public string ToLongTimeString()\r
- {\r
- // TODO implement me\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public double ToOADate()\r
- {\r
- // TODO implement me \r
- return 0;\r
- }\r
-\r
- public string ToShortDateString()\r
- {\r
- // TODO implement me \r
- throw new NotImplementedException ();\r
- }\r
-\r
- public string ToShortTimeString()\r
- {\r
- // TODO implement me\r
- throw new NotImplementedException ();\r
- }\r
- \r
- public override string ToString ()\r
- {\r
- // TODO: Implement me\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public string ToString (IFormatProvider fp)\r
- {\r
- // TODO: Implement me.\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public string ToString (string format)\r
- {\r
- // TODO: Implement me.\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public string ToString (string format, IFormatProvider fp)\r
- {\r
- // TODO: Implement me.\r
- throw new NotImplementedException ();\r
- }\r
-\r
- public DateTime ToUniversalTime()\r
- {\r
- // TODO: implement me \r
- return new DateTime(0);\r
- }\r
-\r
- /* OPERATORS */\r
-\r
- public static DateTime operator +(DateTime d, TimeSpan t)\r
- {\r
- return new DateTime (d.ticks + t.Ticks);\r
- }\r
-\r
- public static bool operator ==(DateTime d1, DateTime d2)\r
- {\r
- return (d1.ticks == d2.ticks);\r
- }\r
-\r
- public static bool operator >(DateTime t1,DateTime t2)\r
- {\r
- return (t1.ticks > t2.ticks);\r
- }\r
-\r
- public static bool operator >=(DateTime t1,DateTime t2)\r
- {\r
- return (t1.ticks >= t2.ticks);\r
- }\r
-\r
- public static bool operator !=(DateTime d1, DateTime d2)\r
- {\r
- return (d1.ticks != d2.ticks);\r
- }\r
-\r
- public static bool operator <(DateTime t1, DateTime t2)\r
- {\r
- return (t1.ticks < t2.ticks );\r
- }\r
-\r
- public static bool operator <=(DateTime t1,DateTime t2)\r
- {\r
- return (t1.ticks <= t2.ticks);\r
- }\r
-\r
- public static TimeSpan operator -(DateTime d1,DateTime d2)\r
- {\r
- return new TimeSpan(d1.ticks - d2.ticks);\r
- }\r
-\r
- public static DateTime operator -(DateTime d,TimeSpan t )\r
- {\r
- return new DateTime (d.ticks - t.Ticks);\r
- }\r
-\r
- public bool ToBoolean(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
- \r
- public byte ToByte(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public char ToChar(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- // TODO Implement me \r
- public System.DateTime ToDateTime(IFormatProvider provider)\r
- {\r
- return new System.DateTime(this.ticks);\r
- } \r
- \r
- public decimal ToDecimal(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public double ToDouble(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public Int16 ToInt16(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public Int32 ToInt32(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public Int64 ToInt64(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- [CLSCompliant(false)]\r
- public SByte ToSByte(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public Single ToSingle(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- public object ToType(Type conversionType,IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- UInt16 System.IConvertible.ToUInt16(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
- \r
- [CLSCompliant(false)]\r
- public UInt32 ToUInt32(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
-\r
- [CLSCompliant(false)]\r
- public UInt64 ToUInt64(IFormatProvider provider)\r
- {\r
- throw new InvalidCastException();\r
- }\r
- }\r
-}\r
-\r
-namespace System\r
-{\r
- public enum DayOfWeek\r
- {\r
- Sunday,\r
- Monday,\r
- Tuesday,\r
- Wednesday,\r
- Thursday,\r
- Friday,\r
- Saturday\r
- }\r
-}\r
-\r
+//
+// System.DateTime.cs
+//
+// author:
+// Marcel Narings (marcel@narings.nl)
+//
+// (C) 2001 Marcel Narings
+
+using System;
+using System.Globalization;
+using System.Runtime.CompilerServices;
+
+
+namespace System
+{
+ /// <summary>
+ /// The DateTime structure represents dates and time ranging from
+ /// 1-1-0001 12:00:00 AM to 31-12-9999 23:59:00 Common Era.
+ /// </summary>
+ ///
+ public struct DateTime : IComparable , IFormattable , IConvertible
+ {
+ long ticks;
+
+ private const long MaxTicks = 3155378975999999999L;
+ private const long MinTicks = 0L;
+ private const int dp400 = 146097;
+ private const int dp100 = 36524;
+ private const int dp4 = 1461;
+
+ // w32 file time starts counting from 1/1/1601 00:00 GMT
+ // which is the constant ticks from the .NET epoch
+ private const long w32file_epoch = 504911232000000000L;
+
+ public static readonly DateTime MaxValue = new DateTime (MaxTicks);
+ public static readonly DateTime MinValue = new DateTime (MinTicks);
+
+ private enum Which
+ {
+ Day,
+ DayYear,
+ Month,
+ Year
+ };
+
+ private static int[] daysmonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+ private static int[] daysmonthleap = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
+
+ private static long AbsoluteDays (int year, int month, int day)
+ {
+ int[] days;
+ int temp = 0, m=1 ;
+
+ days = (IsLeapYear(year) ? daysmonthleap : daysmonth);
+
+ while (m < month)
+ temp += days[m++];
+ return ((day-1) + temp + (365* (year-1)) + ((year-1)/4) - ((year-1)/100) + ((year-1)/400));
+ }
+
+ private int FromTicks(Which what)
+ {
+ int num400, num100, num4, numyears;
+ int M =1;
+
+ int[] days = daysmonth;
+ int totaldays = (int) (ticks / TimeSpan.TicksPerDay);
+
+ num400 = (totaldays / dp400);
+ totaldays -= num400 * dp400;
+
+ num100 = (totaldays / dp100);
+ if (num100 == 4) // leap
+ num100 = 3;
+ totaldays -= (num100 * dp100);
+
+ num4 = totaldays / dp4;
+ totaldays -= (num4 * dp4);
+
+ numyears = totaldays / 365 ;
+
+ if (numyears == 4) //leap
+ numyears =3 ;
+ if (what == Which.Year )
+ return num400*400 + num100*100 + num4*4 + numyears + 1;
+
+ totaldays -= (numyears * 365) ;
+ if (what == Which.DayYear )
+ return totaldays + 1;
+
+ if ((numyears==3) && ((num100 == 3) || !(num4 == 24)) ) //31 dec leapyear
+ days = daysmonthleap;
+
+ while (totaldays >= days[M])
+ totaldays -= days[M++];
+
+ if (what == Which.Month )
+ return M;
+
+ return totaldays +1;
+
+
+ }
+
+
+ // Constructors
+
+ /// <summary>
+ /// Constructs a DateTime for specified ticks
+ /// </summary>
+ ///
+ public DateTime (long newticks)
+ {
+ ticks = newticks;
+
+ if ( newticks < MinValue.ticks || newticks > MaxValue.ticks)
+ throw new ArgumentOutOfRangeException ();
+ }
+
+ public DateTime (int year, int month, int day)
+ : this (year, month, day,0,0,0,0) {}
+
+ public DateTime (int year, int month, int day, int hour, int minute, int second)
+ : this (year, month, day, hour, minute, second, 0) {}
+
+ public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond)
+ {
+ if ( year < 1 || year > 9999 ||
+ month < 1 || month >12 ||
+ day < 1 || day > DaysInMonth(year, month) ||
+ hour < 0 || hour > 23 ||
+ minute < 0 || minute > 59 ||
+ second < 0 || second > 59 )
+ throw new ArgumentOutOfRangeException() ;
+
+ ticks = AbsoluteDays(year,month,day) * TimeSpan.TicksPerDay +
+ hour * TimeSpan.TicksPerHour +
+ minute * TimeSpan.TicksPerMinute +
+ second * TimeSpan.TicksPerSecond +
+ millisecond * TimeSpan.TicksPerMillisecond ;
+
+ if (ticks < MinValue.ticks || ticks > MaxValue.ticks )
+ throw new ArgumentException() ;
+ }
+
+ public DateTime (int year, int month, int day, Calendar calendar)
+ : this (year, month, day, 0, 0, 0, 0, calendar) {}
+
+
+ public DateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar)
+ : this (year, month, day, hour, minute, second, 0, calendar) {}
+
+
+ public DateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
+ : this(year, month, day, hour, minute, second, millisecond)
+ {
+ if ( calendar == null)
+ throw new ArgumentNullException();
+ }
+
+
+ /* Properties */
+
+ public DateTime Date
+ {
+ get
+ {
+ return new DateTime(ticks - (ticks % TimeSpan.TicksPerDay )) ;
+ }
+ }
+
+ public int Day
+ {
+ get
+ {
+ return FromTicks(Which.Day);
+ }
+ }
+
+ public DayOfWeek DayOfWeek
+ {
+ get
+ {
+ return ( (DayOfWeek) (((ticks / TimeSpan.TicksPerDay)+1) % 7) );
+ }
+ }
+
+ public int DayOfYear
+ {
+ get
+ {
+ return FromTicks(Which.DayYear);
+ }
+ }
+
+ public int Hour
+ {
+ get
+ {
+ return ( (int) ((ticks % TimeSpan.TicksPerDay) / TimeSpan.TicksPerHour) );
+ }
+ }
+
+ public int Millisecond
+ {
+ get
+ {
+ return ( (int) (ticks % TimeSpan.TicksPerSecond / TimeSpan.TicksPerMillisecond) );
+ }
+ }
+
+ public int Minute
+ {
+ get
+ {
+ return ( (int) (ticks % TimeSpan.TicksPerHour / TimeSpan.TicksPerMinute) );
+ }
+ }
+
+ public int Month
+ {
+ get
+ {
+ return FromTicks(Which.Month);
+ }
+ }
+
+
+ [MethodImplAttribute(MethodImplOptions.InternalCall)]
+ private static extern long GetNow ();
+
+ public static DateTime Now
+ {
+ get
+ {
+ return new DateTime (GetNow ());
+ }
+ }
+
+ public int Second
+ {
+ get
+ {
+ return (int) (ticks % TimeSpan.TicksPerMinute / TimeSpan.TicksPerSecond);
+ }
+ }
+
+ public long Ticks
+ {
+ get
+ {
+ return ticks ;
+ }
+ }
+
+ public TimeSpan TimeOfDay
+ {
+ get
+ {
+ return new TimeSpan(ticks % TimeSpan.TicksPerDay );
+ }
+
+ }
+
+ //TODO implement
+ public static DateTime Today
+ {
+ get
+ {
+ return new DateTime (0);
+ }
+ }
+
+ //TODO implement
+ public static DateTime UtcNow
+ {
+ get {
+ return new DateTime (0);
+ }
+ }
+
+ public int Year
+ {
+ get
+ {
+ return FromTicks(Which.Year);
+ }
+ }
+
+ /* methods */
+
+ public DateTime Add (TimeSpan ts)
+ {
+ long newticks ;
+
+ newticks = ticks + ts.Ticks ;
+
+ if (ts.Ticks < MinTicks || ts.Ticks > MaxTicks ||
+ newticks < MinTicks || newticks > MaxTicks)
+ throw new ArgumentException ();
+
+ return new DateTime (newticks);
+ }
+
+ public DateTime AddDays (double days)
+ {
+ return AddMilliseconds (days * 86400000);
+ }
+
+ public DateTime AddTicks (long t)
+ {
+ long newticks = ticks + t;
+
+ if (t<MinTicks || t>MaxTicks || newticks<MinTicks || newticks>MaxTicks)
+ throw new ArgumentException ();
+
+ return new DateTime(newticks);
+ }
+
+ public DateTime AddHours (double hours)
+ {
+ return AddMilliseconds (hours * 3600000);
+ }
+
+ public DateTime AddMilliseconds (double ms)
+ {
+ long msticks, newticks;
+
+ msticks = (long) (ms += ms > 0 ? 0.5 : -0.5) * TimeSpan.TicksPerMillisecond ;
+ newticks = ticks + msticks ;
+
+ if (msticks < MinTicks || msticks > MaxTicks ||
+ newticks < MinTicks || newticks > MaxTicks)
+ throw new ArgumentException ();
+
+ return new DateTime (newticks);
+ }
+
+ public DateTime AddMinutes (double minutes)
+ {
+ return AddMilliseconds (minutes * 60000);
+ }
+
+ public DateTime AddMonths (int months)
+ {
+ int day, month, year, maxday ;
+ DateTime temp ;
+
+ day = this.Day;
+ month = this.Month + (months % 12);
+ year = this.Year + months/12 ;
+
+ if (month < 1)
+ {
+ month = 12 + month ;
+ year -- ;
+ }
+ else if (month>12)
+ {
+ month = month -12;
+ year ++;
+ }
+ maxday = DaysInMonth(year, month);
+ if (day > maxday)
+ day = maxday;
+
+ temp = new DateTime (year, month, day);
+ return temp.Add (this.TimeOfDay);
+ }
+
+ public DateTime AddSeconds (double seconds)
+ {
+ return AddMilliseconds (seconds*1000);
+ }
+
+ public DateTime AddYears (int years )
+ {
+ return AddMonths(years * 12);
+ }
+
+ public static int Compare (DateTime t1, DateTime t2)
+ {
+ if (t1.ticks < t2.ticks)
+ return -1;
+ else if (t1.ticks > t2.ticks)
+ return 1;
+ else
+ return 0;
+ }
+
+ public int CompareTo (object v)
+ {
+ if ( v == null)
+ return 1;
+
+ if (!(v is System.DateTime))
+ throw new ArgumentException (Locale.GetText (
+ "Value is not a System.DateTime"));
+
+ return Compare (this, (DateTime) v);
+ }
+
+ public static int DaysInMonth (int year, int month)
+ {
+ int[] days ;
+
+ if (month < 1 || month >12)
+ throw new ArgumentOutOfRangeException ();
+
+ days = (IsLeapYear(year) ? daysmonthleap : daysmonth);
+ return days[month];
+ }
+
+ public override bool Equals (object o)
+ {
+ if (!(o is System.DateTime))
+ return false;
+
+ return ((DateTime) o).ticks == ticks;
+ }
+
+ public static bool Equals (DateTime t1, DateTime t2 )
+ {
+ return (t1.ticks == t2.ticks );
+ }
+
+ public static DateTime FromFileTime (long fileTime)
+ {
+ return new DateTime (w32file_epoch + fileTime);
+ }
+
+ // TODO: Implement me.
+ public static DateTime FromOADate (double d)
+ {
+ return new DateTime(0);
+ }
+
+ // TODO: Implement me.
+ public string[] GetDateTimeFormats()
+ {
+ return null;
+ }
+
+ //TODO: implement me
+ public string[] GetDateTimeFormats( char format )
+ {
+ return null;
+ }
+
+ // TODO: implement me
+ public string[] GetDateTimeFormats( IFormatProvider provider)
+ {
+ return null;
+ }
+
+ //TODO: implement me
+ public string[] GetDateTimeFormats(char format,IFormatProvider provider )
+ {
+ return null;
+ }
+
+ public override int GetHashCode ()
+ {
+ return (int) ticks;
+ }
+
+ public TypeCode GetTypeCode ()
+ {
+ return TypeCode.DateTime;
+ }
+
+ public static bool IsLeapYear (int year)
+ {
+ return ( (year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ;
+ }
+
+ public static DateTime Parse (string s)
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+ }
+
+ public static DateTime Parse (string s, IFormatProvider fp)
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+ }
+
+ public static DateTime Parse (string s, NumberStyles style, IFormatProvider fp)
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+ }
+
+ public static DateTime ParseExact(string s, string format, IFormatProvider provider )
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+ }
+
+ public static DateTime ParseExact(string s, string format, IFormatProvider provider, DateTimeStyles style )
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+
+ }
+
+ public static DateTime ParseExact( string s, string[] formats, IFormatProvider provider, DateTimeStyles style )
+ {
+ // TODO: Implement me
+ return new DateTime (0);
+
+ }
+
+ public TimeSpan Subtract(DateTime dt )
+ {
+ return new TimeSpan(ticks - dt.ticks );
+ }
+
+ public DateTime Subtract(TimeSpan ts)
+ {
+ return new DateTime(ticks - ts.Ticks );
+ }
+
+ public long ToFileTime()
+ {
+ if(ticks < w32file_epoch) {
+ throw new ArgumentOutOfRangeException("file time is not valid");
+ }
+
+ return(ticks - w32file_epoch);
+ }
+
+ public DateTime ToLocalTime()
+ {
+ // TODO Implement me
+ return new DateTime (0);
+ }
+
+ public string ToLongDateString()
+ {
+ // TODO implement me
+ throw new NotImplementedException ();
+ }
+
+ public string ToLongTimeString()
+ {
+ // TODO implement me
+ throw new NotImplementedException ();
+ }
+
+ public double ToOADate()
+ {
+ // TODO implement me
+ return 0;
+ }
+
+ public string ToShortDateString()
+ {
+ // TODO implement me
+ throw new NotImplementedException ();
+ }
+
+ public string ToShortTimeString()
+ {
+ // TODO implement me
+ throw new NotImplementedException ();
+ }
+
+ public override string ToString ()
+ {
+ // TODO: Implement me
+ throw new NotImplementedException ();
+ }
+
+ public string ToString (IFormatProvider fp)
+ {
+ // TODO: Implement me.
+ throw new NotImplementedException ();
+ }
+
+ public string ToString (string format)
+ {
+ // TODO: Implement me.
+ throw new NotImplementedException ();
+ }
+
+ public string ToString (string format, IFormatProvider fp)
+ {
+ // TODO: Implement me.
+ throw new NotImplementedException ();
+ }
+
+ public DateTime ToUniversalTime()
+ {
+ // TODO: implement me
+ return new DateTime(0);
+ }
+
+ /* OPERATORS */
+
+ public static DateTime operator +(DateTime d, TimeSpan t)
+ {
+ return new DateTime (d.ticks + t.Ticks);
+ }
+
+ public static bool operator ==(DateTime d1, DateTime d2)
+ {
+ return (d1.ticks == d2.ticks);
+ }
+
+ public static bool operator >(DateTime t1,DateTime t2)
+ {
+ return (t1.ticks > t2.ticks);
+ }
+
+ public static bool operator >=(DateTime t1,DateTime t2)
+ {
+ return (t1.ticks >= t2.ticks);
+ }
+
+ public static bool operator !=(DateTime d1, DateTime d2)
+ {
+ return (d1.ticks != d2.ticks);
+ }
+
+ public static bool operator <(DateTime t1, DateTime t2)
+ {
+ return (t1.ticks < t2.ticks );
+ }
+
+ public static bool operator <=(DateTime t1,DateTime t2)
+ {
+ return (t1.ticks <= t2.ticks);
+ }
+
+ public static TimeSpan operator -(DateTime d1,DateTime d2)
+ {
+ return new TimeSpan(d1.ticks - d2.ticks);
+ }
+
+ public static DateTime operator -(DateTime d,TimeSpan t )
+ {
+ return new DateTime (d.ticks - t.Ticks);
+ }
+
+ public bool ToBoolean(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public byte ToByte(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public char ToChar(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ // TODO Implement me
+ public System.DateTime ToDateTime(IFormatProvider provider)
+ {
+ return new System.DateTime(this.ticks);
+ }
+
+ public decimal ToDecimal(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public double ToDouble(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public Int16 ToInt16(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public Int32 ToInt32(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public Int64 ToInt64(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ [CLSCompliant(false)]
+ public SByte ToSByte(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public Single ToSingle(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ public object ToType(Type conversionType,IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ UInt16 System.IConvertible.ToUInt16(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ [CLSCompliant(false)]
+ public UInt32 ToUInt32(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+
+ [CLSCompliant(false)]
+ public UInt64 ToUInt64(IFormatProvider provider)
+ {
+ throw new InvalidCastException();
+ }
+ }
+}
+
+namespace System
+{
+ public enum DayOfWeek
+ {
+ Sunday,
+ Monday,
+ Tuesday,
+ Wednesday,
+ Thursday,
+ Friday,
+ Saturday
+ }
+}
+