Changeset 107 for Include/Classes/System
- Timestamp:
- Feb 17, 2007, 6:41:00 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Include/Classes/System/DateTime.ab
r103 r107 27 27 End If 28 28 DateTime(316224000000000) 29 AddYears(year - 1)29 This = AddYears(year - 1) 30 30 31 31 Dim days As Long … … 35 35 Next 36 36 days += day 37 AddDays(days - 1)37 This = AddDays(days - 1) 38 38 End Sub 39 39 … … 49 49 End If 50 50 DateTime(year, month, day) 51 AddHours(hour)52 AddMinutes(minute)53 AddSeconds(second)51 This = AddHours(hour) 52 This = AddMinutes(minute) 53 This = AddSeconds(second) 54 54 End Sub 55 55 … … 61 61 Sub DateTime(year As Long, month As Long, day As Long, hour As Long, minute As Long, second As Long, millisecond As Long) 62 62 DateTime(year, month, day, hour, minute, second) 63 AddMilliseconds(millisecond)63 This = AddMilliseconds(millisecond) 64 64 End Sub 65 65 … … 84 84 Sub ~DateTime() 85 85 End Sub 86 87 Function Operator+ (ByRef value As TimeSpan) As DateTime 88 Dim date As DateTime(Ticks + value.Ticks) 89 Return date 90 End Function 91 92 Function Operator- (ByRef value As DateTime) As TimeSpan 93 Return TimeSpan.FromTicks(Ticks - value.Ticks) 94 End Function 95 96 Function Operator- (ByRef value As TimeSpan) As DateTime 97 Dim date As DateTime(Ticks - value.Ticks) 98 Return date 99 End Function 86 100 87 101 Function Operator == (ByRef value As DateTime) As Boolean … … 131 145 132 146 Function Millisecond() As Long 133 Return (Ticks \ 10000Mod 1000) As Long147 Return (Ticks \ TimeSpan.TicksPerMillisecond Mod 1000) As Long 134 148 End Function 135 149 136 150 Function Second() As Long 137 Return (Ticks \ 10000000Mod 60) As Long151 Return (Ticks \ TimeSpan.TicksPerSecond Mod 60) As Long 138 152 End Function 139 153 140 154 Function Minute() As Long 141 Return (Ticks \ 600000000Mod 60) As Long155 Return (Ticks \ TimeSpan.TicksPerMinute Mod 60) As Long 142 156 End Function 143 157 144 158 Function Hour() As Long 145 Return (Ticks \ 36000000000Mod 24) As Long159 Return (Ticks \ TimeSpan.TicksPerHour Mod 24) As Long 146 160 End Function 147 161 … … 177 191 End Function 178 192 179 Function DayOfWeek() As DayOfWeek193 Function DayOfWeek() As Long 180 194 Return totalDays() Mod 7 - 1 181 195 End Function … … 238 252 End Function 239 253 240 Sub AddTicks(value As Int64) 254 Function Add(ByRef value As TimeSpan) As DateTime 255 Return This + value 256 End Function 257 258 Function AddTicks(value As Int64) As DateTime 241 259 Dim ticks As Int64 242 260 ticks = Ticks 243 If (ticks > DateTime.MaxValue - value) Or (ticks < DateTime.MinValue - value) Then261 If (ticks > MaxValue - value) Or (ticks < MinValue - value) Then 244 262 'ArgumentOutOfRangeException 245 263 debug 246 264 End If 247 Ticks = ticks + value 248 End Sub 249 250 Sub AddMilliseconds(value As Double) 251 AddTicks((value * 10000) As Int64) 252 End Sub 253 254 Sub AddSeconds(value As Double) 255 AddTicks((value * 10000000) As Int64) 256 End Sub 257 258 Sub AddMinutes(value As Double) 259 AddTicks((value * 600000000) As Int64) 260 End Sub 261 262 Sub AddHours(value As Double) 263 AddTicks((value * 36000000000) As Int64) 264 End Sub 265 266 Sub AddDays(value As Double) 267 AddTicks((value * 864000000000) As Int64) 268 End Sub 269 270 Sub AddYears(value As Double) 265 266 AddTicks.Ticks = ticks + value 267 AddTicks.Kind = Kind 268 End Function 269 270 Function AddMilliseconds(value As Double) As DateTime 271 Return AddTicks((value * TimeSpan.TicksPerMillisecond) As Int64) 272 End Function 273 274 Function AddSeconds(value As Double) As DateTime 275 Return AddTicks((value * TimeSpan.TicksPerSecond) As Int64) 276 End Function 277 278 Function AddMinutes(value As Double) As DateTime 279 Return AddTicks((value * TimeSpan.TicksPerMinute) As Int64) 280 End Function 281 282 Function AddHours(value As Double) As DateTime 283 Return AddTicks((value * TimeSpan.TicksPerHour) As Int64) 284 End Function 285 286 Function AddDays(value As Double) As DateTime 287 Return AddTicks((value * TimeSpan.TicksPerDay) As Int64) 288 End Function 289 290 Function AddYears(value As Double) As DateTime 271 291 Dim year As Long 272 292 Dim intValue As Long 293 Dim ticks As Int64 273 294 year = Year 274 295 intValue = Int(value) 275 AddTicks(intValue * 315360000000000 + 864000000000 * ((year Mod 4 + intValue) \ 4 - (year Mod 100 + intValue) \ 100 + (year Mod 400 + intValue) \ 400)) 296 ticks = Ticks + intValue * 315360000000000 + 864000000000 * ((year Mod 4 + intValue) \ 4 - (year Mod 100 + intValue) \ 100 + (year Mod 400 + intValue) \ 400) 297 276 298 If value < 0 Then 277 299 If (year Mod 4 + intValue <= 0 And year Mod 100 > 4) Or (year Mod 400 <= 4) Then 278 AddTicks(-864000000000)300 ticks -= 864000000000 279 301 End If 280 302 End If 281 282 303 If IsLeapYear(year) = TRUE Then 283 AddTicks(((value - intValue) * 316224000000000) As Int64) 284 Else 285 AddTicks(((value - intValue) * 315360000000000) As Int64) 286 End If 287 End Sub 304 ticks += (value - intValue) * 316224000000000 305 Else 306 ticks += (value - intValue) * 315360000000000 307 End If 308 309 AddYears.Ticks = ticks 310 AddYears.Kind = Kind 311 End Function 312 313 Function Subtract(ByRef value As DateTime) As TimeSpan 314 Return This - value 315 End Function 316 317 Function Subtract(ByRef value As TimeSpan) As DateTime 318 Return This - value 319 End Function 288 320 289 321 Static Function DaysInMonth(year As Long, month As Long) As Long … … 430 462 431 463 Function totalDays() As Long 432 Return (Ticks \ 864000000000) As Long464 Return (Ticks \ TimeSpan.TicksPerDay) As Long 433 465 End Function 434 466
Note:
See TracChangeset
for help on using the changeset viewer.