Applied patch from: David Pickens <dsp@rci.rutgers.edu>
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OracleDateTime.cs
1 //
2 // OracleDateTime.cs 
3 //
4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
6 //
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
9 //
10 // Author: Tim Coleman <tim@timcoleman.com>
11 //
12 // Copyright (C) Tim Coleman, 2003
13 //
14 // Licensed under the MIT/X11 License.
15 //
16
17 using System;
18 using System.Data.SqlTypes;
19 using System.Globalization;
20
21 namespace System.Data.OracleClient {
22         public struct OracleDateTime : IComparable, INullable
23         {
24                 #region Fields
25
26                 public static readonly OracleDateTime MaxValue = new OracleDateTime (4712, 12, 31);
27                 public static readonly OracleDateTime MinValue = new OracleDateTime (1, 1, 1);
28                 public static readonly OracleDateTime Null = new OracleDateTime ();
29
30                 DateTime value;
31                 bool notNull;
32
33                 #endregion // Fields
34
35                 #region Constructors
36
37                 public OracleDateTime (DateTime dt)
38                 {
39                         value = dt; 
40                         notNull = true;
41                 }
42
43                 public OracleDateTime (long ticks)
44                         : this (new DateTime (ticks))
45                 {
46                 }
47
48                 public OracleDateTime (OracleDateTime from)
49                         : this (from.Value)
50                 {
51                 }
52
53                 public OracleDateTime (int year, int month, int day)
54                         : this (new DateTime (year, month, day))
55                 {
56                 }
57
58                 public OracleDateTime (int year, int month, int day, Calendar calendar)
59                         : this (new DateTime (year, month, day, calendar))
60                 {
61                 }
62
63                 public OracleDateTime (int year, int month, int day, int hour, int minute, int second)
64                         : this (new DateTime (year, month, day, hour, minute, second))
65                 {
66                 }
67
68                 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar)
69                         : this (new DateTime (year, month, day, hour, minute, second, calendar))
70                 {
71                 }
72
73                 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond)
74                         : this (new DateTime (year, month, day, hour, minute, second, millisecond))
75                 {
76                 }
77
78                 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
79                         : this (new DateTime (year, month, day, hour, minute, second, millisecond, calendar))
80                 {
81                 }
82
83                 #endregion // Constructors
84
85                 #region Properties
86
87                 public int Day {
88                         get { return value.Day; }
89                 }
90
91                 public int Hour {
92                         get { return value.Hour; }
93                 }
94
95                 public bool IsNull {
96                         get { return !notNull; }
97                 }
98
99                 public int Millisecond {
100                         get { return value.Millisecond; }
101                 }
102
103                 public int Minute {
104                         get { return value.Minute; }
105                 }
106
107                 public int Month {
108                         get { return value.Month; }
109                 }
110
111                 public int Second {
112                         get { return value.Second; }
113                 }
114
115                 public DateTime Value {
116                         get { return value; }
117                 }
118
119                 public int Year {
120                         get { return value.Year; }
121                 }
122
123                 #endregion // Properties
124
125                 #region Methods
126
127                 [MonoTODO]
128                 public int CompareTo (object obj)
129                 {
130                         throw new NotImplementedException ();
131                 }
132
133                 [MonoTODO]
134                 public override bool Equals (object value)
135                 {
136                         throw new NotImplementedException ();
137                 }
138
139                 public static OracleBoolean Equals (OracleDateTime x, OracleDateTime y)
140                 {
141                         if (x.IsNull || y.IsNull)
142                                 return OracleBoolean.Null;
143                         return new OracleBoolean (x.Value == y.Value);
144                 }
145
146                 [MonoTODO]
147                 public override int GetHashCode ()
148                 {
149                         throw new NotImplementedException ();
150                 }
151
152                 public static OracleBoolean GreaterThan (OracleDateTime x, OracleDateTime y)
153                 {
154                         if (x.IsNull || y.IsNull)
155                                 return OracleBoolean.Null;
156                         return new OracleBoolean (x.Value > y.Value);
157                 }
158
159                 public static OracleBoolean GreaterThanOrEqual (OracleDateTime x, OracleDateTime y)
160                 {
161                         if (x.IsNull || y.IsNull)
162                                 return OracleBoolean.Null;
163                         return new OracleBoolean (x.Value >= y.Value);
164                 }
165
166                 public static OracleBoolean LessThan (OracleDateTime x, OracleDateTime y)
167                 {
168                         if (x.IsNull || y.IsNull)
169                                 return OracleBoolean.Null;
170                         return new OracleBoolean (x.Value < y.Value);
171                 }
172
173                 public static OracleBoolean LessThanOrEqual (OracleDateTime x, OracleDateTime y)
174                 {
175                         if (x.IsNull || y.IsNull)
176                                 return OracleBoolean.Null;
177                         return new OracleBoolean (x.Value <= y.Value);
178                 }
179
180                 public static OracleBoolean NotEquals (OracleDateTime x, OracleDateTime y)
181                 {
182                         if (x.IsNull || y.IsNull)
183                                 return OracleBoolean.Null;
184                         return new OracleBoolean (x.Value != y.Value);
185                 }
186
187                 public static OracleDateTime Parse (string s)
188                 {
189                         return new OracleDateTime (DateTime.Parse (s));
190                 }
191
192                 public override string ToString ()
193                 {
194                         if (IsNull)
195                                 return "Null";
196                         return Value.ToString ();
197                 }
198
199                 #endregion // Methods
200
201                 #region Operators and Type Conversions
202
203                 public static OracleBoolean operator == (OracleDateTime x, OracleDateTime y)
204                 {
205                         return Equals (x, y);
206                 }
207
208                 public static OracleBoolean operator > (OracleDateTime x, OracleDateTime y)
209                 {
210                         return GreaterThan (x, y);
211                 }
212
213                 public static OracleBoolean operator >= (OracleDateTime x, OracleDateTime y)
214                 {
215                         return GreaterThanOrEqual (x, y);
216                 }
217
218                 public static OracleBoolean operator != (OracleDateTime x, OracleDateTime y)
219                 {
220                         return NotEquals (x, y);
221                 }
222
223                 public static OracleBoolean operator < (OracleDateTime x, OracleDateTime y)
224                 {
225                         return LessThan (x, y);
226                 }
227
228                 public static OracleBoolean operator <= (OracleDateTime x, OracleDateTime y)
229                 {
230                         return LessThanOrEqual (x, y);
231                 }
232
233                 public static explicit operator DateTime (OracleDateTime x)
234                 {
235                         return x.Value;
236                 }
237
238                 public static explicit operator OracleDateTime (DateTime x)
239                 {
240                         return new OracleDateTime (x);
241                 }
242
243                 #endregion // Operators and Type Conversions
244         }
245 }