2002-11-01 Tim Coleman (tim@timcoleman.com)
[mono.git] / mcs / class / Mono.Data.SybaseClient / Mono.Data.SybaseTypes / SybaseDateTime.cs
1 //
2 // Mono.Data.SybaseTypes.SybaseDateTime
3 //
4 // Author:
5 //   Tim Coleman <tim@timcoleman.com>
6 //
7 // (C) Copyright Tim Coleman, 2002
8 //
9
10 using Mono.Data.SybaseClient;
11 using System;
12 using System.Data.SqlTypes;
13 using System.Globalization;
14
15 namespace Mono.Data.SybaseTypes {
16         public struct SybaseDateTime : INullable, IComparable
17         {
18                 #region Fields
19                 private DateTime value;
20                 private bool notNull;
21
22                 public static readonly SybaseDateTime MaxValue = new SybaseDateTime (9999,12,31);
23                 public static readonly SybaseDateTime MinValue = new SybaseDateTime (1753,1,1);
24                 public static readonly SybaseDateTime Null;
25                 public static readonly int SQLTicksPerHour;
26                 public static readonly int SQLTicksPerMinute;
27                 public static readonly int SQLTicksPerSecond;
28
29                 #endregion
30
31                 #region Constructors
32
33                 public SybaseDateTime (DateTime value) 
34                 {
35                         this.value = value;
36                         notNull = true;
37                 }
38
39                 [MonoTODO]
40                 public SybaseDateTime (int dayTicks, int timeTicks) 
41                 {
42                         throw new NotImplementedException ();
43                 }
44
45                 public SybaseDateTime (int year, int month, int day) 
46                 {
47                         this.value = new DateTime (year, month, day);
48                         notNull = true;
49                 }
50
51                 public SybaseDateTime (int year, int month, int day, int hour, int minute, int second) 
52                 {
53                         this.value = new DateTime (year, month, day, hour, minute, second);
54                         notNull = true;
55                 }
56
57                 [MonoTODO]
58                 public SybaseDateTime (int year, int month, int day, int hour, int minute, int second, double millisecond) 
59                 {
60                         throw new NotImplementedException ();
61                 }
62
63                 [MonoTODO]
64                 public SybaseDateTime (int year, int month, int day, int hour, int minute, int second, int bilisecond) 
65                 {
66                         throw new NotImplementedException ();
67                 }
68
69                 #endregion
70
71                 #region Properties
72
73                 [MonoTODO]
74                 public int DayTicks {
75                         get { throw new NotImplementedException (); }
76                 }
77
78                 public bool IsNull { 
79                         get { return !notNull; }
80                 }
81
82                 [MonoTODO]
83                 public int TimeTicks {
84                         get { throw new NotImplementedException (); }
85                 }
86
87                 public DateTime Value {
88                         get { 
89                                 if (this.IsNull) 
90                                         throw new SybaseNullValueException ("The property contains Null.");
91                                 else 
92                                         return value; 
93                         }
94                 }
95
96                 #endregion
97
98                 #region Methods
99
100                 public int CompareTo (object value)
101                 {
102                         if (value == null)
103                                 return 1;
104                         else if (!(value is SybaseDateTime))
105                                 throw new ArgumentException (Locale.GetText ("Value is not a System.Data.SybaseTypes.SybaseDateTime"));
106                         else if (((SybaseDateTime)value).IsNull)
107                                 return 1;
108                         else
109                                 return this.value.CompareTo (((SybaseDateTime)value).Value);
110                 }
111
112                 public override bool Equals (object value)
113                 {
114                         if (!(value is SybaseDateTime))
115                                 return false;
116                         else
117                                 return (bool) (this == (SybaseDateTime)value);
118                 }
119
120                 public static SybaseBoolean Equals (SybaseDateTime x, SybaseDateTime y)
121                 {
122                         return (x == y);
123                 }
124
125                 [MonoTODO]
126                 public override int GetHashCode ()
127                 {
128                         return 42;
129                 }
130
131                 public static SybaseBoolean GreaterThan (SybaseDateTime x, SybaseDateTime y)
132                 {
133                         return (x > y);
134                 }
135
136                 public static SybaseBoolean GreaterThanOrEqual (SybaseDateTime x, SybaseDateTime y)
137                 {
138                         return (x >= y);
139                 }
140
141                 public static SybaseBoolean LessThan (SybaseDateTime x, SybaseDateTime y)
142                 {
143                         return (x < y);
144                 }
145
146                 public static SybaseBoolean LessThanOrEqual (SybaseDateTime x, SybaseDateTime y)
147                 {
148                         return (x <= y);
149                 }
150
151                 public static SybaseBoolean NotEquals (SybaseDateTime x, SybaseDateTime y)
152                 {
153                         return (x != y);
154                 }
155
156                 [MonoTODO]
157                 public static SybaseDateTime Parse (string s)
158                 {
159                         throw new NotImplementedException ();
160                 }
161
162                 public SybaseString ToSybaseString ()
163                 {
164                         return ((SybaseString)this);
165                 }
166
167                 public override string ToString ()
168                 {       
169                         if (this.IsNull)
170                                 return String.Empty;
171                         else
172                                 return value.ToString ();
173                 }
174         
175                 [MonoTODO]      
176                 public static SybaseDateTime operator + (SybaseDateTime x, TimeSpan t)
177                 {
178                         throw new NotImplementedException ();
179                 }
180
181                 public static SybaseBoolean operator == (SybaseDateTime x, SybaseDateTime y)
182                 {
183                         if (x.IsNull || y.IsNull) 
184                                 return SybaseBoolean.Null;
185                         else
186                                 return new SybaseBoolean (x.Value == y.Value);
187                 }
188
189                 public static SybaseBoolean operator > (SybaseDateTime x, SybaseDateTime y)
190                 {
191                         if (x.IsNull || y.IsNull) 
192                                 return SybaseBoolean.Null;
193                         else
194                                 return new SybaseBoolean (x.Value > y.Value);
195                 }
196
197                 public static SybaseBoolean operator >= (SybaseDateTime x, SybaseDateTime y)
198                 {
199                         if (x.IsNull || y.IsNull) 
200                                 return SybaseBoolean.Null;
201                         else
202                                 return new SybaseBoolean (x.Value >= y.Value);
203                 }
204
205                 public static SybaseBoolean operator != (SybaseDateTime x, SybaseDateTime y)
206                 {
207                         if (x.IsNull || y.IsNull) 
208                                 return SybaseBoolean.Null;
209                         else
210                                 return new SybaseBoolean (!(x.Value == y.Value));
211                 }
212
213                 public static SybaseBoolean operator < (SybaseDateTime x, SybaseDateTime y)
214                 {
215                         if (x.IsNull || y.IsNull) 
216                                 return SybaseBoolean.Null;
217                         else
218                                 return new SybaseBoolean (x.Value < y.Value);
219                 }
220
221                 public static SybaseBoolean operator <= (SybaseDateTime x, SybaseDateTime y)
222                 {
223                         if (x.IsNull || y.IsNull) 
224                                 return SybaseBoolean.Null;
225                         else
226                                 return new SybaseBoolean (x.Value <= y.Value);
227                 }
228
229                 [MonoTODO]
230                 public static SybaseDateTime operator - (SybaseDateTime x, TimeSpan t)
231                 {
232                         throw new NotImplementedException ();
233                 }
234
235                 public static explicit operator DateTime (SybaseDateTime x)
236                 {
237                         return x.Value;
238                 }
239
240                 [MonoTODO]
241                 public static explicit operator SybaseDateTime (SybaseString x)
242                 {
243                         throw new NotImplementedException();
244                 }
245
246                 public static implicit operator SybaseDateTime (DateTime x)
247                 {
248                         return new SybaseDateTime (x);
249                 }
250
251                 #endregion
252         }
253 }
254