Add licensing info
[mono.git] / mcs / class / Mono.Data.TdsClient / Mono.Data.TdsTypes / TdsDateTime.cs
1 //
2 // Mono.Data.TdsTypes.TdsDateTime
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
9
10 //
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.
29 //
30
31 using Mono.Data.TdsClient;
32 using System;
33 using System.Data.SqlTypes;
34 using System.Globalization;
35
36 namespace Mono.Data.TdsTypes {
37         public struct TdsDateTime : INullable, IComparable
38         {
39                 #region Fields
40                 private DateTime value;
41                 private bool notNull;
42
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;
49
50                 #endregion
51
52                 #region Constructors
53
54                 public TdsDateTime (DateTime value) 
55                 {
56                         this.value = value;
57                         notNull = true;
58                 }
59
60                 [MonoTODO]
61                 public TdsDateTime (int dayTicks, int timeTicks) 
62                 {
63                         throw new NotImplementedException ();
64                 }
65
66                 public TdsDateTime (int year, int month, int day) 
67                 {
68                         this.value = new DateTime (year, month, day);
69                         notNull = true;
70                 }
71
72                 public TdsDateTime (int year, int month, int day, int hour, int minute, int second) 
73                 {
74                         this.value = new DateTime (year, month, day, hour, minute, second);
75                         notNull = true;
76                 }
77
78                 [MonoTODO]
79                 public TdsDateTime (int year, int month, int day, int hour, int minute, int second, double millisecond) 
80                 {
81                         throw new NotImplementedException ();
82                 }
83
84                 [MonoTODO]
85                 public TdsDateTime (int year, int month, int day, int hour, int minute, int second, int bilisecond) 
86                 {
87                         throw new NotImplementedException ();
88                 }
89
90                 #endregion
91
92                 #region Properties
93
94                 [MonoTODO]
95                 public int DayTicks {
96                         get { throw new NotImplementedException (); }
97                 }
98
99                 public bool IsNull { 
100                         get { return !notNull; }
101                 }
102
103                 [MonoTODO]
104                 public int TimeTicks {
105                         get { throw new NotImplementedException (); }
106                 }
107
108                 public DateTime Value {
109                         get { 
110                                 if (this.IsNull) 
111                                         throw new TdsNullValueException ("The property contains Null.");
112                                 else 
113                                         return value; 
114                         }
115                 }
116
117                 #endregion
118
119                 #region Methods
120
121                 public int CompareTo (object value)
122                 {
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);
131                 }
132
133                 public override bool Equals (object value)
134                 {
135                         if (!(value is TdsDateTime))
136                                 return false;
137                         else
138                                 return (bool) (this == (TdsDateTime)value);
139                 }
140
141                 public static TdsBoolean Equals (TdsDateTime x, TdsDateTime y)
142                 {
143                         return (x == y);
144                 }
145
146                 [MonoTODO]
147                 public override int GetHashCode ()
148                 {
149                         return 42;
150                 }
151
152                 public static TdsBoolean GreaterThan (TdsDateTime x, TdsDateTime y)
153                 {
154                         return (x > y);
155                 }
156
157                 public static TdsBoolean GreaterThanOrEqual (TdsDateTime x, TdsDateTime y)
158                 {
159                         return (x >= y);
160                 }
161
162                 public static TdsBoolean LessThan (TdsDateTime x, TdsDateTime y)
163                 {
164                         return (x < y);
165                 }
166
167                 public static TdsBoolean LessThanOrEqual (TdsDateTime x, TdsDateTime y)
168                 {
169                         return (x <= y);
170                 }
171
172                 public static TdsBoolean NotEquals (TdsDateTime x, TdsDateTime y)
173                 {
174                         return (x != y);
175                 }
176
177                 [MonoTODO]
178                 public static TdsDateTime Parse (string s)
179                 {
180                         throw new NotImplementedException ();
181                 }
182
183                 public TdsString ToTdsString ()
184                 {
185                         return ((TdsString)this);
186                 }
187
188                 public override string ToString ()
189                 {       
190                         if (this.IsNull)
191                                 return String.Empty;
192                         else
193                                 return value.ToString ();
194                 }
195         
196                 [MonoTODO]      
197                 public static TdsDateTime operator + (TdsDateTime x, TimeSpan t)
198                 {
199                         throw new NotImplementedException ();
200                 }
201
202                 public static TdsBoolean operator == (TdsDateTime x, TdsDateTime y)
203                 {
204                         if (x.IsNull || y.IsNull) 
205                                 return TdsBoolean.Null;
206                         else
207                                 return new TdsBoolean (x.Value == y.Value);
208                 }
209
210                 public static TdsBoolean operator > (TdsDateTime x, TdsDateTime y)
211                 {
212                         if (x.IsNull || y.IsNull) 
213                                 return TdsBoolean.Null;
214                         else
215                                 return new TdsBoolean (x.Value > y.Value);
216                 }
217
218                 public static TdsBoolean operator >= (TdsDateTime x, TdsDateTime y)
219                 {
220                         if (x.IsNull || y.IsNull) 
221                                 return TdsBoolean.Null;
222                         else
223                                 return new TdsBoolean (x.Value >= y.Value);
224                 }
225
226                 public static TdsBoolean operator != (TdsDateTime x, TdsDateTime y)
227                 {
228                         if (x.IsNull || y.IsNull) 
229                                 return TdsBoolean.Null;
230                         else
231                                 return new TdsBoolean (!(x.Value == y.Value));
232                 }
233
234                 public static TdsBoolean operator < (TdsDateTime x, TdsDateTime y)
235                 {
236                         if (x.IsNull || y.IsNull) 
237                                 return TdsBoolean.Null;
238                         else
239                                 return new TdsBoolean (x.Value < y.Value);
240                 }
241
242                 public static TdsBoolean operator <= (TdsDateTime x, TdsDateTime y)
243                 {
244                         if (x.IsNull || y.IsNull) 
245                                 return TdsBoolean.Null;
246                         else
247                                 return new TdsBoolean (x.Value <= y.Value);
248                 }
249
250                 [MonoTODO]
251                 public static TdsDateTime operator - (TdsDateTime x, TimeSpan t)
252                 {
253                         throw new NotImplementedException ();
254                 }
255
256                 public static explicit operator DateTime (TdsDateTime x)
257                 {
258                         return x.Value;
259                 }
260
261                 [MonoTODO]
262                 public static explicit operator TdsDateTime (TdsString x)
263                 {
264                         throw new NotImplementedException();
265                 }
266
267                 public static implicit operator TdsDateTime (DateTime x)
268                 {
269                         return new TdsDateTime (x);
270                 }
271
272                 #endregion
273         }
274 }
275