4 // Part of the Mono class libraries at
5 // mcs/class/System.Data.OracleClient/System.Data.OracleClient
7 // Assembly: System.Data.OracleClient.dll
8 // Namespace: System.Data.OracleClient
10 // Authors: Tim Coleman <tim@timcoleman.com>
11 // Daniel Morgan <danielmorgan@verizon.net>
13 // Copyright (C) Tim Coleman, 2003
14 // Copyright (C) Daniel Morgan, 2005
16 // Licensed under the MIT/X11 License.
20 using System.Data.SqlTypes;
21 using System.Globalization;
24 namespace System.Data.OracleClient {
25 public struct OracleDateTime : IComparable, INullable
29 public static readonly OracleDateTime MaxValue = new OracleDateTime (4712, 12, 31);
30 public static readonly OracleDateTime MinValue = new OracleDateTime (1, 1, 1);
31 public static readonly OracleDateTime Null = new OracleDateTime ();
40 public OracleDateTime (DateTime dt)
46 public OracleDateTime (long ticks)
47 : this (new DateTime (ticks))
51 public OracleDateTime (OracleDateTime from)
56 public OracleDateTime (int year, int month, int day)
57 : this (new DateTime (year, month, day))
61 public OracleDateTime (int year, int month, int day, Calendar calendar)
62 : this (new DateTime (year, month, day, calendar))
66 public OracleDateTime (int year, int month, int day, int hour, int minute, int second)
67 : this (new DateTime (year, month, day, hour, minute, second))
71 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, Calendar calendar)
72 : this (new DateTime (year, month, day, hour, minute, second, calendar))
76 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond)
77 : this (new DateTime (year, month, day, hour, minute, second, millisecond))
81 public OracleDateTime (int year, int month, int day, int hour, int minute, int second, int millisecond, Calendar calendar)
82 : this (new DateTime (year, month, day, hour, minute, second, millisecond, calendar))
86 #endregion // Constructors
91 get { return value.Day; }
95 get { return value.Hour; }
99 get { return !notNull; }
102 public int Millisecond {
103 get { return value.Millisecond; }
107 get { return value.Minute; }
111 get { return value.Month; }
115 get { return value.Second; }
118 public DateTime Value {
119 get { return value; }
123 get { return value.Year; }
126 #endregion // Properties
131 public int CompareTo (object obj)
133 throw new NotImplementedException ();
137 public override bool Equals (object value)
139 throw new NotImplementedException ();
142 public static OracleBoolean Equals (OracleDateTime x, OracleDateTime y)
144 if (x.IsNull || y.IsNull)
145 return OracleBoolean.Null;
146 return new OracleBoolean (x.Value == y.Value);
150 public override int GetHashCode ()
152 throw new NotImplementedException ();
155 public static OracleBoolean GreaterThan (OracleDateTime x, OracleDateTime y)
157 if (x.IsNull || y.IsNull)
158 return OracleBoolean.Null;
159 return new OracleBoolean (x.Value > y.Value);
162 public static OracleBoolean GreaterThanOrEqual (OracleDateTime x, OracleDateTime y)
164 if (x.IsNull || y.IsNull)
165 return OracleBoolean.Null;
166 return new OracleBoolean (x.Value >= y.Value);
169 public static OracleBoolean LessThan (OracleDateTime x, OracleDateTime y)
171 if (x.IsNull || y.IsNull)
172 return OracleBoolean.Null;
173 return new OracleBoolean (x.Value < y.Value);
176 public static OracleBoolean LessThanOrEqual (OracleDateTime x, OracleDateTime y)
178 if (x.IsNull || y.IsNull)
179 return OracleBoolean.Null;
180 return new OracleBoolean (x.Value <= y.Value);
183 public static OracleBoolean NotEquals (OracleDateTime x, OracleDateTime y)
185 if (x.IsNull || y.IsNull)
186 return OracleBoolean.Null;
187 return new OracleBoolean (x.Value != y.Value);
190 public static OracleDateTime Parse (string s)
192 return new OracleDateTime (DateTime.Parse (s));
195 public override string ToString ()
199 return Value.ToString ();
202 #endregion // Methods
204 #region Operators and Type Conversions
206 public static OracleBoolean operator == (OracleDateTime x, OracleDateTime y)
208 return Equals (x, y);
211 public static OracleBoolean operator > (OracleDateTime x, OracleDateTime y)
213 return GreaterThan (x, y);
216 public static OracleBoolean operator >= (OracleDateTime x, OracleDateTime y)
218 return GreaterThanOrEqual (x, y);
221 public static OracleBoolean operator != (OracleDateTime x, OracleDateTime y)
223 return NotEquals (x, y);
226 public static OracleBoolean operator < (OracleDateTime x, OracleDateTime y)
228 return LessThan (x, y);
231 public static OracleBoolean operator <= (OracleDateTime x, OracleDateTime y)
233 return LessThanOrEqual (x, y);
236 public static explicit operator DateTime (OracleDateTime x)
241 public static explicit operator OracleDateTime (string x)
243 return new OracleDateTime (DateTime.Parse (x));
246 private static string ConvertSystemDatePartToOracleDate (string sysPart)
248 if (sysPart.Length == 0)
279 // ignore any others?
285 private static string ConvertOracleDatePartToSystemDatePart (string oraPart)
287 if (oraPart.Length == 0)
293 // TODO: need to handle "A.M." and "P.M."
295 case "RR": // TODO: handle special year RR. for now, treat it like yy
323 // ignore any others?
329 internal static string ConvertSystemDateTimeFormatToOracleDate (string sysFormat)
331 if (sysFormat == String.Empty)
334 char[] chars = sysFormat.ToCharArray ();
336 StringBuilder sb = new StringBuilder ();
337 StringBuilder sfinal = new StringBuilder ();
340 bool inQuote = false;
341 char quoteChar = '\"';
344 for (i = 0; i < chars.Length; i++) {
347 if (inQuote == true) {
361 sPart = ConvertSystemDatePartToOracleDate (sb.ToString ());
362 if (sPart.Length > 0)
363 sfinal.Append (sPart);
366 sb = new StringBuilder ();
382 sPart = ConvertSystemDatePartToOracleDate (sb.ToString ());
383 if (sPart.Length > 0)
384 sfinal.Append (sPart);
387 string returnStr = sfinal.ToString ();
392 internal static string ConvertOracleDateFormatToSystemDateTime (string oraFormat)
394 if (oraFormat == String.Empty)
397 char[] chars = oraFormat.ToCharArray ();
399 StringBuilder sb = new StringBuilder ();
400 StringBuilder sfinal = new StringBuilder ();
403 bool inQuote = false;
404 char quoteChar = '\"';
407 for (i = 0; i < chars.Length; i++) {
410 if (inQuote == true) {
424 sPart = ConvertOracleDatePartToSystemDatePart (sb.ToString ());
425 if (sPart.Length > 0)
426 sfinal.Append (sPart);
429 sb = new StringBuilder ();
445 sPart = ConvertOracleDatePartToSystemDatePart (sb.ToString ());
446 if (sPart.Length > 0)
447 sfinal.Append (sPart);
450 string returnStr = sfinal.ToString ();
455 #endregion // Operators and Type Conversions