Applied patch from: David Pickens <dsp@rci.rutgers.edu>
[mono.git] / mcs / class / System.Data.OracleClient / System.Data.OracleClient / OracleTimeSpan.cs
1 //
2 // OracleTimeSpan.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
20 namespace System.Data.OracleClient {
21         public struct OracleTimeSpan : IComparable, INullable
22         {
23                 #region Fields
24
25                 public static readonly OracleTimeSpan MaxValue = new OracleTimeSpan (TimeSpan.MaxValue);
26                 public static readonly OracleTimeSpan MinValue = new OracleTimeSpan (TimeSpan.MinValue);
27                 public static readonly OracleTimeSpan Null = new OracleTimeSpan ();
28
29                 bool notNull; 
30                 TimeSpan value;
31
32                 #endregion // Fields
33
34                 #region Constructors
35
36                 public OracleTimeSpan (long ticks)
37                         : this (new TimeSpan (ticks))
38                 {
39                 }
40
41                 public OracleTimeSpan (OracleTimeSpan from)
42                         : this (from.Value)
43                 {
44                 }
45
46                 public OracleTimeSpan (TimeSpan ts)
47                 {
48                         value = ts;
49                         notNull = true;
50                 }
51
52                 public OracleTimeSpan (int hours, int minutes, int seconds)
53                         : this (new TimeSpan (hours, minutes, seconds))
54                 {
55                 }
56
57                 public OracleTimeSpan (int days, int hours, int minutes, int seconds)
58                         : this (new TimeSpan (days, hours, minutes, seconds))
59                 {
60                 }
61
62                 public OracleTimeSpan (int days, int hours, int minutes, int seconds, int milliseconds)
63                         : this (new TimeSpan (days, hours, minutes, seconds, milliseconds))
64                 {
65                 }
66
67                 #endregion // Constructors
68
69                 #region Properties
70
71                 public int Days {
72                         get { return Value.Days; }
73                 }
74
75                 public int Hours {
76                         get { return Value.Days; }
77                 }
78
79                 public bool IsNull {
80                         get { return !notNull; }
81                 }
82
83                 public int Milliseconds {
84                         get { return Value.Milliseconds; }
85                 }
86
87                 public int Minutes {
88                         get { return Value.Minutes; }
89                 }
90
91                 public int Seconds {
92                         get { return Value.Seconds; }
93                 }
94
95                 public TimeSpan Value {
96                         get { return value; }
97                 }
98
99                 #endregion // Properties
100
101                 #region Methods
102
103                 [MonoTODO]
104                 public int CompareTo (object obj)
105                 {
106                         throw new NotImplementedException ();
107                 }
108
109                 [MonoTODO]
110                 public override bool Equals (object value)
111                 {
112                         throw new NotImplementedException ();
113                 }
114
115                 public static OracleBoolean Equals (OracleTimeSpan x, OracleTimeSpan y)
116                 {
117                         if (x.IsNull || y.IsNull)
118                                 return OracleBoolean.Null;
119                         return new OracleBoolean (x.Value == y.Value);
120                 }
121
122                 [MonoTODO]
123                 public override int GetHashCode ()
124                 {
125                         throw new NotImplementedException ();
126                 }
127
128                 public static OracleBoolean GreaterThan (OracleTimeSpan x, OracleTimeSpan y)
129                 {
130                         if (x.IsNull || y.IsNull)
131                                 return OracleBoolean.Null;
132                         return (x.Value > y.Value);
133                 }
134
135                 public static OracleBoolean GreaterThanOrEqual (OracleTimeSpan x, OracleTimeSpan y)
136                 {
137                         if (x.IsNull || y.IsNull)
138                                 return OracleBoolean.Null;
139                         return (x.Value >= y.Value);
140                 }
141
142                 public static OracleBoolean LessThan (OracleTimeSpan x, OracleTimeSpan y)
143                 {
144                         if (x.IsNull || y.IsNull)
145                                 return OracleBoolean.Null;
146                         return (x.Value < y.Value);
147                 }
148
149                 public static OracleBoolean LessThanOrEqual (OracleTimeSpan x, OracleTimeSpan y)
150                 {
151                         if (x.IsNull || y.IsNull)
152                                 return OracleBoolean.Null;
153                         return (x.Value <= y.Value);
154                 }
155
156                 public static OracleBoolean NotEquals (OracleTimeSpan x, OracleTimeSpan y)
157                 {
158                         if (x.IsNull || y.IsNull)
159                                 return OracleBoolean.Null;
160                         return (x.Value != y.Value);
161                 }
162                 
163                 public static OracleTimeSpan Parse (string s)
164                 {
165                         return new OracleTimeSpan (TimeSpan.Parse (s));
166                 }
167
168                 public override string ToString ()
169                 {
170                         if (IsNull)
171                                 return "Null";
172                         return value.ToString ();
173                 }
174
175                 #endregion // Methods
176
177                 #region Operators and Type Conversions
178
179                 public static OracleBoolean operator == (OracleTimeSpan x, OracleTimeSpan y)
180                 {
181                         return Equals (x, y);
182                 }
183
184                 public static OracleBoolean operator > (OracleTimeSpan x, OracleTimeSpan y)
185                 {
186                         return GreaterThan (x, y);
187                 }
188
189                 public static OracleBoolean operator >= (OracleTimeSpan x, OracleTimeSpan y)
190                 {
191                         return GreaterThanOrEqual (x, y);
192                 }
193
194                 public static OracleBoolean operator != (OracleTimeSpan x, OracleTimeSpan y)
195                 {
196                         return NotEquals (x, y);
197                 }
198
199                 public static OracleBoolean operator < (OracleTimeSpan x, OracleTimeSpan y)
200                 {
201                         return LessThan (x, y);
202                 }
203
204                 public static OracleBoolean operator <= (OracleTimeSpan x, OracleTimeSpan y)
205                 {
206                         return LessThan (x, y);
207                 }
208
209                 public static explicit operator TimeSpan (OracleTimeSpan x)
210                 {
211                         return x.Value;
212                 }
213
214                 public static explicit operator OracleTimeSpan (string s)
215                 {
216                         return Parse (s);
217                 }
218
219                 #endregion // Operators and Type Conversions
220         }
221 }