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 { 22 public struct OracleTimeSpan : IComparable, INullable 23 { 24 #region Fields 25 26 public static readonly OracleTimeSpan MaxValue = new OracleTimeSpan (TimeSpan.MaxValue); 27 public static readonly OracleTimeSpan MinValue = new OracleTimeSpan (TimeSpan.MinValue); 28 public static readonly OracleTimeSpan Null = new OracleTimeSpan (); 29 30 bool notNull; 31 TimeSpan value; 32 33 #endregion // Fields 34 35 #region Constructors 36 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan37 public OracleTimeSpan (long ticks) 38 : this (new TimeSpan (ticks)) 39 { 40 } 41 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan42 public OracleTimeSpan (OracleTimeSpan from) 43 { 44 if (from.IsNull) 45 throw new NullReferenceException (); 46 value = from.value; 47 notNull = true; 48 } 49 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan50 public OracleTimeSpan (TimeSpan ts) 51 { 52 value = ts; 53 notNull = true; 54 } 55 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan56 public OracleTimeSpan (int hours, int minutes, int seconds) 57 : this (new TimeSpan (hours, minutes, seconds)) 58 { 59 } 60 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan61 public OracleTimeSpan (int days, int hours, int minutes, int seconds) 62 : this (new TimeSpan (days, hours, minutes, seconds)) 63 { 64 } 65 OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan66 public OracleTimeSpan (int days, int hours, int minutes, int seconds, int milliseconds) 67 : this (new TimeSpan (days, hours, minutes, seconds, milliseconds)) 68 { 69 } 70 71 #endregion // Constructors 72 73 #region Properties 74 75 public int Days { 76 get { return Value.Days; } 77 } 78 79 public int Hours { 80 get { return Value.Hours; } 81 } 82 83 public bool IsNull { 84 get { return !notNull; } 85 } 86 87 public int Milliseconds { 88 get { return Value.Milliseconds; } 89 } 90 91 public int Minutes { 92 get { return Value.Minutes; } 93 } 94 95 public int Seconds { 96 get { return Value.Seconds; } 97 } 98 99 public TimeSpan Value { 100 get { 101 if (IsNull) 102 throw CreateValueNullException (); 103 return value; 104 } 105 } 106 107 #endregion // Properties 108 109 #region Methods 110 CompareToSystem.Data.OracleClient.OracleTimeSpan111 public int CompareTo (object obj) 112 { 113 OracleTimeSpan o = (OracleTimeSpan) obj; 114 if (obj == null) 115 throw new NullReferenceException ("Object reference not set to an instance of an object"); 116 else if (!(obj is OracleTimeSpan)) 117 throw new ArgumentException ("Value is not a System.Data.OracleClient.OracleTimeSpan", obj.ToString ()); 118 else if (o.IsNull && this.IsNull) 119 return 0; 120 else if (o.IsNull && !(this.IsNull)) 121 return 1; 122 else 123 return value.CompareTo (o.Value); 124 } 125 EqualsSystem.Data.OracleClient.OracleTimeSpan126 public override bool Equals (object value) 127 { 128 if (value is OracleTimeSpan) 129 { 130 OracleTimeSpan t = (OracleTimeSpan) value; 131 if (!(this.IsNull) && !(t.IsNull)) 132 return this.value == t.value; 133 else 134 throw new InvalidOperationException ("The value is null"); 135 } 136 return false; 137 } 138 EqualsSystem.Data.OracleClient.OracleTimeSpan139 public static OracleBoolean Equals (OracleTimeSpan x, OracleTimeSpan y) 140 { 141 if (x.IsNull || y.IsNull) 142 return OracleBoolean.Null; 143 return new OracleBoolean (x.Value == y.Value); 144 } 145 146 [MonoTODO] GetHashCodeSystem.Data.OracleClient.OracleTimeSpan147 public override int GetHashCode () 148 { 149 throw new NotImplementedException (); 150 } 151 GreaterThanSystem.Data.OracleClient.OracleTimeSpan152 public static OracleBoolean GreaterThan (OracleTimeSpan x, OracleTimeSpan y) 153 { 154 if (x.IsNull || y.IsNull) 155 return OracleBoolean.Null; 156 return (x.Value > y.Value); 157 } 158 GreaterThanOrEqualSystem.Data.OracleClient.OracleTimeSpan159 public static OracleBoolean GreaterThanOrEqual (OracleTimeSpan x, OracleTimeSpan y) 160 { 161 if (x.IsNull || y.IsNull) 162 return OracleBoolean.Null; 163 return (x.Value >= y.Value); 164 } 165 LessThanSystem.Data.OracleClient.OracleTimeSpan166 public static OracleBoolean LessThan (OracleTimeSpan x, OracleTimeSpan y) 167 { 168 if (x.IsNull || y.IsNull) 169 return OracleBoolean.Null; 170 return (x.Value < y.Value); 171 } 172 LessThanOrEqualSystem.Data.OracleClient.OracleTimeSpan173 public static OracleBoolean LessThanOrEqual (OracleTimeSpan x, OracleTimeSpan y) 174 { 175 if (x.IsNull || y.IsNull) 176 return OracleBoolean.Null; 177 return (x.Value <= y.Value); 178 } 179 NotEqualsSystem.Data.OracleClient.OracleTimeSpan180 public static OracleBoolean NotEquals (OracleTimeSpan x, OracleTimeSpan y) 181 { 182 if (x.IsNull || y.IsNull) 183 return OracleBoolean.Null; 184 return (x.Value != y.Value); 185 } 186 ParseSystem.Data.OracleClient.OracleTimeSpan187 public static OracleTimeSpan Parse (string s) 188 { 189 return new OracleTimeSpan (TimeSpan.Parse (s)); 190 } 191 ToStringSystem.Data.OracleClient.OracleTimeSpan192 public override string ToString () 193 { 194 if (IsNull) 195 return "Null"; 196 return value.ToString (); 197 } 198 CreateValueNullExceptionSystem.Data.OracleClient.OracleTimeSpan199 static Exception CreateValueNullException () 200 { 201 return new InvalidOperationException ("The value is Null"); 202 } 203 204 #endregion // Methods 205 206 #region Operators and Type Conversions 207 operator ==System.Data.OracleClient.OracleTimeSpan208 public static OracleBoolean operator == (OracleTimeSpan x, OracleTimeSpan y) 209 { 210 return Equals (x, y); 211 } 212 operator >System.Data.OracleClient.OracleTimeSpan213 public static OracleBoolean operator > (OracleTimeSpan x, OracleTimeSpan y) 214 { 215 return GreaterThan (x, y); 216 } 217 operator >=System.Data.OracleClient.OracleTimeSpan218 public static OracleBoolean operator >= (OracleTimeSpan x, OracleTimeSpan y) 219 { 220 return GreaterThanOrEqual (x, y); 221 } 222 operator !=System.Data.OracleClient.OracleTimeSpan223 public static OracleBoolean operator != (OracleTimeSpan x, OracleTimeSpan y) 224 { 225 return NotEquals (x, y); 226 } 227 operator <System.Data.OracleClient.OracleTimeSpan228 public static OracleBoolean operator < (OracleTimeSpan x, OracleTimeSpan y) 229 { 230 return LessThan (x, y); 231 } 232 operator <=System.Data.OracleClient.OracleTimeSpan233 public static OracleBoolean operator <= (OracleTimeSpan x, OracleTimeSpan y) 234 { 235 return LessThan (x, y); 236 } 237 operator TimeSpanSystem.Data.OracleClient.OracleTimeSpan238 public static explicit operator TimeSpan (OracleTimeSpan x) 239 { 240 return x.Value; 241 } 242 operator OracleTimeSpanSystem.Data.OracleClient.OracleTimeSpan243 public static explicit operator OracleTimeSpan (string x) 244 { 245 return Parse (x); 246 } 247 248 #endregion // Operators and Type Conversions 249 } 250 } 251