**** Merged from MCS ****
[mono-project.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsTypes / TdsDateTime.cs
blob27552b8171321b991b41ac048b048678026497c0
1 //
2 // Mono.Data.TdsTypes.TdsDateTime
3 //
4 // Author:
5 // Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using Mono.Data.TdsClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
36 namespace Mono.Data.TdsTypes {
37 public struct TdsDateTime : INullable, IComparable
39 #region Fields
40 private DateTime value;
41 private bool notNull;
43 public static readonly TdsDateTime MaxValue = new TdsDateTime (9999,12,31);
44 public static readonly TdsDateTime MinValue = new TdsDateTime (1753,1,1);
45 public static readonly TdsDateTime Null;
46 public static readonly int SQLTicksPerHour;
47 public static readonly int SQLTicksPerMinute;
48 public static readonly int SQLTicksPerSecond;
50 #endregion
52 #region Constructors
54 public TdsDateTime (DateTime value)
56 this.value = value;
57 notNull = true;
60 [MonoTODO]
61 public TdsDateTime (int dayTicks, int timeTicks)
63 throw new NotImplementedException ();
66 public TdsDateTime (int year, int month, int day)
68 this.value = new DateTime (year, month, day);
69 notNull = true;
72 public TdsDateTime (int year, int month, int day, int hour, int minute, int second)
74 this.value = new DateTime (year, month, day, hour, minute, second);
75 notNull = true;
78 [MonoTODO]
79 public TdsDateTime (int year, int month, int day, int hour, int minute, int second, double millisecond)
81 throw new NotImplementedException ();
84 [MonoTODO]
85 public TdsDateTime (int year, int month, int day, int hour, int minute, int second, int bilisecond)
87 throw new NotImplementedException ();
90 #endregion
92 #region Properties
94 [MonoTODO]
95 public int DayTicks {
96 get { throw new NotImplementedException (); }
99 public bool IsNull {
100 get { return !notNull; }
103 [MonoTODO]
104 public int TimeTicks {
105 get { throw new NotImplementedException (); }
108 public DateTime Value {
109 get {
110 if (this.IsNull)
111 throw new TdsNullValueException ("The property contains Null.");
112 else
113 return value;
117 #endregion
119 #region Methods
121 public int CompareTo (object value)
123 if (value == null)
124 return 1;
125 else if (!(value is TdsDateTime))
126 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.TdsTypes.TdsDateTime"));
127 else if (((TdsDateTime)value).IsNull)
128 return 1;
129 else
130 return this.value.CompareTo (((TdsDateTime)value).Value);
133 public override bool Equals (object value)
135 if (!(value is TdsDateTime))
136 return false;
137 else
138 return (bool) (this == (TdsDateTime)value);
141 public static TdsBoolean Equals (TdsDateTime x, TdsDateTime y)
143 return (x == y);
146 [MonoTODO]
147 public override int GetHashCode ()
149 return 42;
152 public static TdsBoolean GreaterThan (TdsDateTime x, TdsDateTime y)
154 return (x > y);
157 public static TdsBoolean GreaterThanOrEqual (TdsDateTime x, TdsDateTime y)
159 return (x >= y);
162 public static TdsBoolean LessThan (TdsDateTime x, TdsDateTime y)
164 return (x < y);
167 public static TdsBoolean LessThanOrEqual (TdsDateTime x, TdsDateTime y)
169 return (x <= y);
172 public static TdsBoolean NotEquals (TdsDateTime x, TdsDateTime y)
174 return (x != y);
177 [MonoTODO]
178 public static TdsDateTime Parse (string s)
180 throw new NotImplementedException ();
183 public TdsString ToTdsString ()
185 return ((TdsString)this);
188 public override string ToString ()
190 if (this.IsNull)
191 return String.Empty;
192 else
193 return value.ToString ();
196 [MonoTODO]
197 public static TdsDateTime operator + (TdsDateTime x, TimeSpan t)
199 throw new NotImplementedException ();
202 public static TdsBoolean operator == (TdsDateTime x, TdsDateTime y)
204 if (x.IsNull || y.IsNull)
205 return TdsBoolean.Null;
206 else
207 return new TdsBoolean (x.Value == y.Value);
210 public static TdsBoolean operator > (TdsDateTime x, TdsDateTime y)
212 if (x.IsNull || y.IsNull)
213 return TdsBoolean.Null;
214 else
215 return new TdsBoolean (x.Value > y.Value);
218 public static TdsBoolean operator >= (TdsDateTime x, TdsDateTime y)
220 if (x.IsNull || y.IsNull)
221 return TdsBoolean.Null;
222 else
223 return new TdsBoolean (x.Value >= y.Value);
226 public static TdsBoolean operator != (TdsDateTime x, TdsDateTime y)
228 if (x.IsNull || y.IsNull)
229 return TdsBoolean.Null;
230 else
231 return new TdsBoolean (!(x.Value == y.Value));
234 public static TdsBoolean operator < (TdsDateTime x, TdsDateTime y)
236 if (x.IsNull || y.IsNull)
237 return TdsBoolean.Null;
238 else
239 return new TdsBoolean (x.Value < y.Value);
242 public static TdsBoolean operator <= (TdsDateTime x, TdsDateTime y)
244 if (x.IsNull || y.IsNull)
245 return TdsBoolean.Null;
246 else
247 return new TdsBoolean (x.Value <= y.Value);
250 [MonoTODO]
251 public static TdsDateTime operator - (TdsDateTime x, TimeSpan t)
253 throw new NotImplementedException ();
256 public static explicit operator DateTime (TdsDateTime x)
258 return x.Value;
261 [MonoTODO]
262 public static explicit operator TdsDateTime (TdsString x)
264 throw new NotImplementedException();
267 public static implicit operator TdsDateTime (DateTime x)
269 return new TdsDateTime (x);
272 #endregion