 |
Changeset 2983
- Timestamp:
- 12/08/07 15:08:57
(1 year ago)
- Author:
- kris
- Message:
* shortened a couple of overly long names (in new package)
* gave TimeOfDay? methods the same names as TimeSpan? ones
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2978 |
r2983 |
|
| 294 | 294 | failedConnectCount, failedReceiveCount, failedSendCount, errorCount)); |
|---|
| 295 | 295 | |
|---|
| 296 | | log.info(sprint("Total time: {0} ms", cast(uint) (Clock.now - start).milliseconds)); |
|---|
| | 296 | log.info(sprint("Total time: {0} ms", cast(uint) (Clock.now - start).millis)); |
|---|
| 297 | 297 | |
|---|
| 298 | 298 | clientThread.join(); |
|---|
| r2978 |
r2983 |
|
| 1102 | 1102 | static Time convert (FILETIME time) |
|---|
| 1103 | 1103 | { |
|---|
| 1104 | | return Time.epoch1601 + TimeSpan(*cast(long*) &time); |
|---|
| | 1104 | return Time (TimeSpan.Epoch1601 + *cast(long*) &time); |
|---|
| 1105 | 1105 | } |
|---|
| 1106 | 1106 | |
|---|
| … | … | |
| 1421 | 1421 | { |
|---|
| 1422 | 1422 | return Time.epoch1970 + |
|---|
| 1423 | | TimeSpan.seconds(tv.tv_sec) + |
|---|
| 1424 | | TimeSpan.microseconds(tv.tv_usec); |
|---|
| | 1423 | TimeSpan.seconds(tv.tv_sec) + |
|---|
| | 1424 | TimeSpan.microseconds(tv.tv_usec); |
|---|
| 1425 | 1425 | } |
|---|
| 1426 | 1426 | |
|---|
| r2903 |
r2983 |
|
| 336 | 336 | { |
|---|
| 337 | 337 | tv.tv_sec = cast(typeof(tv.tv_sec)) interval.seconds; |
|---|
| 338 | | tv.tv_usec = cast(typeof(tv.tv_usec)) (interval.microseconds % 1_000_000); |
|---|
| | 338 | tv.tv_usec = cast(typeof(tv.tv_usec)) (interval.micros % 1_000_000); |
|---|
| 339 | 339 | return tv; |
|---|
| 340 | 340 | } |
|---|
| r2900 |
r2983 |
|
| 358 | 358 | public int select(TimeSpan timeout) |
|---|
| 359 | 359 | { |
|---|
| 360 | | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| | 360 | int to = (timeout != TimeSpan.max ? cast(int) timeout.millis : -1); |
|---|
| 361 | 361 | |
|---|
| 362 | 362 | while (true) |
|---|
| r2913 |
r2983 |
|
| 311 | 311 | public int select(TimeSpan timeout) |
|---|
| 312 | 312 | { |
|---|
| 313 | | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| | 313 | int to = (timeout != TimeSpan.max ? cast(int) timeout.millis : -1); |
|---|
| 314 | 314 | |
|---|
| 315 | 315 | debug (selector) |
|---|
| r2900 |
r2983 |
|
| 437 | 437 | |
|---|
| 438 | 438 | debug (selector) |
|---|
| 439 | | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", timeout.milliseconds); |
|---|
| | 439 | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", timeout.millis); |
|---|
| 440 | 440 | |
|---|
| 441 | 441 | if (_readSet !is null) |
|---|
| r2978 |
r2983 |
|
| 1401 | 1401 | timeval tv; |
|---|
| 1402 | 1402 | tv.tv_sec = cast(uint) time.seconds; |
|---|
| 1403 | | tv.tv_usec = cast(uint) time.microseconds % 1_000_000; |
|---|
| | 1403 | tv.tv_usec = cast(uint) time.micros % 1_000_000; |
|---|
| 1404 | 1404 | return tv; |
|---|
| 1405 | 1405 | } |
|---|
| r2978 |
r2983 |
|
| 288 | 288 | QueuedEntry* prev, |
|---|
| 289 | 289 | next; |
|---|
| 290 | | Time time; |
|---|
| | 290 | Time time; |
|---|
| 291 | 291 | V value; |
|---|
| 292 | 292 | |
|---|
| r2978 |
r2983 |
|
| 1055 | 1055 | |
|---|
| 1056 | 1056 | // set a 500ms timeout for read operations |
|---|
| 1057 | | conduit_.setTimeout (TimeSpan.milliseconds(500)); |
|---|
| | 1057 | conduit_.setTimeout (TimeSpan.millis(500)); |
|---|
| 1058 | 1058 | |
|---|
| 1059 | 1059 | // open a connection to this server |
|---|
| r2978 |
r2983 |
|
| 36 | 36 | |
|---|
| 37 | 37 | /// The number of milliseconds to wait for socket communication or connection. |
|---|
| 38 | | protected TimeSpan timeout = TimeSpan.milliseconds(5000); |
|---|
| | 38 | protected TimeSpan timeout = TimeSpan.millis(5000); |
|---|
| 39 | 39 | |
|---|
| 40 | 40 | /// provided by host |
|---|
| … | … | |
| 239 | 239 | { |
|---|
| 240 | 240 | char[10] tmp; |
|---|
| 241 | | exception ("CLIENT: Unable to connect within the specified time limit (" ~ Integer.itoa(tmp, cast(uint) this.timeout.milliseconds) ~ " ms.)"); |
|---|
| | 241 | exception ("CLIENT: Unable to connect within the specified time limit (" ~ Integer.itoa(tmp, cast(uint) this.timeout.millis) ~ " ms.)"); |
|---|
| 242 | 242 | } |
|---|
| 243 | 243 | |
|---|
| r2980 |
r2983 |
|
| 367 | 367 | case 'h': // hour (12-hour clock) |
|---|
| 368 | 368 | len = parseRepeat(format, index, c); |
|---|
| 369 | | int hour = time.hour % 12; |
|---|
| | 369 | int hour = time.hours % 12; |
|---|
| 370 | 370 | if (hour is 0) |
|---|
| 371 | 371 | hour = 12; |
|---|
| … | … | |
| 374 | 374 | case 'H': // hour (24-hour clock) |
|---|
| 375 | 375 | len = parseRepeat(format, index, c); |
|---|
| 376 | | result ~= formatInt (tmp, time.hour, len); |
|---|
| | 376 | result ~= formatInt (tmp, time.hours, len); |
|---|
| 377 | 377 | break; |
|---|
| 378 | 378 | case 'm': // minute |
|---|
| 379 | 379 | len = parseRepeat(format, index, c); |
|---|
| 380 | | result ~= formatInt (tmp, time.minute, len); |
|---|
| | 380 | result ~= formatInt (tmp, time.minutes, len); |
|---|
| 381 | 381 | break; |
|---|
| 382 | 382 | case 's': // second |
|---|
| 383 | 383 | len = parseRepeat(format, index, c); |
|---|
| 384 | | result ~= formatInt (tmp, time.second, len); |
|---|
| | 384 | result ~= formatInt (tmp, time.seconds, len); |
|---|
| 385 | 385 | break; |
|---|
| 386 | 386 | case 't': // AM/PM |
|---|
| … | … | |
| 388 | 388 | if (len is 1) |
|---|
| 389 | 389 | { |
|---|
| 390 | | if (time.hour < 12) |
|---|
| | 390 | if (time.hours < 12) |
|---|
| 391 | 391 | { |
|---|
| 392 | 392 | if (dtf.amDesignator.length != 0) |
|---|
| … | … | |
| 400 | 400 | } |
|---|
| 401 | 401 | else |
|---|
| 402 | | result ~= (time.hour < 12) ? dtf.amDesignator : dtf.pmDesignator; |
|---|
| | 402 | result ~= (time.hours < 12) ? dtf.amDesignator : dtf.pmDesignator; |
|---|
| 403 | 403 | break; |
|---|
| 404 | 404 | case 'z': // timezone offset |
|---|
| r2978 |
r2983 |
|
| 133 | 133 | //Due to dmd bug, this doesn't compile |
|---|
| 134 | 134 | //TimeSpan result = TimeSpan.hours(hour) + TimeSpan.minutes(minute); |
|---|
| 135 | | TimeSpan result = TimeSpan(TimeSpan.hour.ticks * hour + TimeSpan.minute.ticks * minute); |
|---|
| | 135 | TimeSpan result = TimeSpan(TimeSpan.TicksPerHour * hour + TimeSpan.TicksPerMinute * minute); |
|---|
| 136 | 136 | if (sign) |
|---|
| 137 | 137 | result = -result; |
|---|
| r2978 |
r2983 |
|
| 133 | 133 | package static Time convert (FILETIME time) |
|---|
| 134 | 134 | { |
|---|
| 135 | | auto t = *cast(long*)&time; |
|---|
| | 135 | auto t = *cast(long*) &time; |
|---|
| 136 | 136 | t *= 100 / TimeSpan.NanosecondsPerTick; |
|---|
| 137 | 137 | return Time.epoch1601 + TimeSpan(t); |
|---|
| … | … | |
| 241 | 241 | return Time.epoch1970 + |
|---|
| 242 | 242 | TimeSpan.seconds(seconds) + |
|---|
| 243 | | TimeSpan.milliseconds(date.ms); |
|---|
| | 243 | TimeSpan.millis(date.ms); |
|---|
| 244 | 244 | } |
|---|
| 245 | 245 | |
|---|
| … | … | |
| 254 | 254 | return Time.epoch1970 + |
|---|
| 255 | 255 | TimeSpan.seconds(tv.tv_sec) + |
|---|
| 256 | | TimeSpan.microseconds(tv.tv_usec); |
|---|
| | 256 | TimeSpan.micros(tv.tv_usec); |
|---|
| 257 | 257 | } |
|---|
| 258 | 258 | |
|---|
| … | … | |
| 270 | 270 | assert (span >= TimeSpan.zero); |
|---|
| 271 | 271 | tv.tv_sec = span.seconds; |
|---|
| 272 | | tv.tv_usec = span.microseconds % 1_000_000L; |
|---|
| | 272 | tv.tv_usec = span.micros % 1_000_000L; |
|---|
| 273 | 273 | return tv; |
|---|
| 274 | 274 | } |
|---|
| r2980 |
r2983 |
|
| 41 | 41 | private long ticks_; |
|---|
| 42 | 42 | |
|---|
| | 43 | private enum : long |
|---|
| | 44 | { |
|---|
| | 45 | maximum = (TimeSpan.DaysPer400Years * 25 - 366) * TimeSpan.TicksPerDay - 1, |
|---|
| | 46 | minimum = -((TimeSpan.DaysPer400Years * 25 - 366) * TimeSpan.TicksPerDay - 1), |
|---|
| | 47 | } |
|---|
| | 48 | |
|---|
| 43 | 49 | /// Represents the smallest and largest Time value. |
|---|
| 44 | | public static const Time epoch = {0}, |
|---|
| 45 | | max = {(TimeSpan.DaysPer400Years * 25 - 366) * TimeSpan.TicksPerDay - 1}, |
|---|
| 46 | | min = {-((TimeSpan.DaysPer400Years * 25 - 366) * TimeSpan.TicksPerDay - 1)}, |
|---|
| 47 | | epoch1601 = {TimeSpan.DaysPer400Years * 4 * TimeSpan.TicksPerDay}, |
|---|
| 48 | | epoch1970 = {TimeSpan.DaysPer400Years * 4 * TimeSpan.TicksPerDay + TimeSpan.TicksPerSecond * 11644473600L}; |
|---|
| | 50 | static const Time epoch = {0}, |
|---|
| | 51 | min = {minimum}, |
|---|
| | 52 | max = {maximum}, |
|---|
| | 53 | epoch1601 = {TimeSpan.Epoch1601}, |
|---|
| | 54 | epoch1970 = {TimeSpan.Epoch1970}; |
|---|
| 49 | 55 | |
|---|
| 50 | 56 | /********************************************************************** |
|---|
| … | … | |
| 86 | 92 | if (ticks_ < t.ticks_) |
|---|
| 87 | 93 | return -1; |
|---|
| | 94 | |
|---|
| 88 | 95 | if (ticks_ > t.ticks_) |
|---|
| 89 | 96 | return 1; |
|---|
| | 97 | |
|---|
| 90 | 98 | return 0; |
|---|
| 91 | 99 | } |
|---|
| … | … | |
| 183 | 191 | Time date () |
|---|
| 184 | 192 | { |
|---|
| 185 | | return Time (ticks_ - (ticks_ % TimeSpan.day.ticks)); |
|---|
| 186 | | } |
|---|
| 187 | | |
|---|
| 188 | | /********************************************************************** |
|---|
| 189 | | |
|---|
| 190 | | $(I Property.) Retrieves the equivalent TimeSpan. |
|---|
| 191 | | |
|---|
| 192 | | Returns: A TimeSpan representing this Time. |
|---|
| 193 | | |
|---|
| 194 | | **********************************************************************/ |
|---|
| 195 | | |
|---|
| 196 | | TimeSpan span () |
|---|
| 197 | | { |
|---|
| 198 | | return TimeSpan (ticks_); |
|---|
| | 193 | return Time (ticks_ - (ticks_ % TimeSpan.TicksPerDay)); |
|---|
| 199 | 194 | } |
|---|
| 200 | 195 | |
|---|
| … | … | |
| 211 | 206 | { |
|---|
| 212 | 207 | return TimeOfDay (ticks_); |
|---|
| | 208 | } |
|---|
| | 209 | |
|---|
| | 210 | /********************************************************************** |
|---|
| | 211 | |
|---|
| | 212 | $(I Property.) Retrieves the equivalent TimeSpan. |
|---|
| | 213 | |
|---|
| | 214 | Returns: A TimeSpan representing this Time. |
|---|
| | 215 | |
|---|
| | 216 | **********************************************************************/ |
|---|
| | 217 | |
|---|
| | 218 | TimeSpan span () |
|---|
| | 219 | { |
|---|
| | 220 | return TimeSpan (ticks_); |
|---|
| 213 | 221 | } |
|---|
| 214 | 222 | } |
|---|
| … | … | |
| 235 | 243 | { |
|---|
| 236 | 244 | auto c = foo(); |
|---|
| 237 | | auto h = c.time.minute; |
|---|
| | 245 | auto h = c.time.minutes; |
|---|
| 238 | 246 | Stdout (c.ticks).newline; |
|---|
| 239 | 247 | } |
|---|
| r2980 |
r2983 |
|
| 27 | 27 | * |
|---|
| 28 | 28 | * Time start = Clock.now; |
|---|
| 29 | | * Thread.sleep(TimeSpan.milliseconds(150).interval); |
|---|
| | 29 | * Thread.sleep(TimeSpan.millis(150).interval); |
|---|
| 30 | 30 | * Stdout.format("slept for {} ms", |
|---|
| 31 | | * (start - Clock.now).milliseconds).newline; |
|---|
| | 31 | * (start - Clock.now).millis).newline; |
|---|
| 32 | 32 | * ------------------- |
|---|
| 33 | 33 | * See_Also: tango.core.Thread, tango.time.Time, tango.time.Clock |
|---|
| … | … | |
| 44 | 44 | enum : long |
|---|
| 45 | 45 | { |
|---|
| | 46 | /// basic tick values |
|---|
| 46 | 47 | NanosecondsPerTick = 100, |
|---|
| 47 | 48 | TicksPerMicrosecond = 1000 / NanosecondsPerTick, |
|---|
| … | … | |
| 52 | 53 | TicksPerDay = 24 * TicksPerHour, |
|---|
| 53 | 54 | |
|---|
| | 55 | // millisecond counts |
|---|
| 54 | 56 | MillisPerSecond = 1000, |
|---|
| 55 | 57 | MillisPerMinute = MillisPerSecond * 60, |
|---|
| … | … | |
| 57 | 59 | MillisPerDay = MillisPerHour * 24, |
|---|
| 58 | 60 | |
|---|
| | 61 | /// day counts |
|---|
| 59 | 62 | DaysPerYear = 365, |
|---|
| 60 | 63 | DaysPer4Years = DaysPerYear * 4 + 1, |
|---|
| 61 | 64 | DaysPer100Years = DaysPer4Years * 25 - 1, |
|---|
| 62 | 65 | DaysPer400Years = DaysPer100Years * 4 + 1, |
|---|
| | 66 | |
|---|
| | 67 | // epoch counts |
|---|
| | 68 | Epoch1601 = DaysPer400Years * 4 * TicksPerDay, |
|---|
| | 69 | Epoch1970 = Epoch1601 + TicksPerSecond * 11644473600L, |
|---|
| | 70 | } |
|---|
| | 71 | /+ |
|---|
| | 72 | enum Tick : long |
|---|
| | 73 | { |
|---|
| | 74 | Micro = TicksPerMicrosecond, |
|---|
| | 75 | Milli = TicksPerMillisecond, |
|---|
| | 76 | Second = TicksPerSecond, |
|---|
| | 77 | Minute = TicksPerMinute, |
|---|
| | 78 | Hour = TicksPerHour, |
|---|
| | 79 | Day = TicksPerDay |
|---|
| | 80 | } |
|---|
| | 81 | |
|---|
| | 82 | enum Milli : long |
|---|
| | 83 | { |
|---|
| | 84 | Second = 1000, |
|---|
| | 85 | Minute = Second * 60, |
|---|
| | 86 | Hour = Minute * 60, |
|---|
| | 87 | Day = Hour * 24 |
|---|
| | 88 | } |
|---|
| | 89 | |
|---|
| | 90 | enum Day : long |
|---|
| | 91 | { |
|---|
| | 92 | Year = 365, |
|---|
| | 93 | Year4 = Year * 4 + 1, |
|---|
| | 94 | Year100 = Year4 * 25 - 1, |
|---|
| | 95 | Year400 = Year100 * 4 + 1 |
|---|
| 63 | 96 | } |
|---|
| 64 | 97 | |
|---|
| … | … | |
| 67 | 100 | * measurement of the same name. |
|---|
| 68 | 101 | */ |
|---|
| | 102 | |
|---|
| | 103 | // NOTE: const is not manifest-constant, so the use of these makes |
|---|
| | 104 | // for less efficient codegen. I've removed them for now |
|---|
| 69 | 105 | static const TimeSpan microsecond = {TicksPerMicrosecond}, |
|---|
| 70 | 106 | millisecond = {TicksPerMillisecond}, |
|---|
| … | … | |
| 73 | 109 | hour = {TicksPerHour}, |
|---|
| 74 | 110 | day = {TicksPerDay}; |
|---|
| 75 | | |
|---|
| 76 | | /** |
|---|
| 77 | | * Alias for microsecond |
|---|
| 78 | | */ |
|---|
| 79 | | alias microsecond us; |
|---|
| 80 | | |
|---|
| 81 | | /** |
|---|
| 82 | | * Alias for millisecond |
|---|
| 83 | | */ |
|---|
| 84 | | alias millisecond ms; |
|---|
| 85 | 111 | |
|---|
| 86 | 112 | // |
|---|
| … | … | |
| 93 | 119 | fourHundredYears = {DaysPer400Years * TicksPerDay}; |
|---|
| 94 | 120 | |
|---|
| | 121 | +/ |
|---|
| | 122 | |
|---|
| 95 | 123 | /** |
|---|
| 96 | 124 | * Minimum TimeSpan |
|---|
| 97 | 125 | */ |
|---|
| 98 | | static const TimeSpan min = {long.min}; |
|---|
| | 126 | static const TimeSpan min = {long.min}; |
|---|
| 99 | 127 | |
|---|
| 100 | 128 | /** |
|---|
| 101 | 129 | * Maximum TimeSpan |
|---|
| 102 | 130 | */ |
|---|
| 103 | | static const TimeSpan max = {long.max}; |
|---|
| | 131 | static const TimeSpan max = {long.max}; |
|---|
| 104 | 132 | |
|---|
| 105 | 133 | /** |
|---|
| … | … | |
| 131 | 159 | if (ticks_ < t.ticks_) |
|---|
| 132 | 160 | return -1; |
|---|
| | 161 | |
|---|
| 133 | 162 | if (ticks_ > t.ticks_) |
|---|
| 134 | 163 | return 1; |
|---|
| | 164 | |
|---|
| 135 | 165 | return 0; |
|---|
| 136 | 166 | } |
|---|
| … | … | |
| 271 | 301 | * Returns: The number of nanoseconds that this TimeSpan represents. |
|---|
| 272 | 302 | */ |
|---|
| 273 | | long nanoseconds() |
|---|
| | 303 | long nanos() |
|---|
| 274 | 304 | { |
|---|
| 275 | 305 | return ticks_ * NanosecondsPerTick; |
|---|
| … | … | |
| 281 | 311 | * Returns: The number of microseconds that this TimeSpan represents. |
|---|
| 282 | 312 | */ |
|---|
| 283 | | long microseconds() |
|---|
| | 313 | long micros() |
|---|
| 284 | 314 | { |
|---|
| 285 | 315 | return ticks_ / TicksPerMicrosecond; |
|---|
| … | … | |
| 291 | 321 | * Returns: The number of milliseconds that this TimeSpan represents. |
|---|
| 292 | 322 | */ |
|---|
| 293 | | long milliseconds() |
|---|
| | 323 | long millis() |
|---|
| 294 | 324 | { |
|---|
| 295 | 325 | return ticks_ / TicksPerMillisecond; |
|---|
| … | … | |
| 323 | 353 | long hours() |
|---|
| 324 | 354 | { |
|---|
| 325 | | return ticks_ / TicksPerHour; |
|---|
| | 355 | return ticks_ / TicksPerHour; |
|---|
| 326 | 356 | } |
|---|
| 327 | 357 | |
|---|
| … | … | |
| 333 | 363 | long days() |
|---|
| 334 | 364 | { |
|---|
| 335 | | return ticks_ / TicksPerDay; |
|---|
| | 365 | return ticks_ / TicksPerDay; |
|---|
| 336 | 366 | } |
|---|
| 337 | 367 | |
|---|
| … | … | |
| 347 | 377 | double interval() |
|---|
| 348 | 378 | { |
|---|
| 349 | | return (cast(double)ticks_) / TicksPerSecond; |
|---|
| | 379 | return (cast(double) ticks_) / TicksPerSecond; |
|---|
| 350 | 380 | } |
|---|
| 351 | 381 | |
|---|
| … | … | |
| 369 | 399 | * Returns: A TimeSpan representing the given number of nanoseconds. |
|---|
| 370 | 400 | */ |
|---|
| 371 | | static TimeSpan nanoseconds(long value) |
|---|
| | 401 | static TimeSpan nanos(long value) |
|---|
| 372 | 402 | { |
|---|
| 373 | 403 | return TimeSpan(value / NanosecondsPerTick); |
|---|
| … | … | |
| 380 | 410 | * Returns: A TimeSpan representing the given number of microseconds. |
|---|
| 381 | 411 | */ |
|---|
| 382 | | static TimeSpan microseconds(long value) |
|---|
| | 412 | static TimeSpan micros(long value) |
|---|
| 383 | 413 | { |
|---|
| 384 | 414 | return TimeSpan(TicksPerMicrosecond * value); |
|---|
| … | … | |
| 391 | 421 | * Returns: A TimeSpan representing the given number of milliseconds. |
|---|
| 392 | 422 | */ |
|---|
| 393 | | static TimeSpan milliseconds(long value) |
|---|
| | 423 | static TimeSpan millis(long value) |
|---|
| 394 | 424 | { |
|---|
| 395 | 425 | return TimeSpan(TicksPerMillisecond * value); |
|---|
| … | … | |
| 466 | 496 | private long ticks; |
|---|
| 467 | 497 | |
|---|
| 468 | | /** |
|---|
| 469 | | * Alias for microsecond |
|---|
| 470 | | */ |
|---|
| 471 | | alias microsecond us; |
|---|
| 472 | | /** |
|---|
| 473 | | * Alias for millisecond |
|---|
| 474 | | */ |
|---|
| 475 | | alias millisecond ms; |
|---|
| 476 | | |
|---|
| 477 | 498 | /********************************************************************** |
|---|
| 478 | 499 | |
|---|
| 479 | | $(I Property.) Retrieves the _hour component of the date. |
|---|
| | 500 | $(I Property.) Retrieves the _hour component of the time. |
|---|
| 480 | 501 | |
|---|
| 481 | 502 | Returns: The _hour. |
|---|
| … | … | |
| 483 | 504 | **********************************************************************/ |
|---|
| 484 | 505 | |
|---|
| 485 | | int hour () |
|---|
| | 506 | int hours () |
|---|
| 486 | 507 | { |
|---|
| 487 | 508 | return cast(int) ((ticks / TimeSpan.TicksPerHour) % 24); |
|---|
| … | … | |
| 490 | 511 | /********************************************************************** |
|---|
| 491 | 512 | |
|---|
| 492 | | $(I Property.) Retrieves the _minute component of the date. |
|---|
| | 513 | $(I Property.) Retrieves the _minute component of the time. |
|---|
| 493 | 514 | |
|---|
| 494 | 515 | Returns: The _minute. |
|---|
| … | … | |
| 496 | 517 | **********************************************************************/ |
|---|
| 497 | 518 | |
|---|
| 498 | | int minute () |
|---|
| | 519 | int minutes () |
|---|
| 499 | 520 | { |
|---|
| 500 | 521 | return cast(int) ((ticks / TimeSpan.TicksPerMinute) % 60); |
|---|
| … | … | |
| 503 | 524 | /********************************************************************** |
|---|
| 504 | 525 | |
|---|
| 505 | | $(I Property.) Retrieves the _second component of the date. |
|---|
| | 526 | $(I Property.) Retrieves the _second component of the time. |
|---|
| 506 | 527 | |
|---|
| 507 | 528 | Returns: The _second. |
|---|
| … | … | |
| 509 | 530 | **********************************************************************/ |
|---|
| 510 | 531 | |
|---|
| 511 | | int second () |
|---|
| | 532 | int seconds () |
|---|
| 512 | 533 | { |
|---|
| 513 | 534 | return cast(int) ((ticks / TimeSpan.TicksPerSecond) % 60); |
|---|
| … | … | |
| 517 | 538 | |
|---|
| 518 | 539 | $(I Property.) Retrieves the _millisecond component of the |
|---|
| 519 | | date. |
|---|
| 520 | | |
|---|
| 521 | | Returns: The _millisecond. |
|---|
| | 540 | time. |
|---|
| | 541 | |
|---|
| | 542 | Returns: The _milliseconds. |
|---|
| 522 | 543 | |
|---|
| 523 | 544 | **********************************************************************/ |
|---|
| 524 | 545 | |
|---|
| 525 | | int millisecond () |
|---|
| | 546 | int millis () |
|---|
| 526 | 547 | { |
|---|
| 527 | 548 | return cast(int) ((ticks / TimeSpan.TicksPerMillisecond) % 1000); |
|---|
| … | … | |
| 531 | 552 | |
|---|
| 532 | 553 | $(I Property.) Retrieves the _microsecond component of the |
|---|
| 533 | | date. |
|---|
| 534 | | |
|---|
| 535 | | Returns: The _microsecond. |
|---|
| | 554 | time. |
|---|
| | 555 | |
|---|
| | 556 | Returns: The _microseconds. |
|---|
| 536 | 557 | |
|---|
| 537 | 558 | **********************************************************************/ |
|---|
| 538 | 559 | |
|---|
| 539 | | int microsecond () |
|---|
| | 560 | int micros () |
|---|
| 540 | 561 | { |
|---|
| 541 | 562 | return cast(int) ((ticks / TimeSpan.TicksPerMicrosecond) % 1000); |
|---|
| … | … | |
| 544 | 565 | |
|---|
| 545 | 566 | |
|---|
| 546 | | |
|---|
| 547 | | unittest |
|---|
| | 567 | debug (UnitTest) |
|---|
| 548 | 568 | { |
|---|
| 549 | | assert(TimeSpan.ms > TimeSpan.us); |
|---|
| 550 | | assert(TimeSpan.year > TimeSpan.us); |
|---|
| 551 | | assert(TimeSpan.year > TimeSpan.day); |
|---|
| 552 | | assert(TimeSpan.zero > TimeSpan.min); |
|---|
| 553 | | assert(TimeSpan.max > TimeSpan.zero); |
|---|
| 554 | | assert(TimeSpan.max > TimeSpan.min); |
|---|
| 555 | | assert(TimeSpan.zero >= TimeSpan.zero); |
|---|
| 556 | | assert(TimeSpan.zero <= TimeSpan.zero); |
|---|
| 557 | | assert(TimeSpan.max >= TimeSpan.max); |
|---|
| 558 | | assert(TimeSpan.max <= TimeSpan.max); |
|---|
| 559 | | assert(TimeSpan.min >= TimeSpan.min); |
|---|
| 560 | | assert(TimeSpan.min <= TimeSpan.min); |
|---|
| | 569 | unittest |
|---|
| | 570 | { |
|---|
| | 571 | assert(TimeSpan.zero > TimeSpan.min); |
|---|
| | 572 | assert(TimeSpan.max > TimeSpan.zero); |
|---|
| | 573 | assert(TimeSpan.max > TimeSpan.min); |
|---|
| | 574 | assert(TimeSpan.zero >= TimeSpan.zero); |
|---|
| | 575 | assert(TimeSpan.zero <= TimeSpan.zero); |
|---|
| | 576 | assert(TimeSpan.max >= TimeSpan.max); |
|---|
| | 577 | assert(TimeSpan.max <= TimeSpan.max); |
|---|
| | 578 | assert(TimeSpan.min >= TimeSpan.min); |
|---|
| | 579 | assert(TimeSpan.min <= TimeSpan.min); |
|---|
| | 580 | |
|---|
| | 581 | assert (TimeSpan.micros(999).micros is 999); |
|---|
| | 582 | assert (TimeSpan.micros(1999).micros is 1999); |
|---|
| | 583 | assert (TimeSpan.seconds(50).seconds is 50); |
|---|
| | 584 | assert (TimeSpan.seconds(5000).seconds is 5000); |
|---|
| | 585 | assert (TimeSpan.minutes(50).minutes is 50); |
|---|
| | 586 | assert (TimeSpan.minutes(5000).minutes is 5000); |
|---|
| | 587 | assert (TimeSpan.hours(23).hours is 23); |
|---|
| | 588 | assert (TimeSpan.hours(5000).hours is 5000); |
|---|
| | 589 | assert (TimeSpan.days(6).days is 6); |
|---|
| | 590 | assert (TimeSpan.days(5000).days is 5000); |
|---|
| | 591 | |
|---|
| | 592 | assert (TimeSpan.micros(999).time.micros is 999); |
|---|
| | 593 | assert (TimeSpan.micros(1999).time.micros is 999); |
|---|
| | 594 | assert (TimeSpan.seconds(50).time.seconds is 50); |
|---|
| | 595 | assert (TimeSpan.seconds(5000).time.seconds is 5000 % 60); |
|---|
| | 596 | assert (TimeSpan.minutes(50).time.minutes is 50); |
|---|
| | 597 | assert (TimeSpan.minutes(5000).time.minutes is 5000 % 60); |
|---|
| | 598 | assert (TimeSpan.hours(23).time.hours is 23); |
|---|
| | 599 | assert (TimeSpan.hours(5000).time.hours is 5000 % 24); |
|---|
| | 600 | } |
|---|
| 561 | 601 | } |
|---|
| 562 | 602 | |
|---|
| … | … | |
| 567 | 607 | { |
|---|
| 568 | 608 | auto t = TimeSpan(1); |
|---|
| 569 | | auto h = t.hour; |
|---|
| 570 | | auto m = t.time.minute; |
|---|
| | 609 | auto h = t.hours; |
|---|
| | 610 | auto m = t.time.minutes; |
|---|
| 571 | 611 | } |
|---|
| 572 | 612 | } |
|---|
| r2978 |
r2983 |
|
| 231 | 231 | |
|---|
| 232 | 232 | auto seconds = mktime (&t); |
|---|
| 233 | | return Time.epoch1970 + TimeSpan.seconds(seconds) + TimeSpan.milliseconds(date.ms); |
|---|
| | 233 | return Time.epoch1970 + TimeSpan.seconds(seconds) |
|---|
| | 234 | + TimeSpan.millis(date.ms); |
|---|
| 234 | 235 | } |
|---|
| 235 | 236 | } |
|---|
| … | … | |
| 241 | 242 | static Time toLocal (Time utc) |
|---|
| 242 | 243 | { |
|---|
| 243 | | auto mod = utc.ticks % TimeSpan.ms.ticks; |
|---|
| | 244 | auto mod = utc.ticks % TimeSpan.TicksPerMillisecond; |
|---|
| 244 | 245 | return Clock.fromDate(toDate(utc)) + TimeSpan(mod); |
|---|
| 245 | 246 | } |
|---|
| … | … | |
| 251 | 252 | static Time toUtc (Time wall) |
|---|
| 252 | 253 | { |
|---|
| 253 | | auto mod = wall.ticks % TimeSpan.ms.ticks; |
|---|
| | 254 | auto mod = wall.ticks % TimeSpan.TicksPerMillisecond; |
|---|
| 254 | 255 | return fromDate(Clock.toDate(wall)) + TimeSpan(mod); |
|---|
| 255 | 256 | } |
|---|
| r2978 |
r2983 |
|
| 72 | 72 | override Time getTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) |
|---|
| 73 | 73 | { |
|---|
| 74 | | return Time (getDateTicks(year, month, day) + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| | 74 | return Time (getDateTicks(year, month, day) + getTimeTicks(hour, minute, second)) + TimeSpan.millis(millisecond); |
|---|
| 75 | 75 | } |
|---|
| 76 | 76 | |
|---|
| … | … | |
| 82 | 82 | override DayOfWeek getDayOfWeek(Time time) |
|---|
| 83 | 83 | { |
|---|
| 84 | | return cast(DayOfWeek)((time.ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| | 84 | return cast(DayOfWeek)((time.ticks / TimeSpan.TicksPerDay + 1) % 7); |
|---|
| 85 | 85 | } |
|---|
| 86 | 86 | |
|---|
| … | … | |
| 228 | 228 | package static void splitDate (long ticks, out int year, out int month, out int day, out int dayOfYear) |
|---|
| 229 | 229 | { |
|---|
| 230 | | int numDays = cast(int)(ticks / TimeSpan.day.ticks); |
|---|
| | 230 | int numDays = cast(int)(ticks / TimeSpan.TicksPerDay); |
|---|
| 231 | 231 | int whole400Years = numDays / cast(int) TimeSpan.DaysPer400Years; |
|---|
| 232 | 232 | numDays -= whole400Years * cast(int) TimeSpan.DaysPer400Years; |
|---|
| … | … | |
| 276 | 276 | int[] monthDays = isLeapYear(year, AD_ERA) ? DaysToMonthLeap : DaysToMonthCommon; |
|---|
| 277 | 277 | year--; |
|---|
| 278 | | return (year * 365 + year / 4 - year / 100 + year / 400 + monthDays[month - 1] + day - 1) * TimeSpan.day.ticks; |
|---|
| | 278 | return (year * 365 + year / 4 - year / 100 + year / 400 + monthDays[month - 1] + day - 1) * TimeSpan.TicksPerDay; |
|---|
| 279 | 279 | } |
|---|
| 280 | 280 | } |
|---|
| r2978 |
r2983 |
|
| 79 | 79 | */ |
|---|
| 80 | 80 | public override DayOfWeek getDayOfWeek(Time time) { |
|---|
| 81 | | return cast(DayOfWeek) cast(int) ((time.ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| | 81 | return cast(DayOfWeek) cast(int) ((time.ticks / TimeSpan.TicksPerDay + 1) % 7); |
|---|
| 82 | 82 | } |
|---|
| 83 | 83 | |
|---|
| … | … | |
| 91 | 91 | int yearType = getYearType(year); |
|---|
| 92 | 92 | int days = getStartOfYear(year) - DaysToOneAD; |
|---|
| 93 | | int day = cast(int)(time.ticks / TimeSpan.day.ticks) - days; |
|---|
| | 93 | int day = cast(int)(time.ticks / TimeSpan.TicksPerDay) - days; |
|---|
| 94 | 94 | int n; |
|---|
| 95 | 95 | while (n < 12 && day >= MonthDays[yearType][n + 1]) { |
|---|
| … | … | |
| 108 | 108 | int year = getYear(time); |
|---|
| 109 | 109 | int days = getStartOfYear(year) - DaysToOneAD; |
|---|
| 110 | | return (cast(int)(time.ticks / TimeSpan.day.ticks) - days) + 1; |
|---|
| | 110 | return (cast(int)(time.ticks / TimeSpan.TicksPerDay) - days) + 1; |
|---|
| 111 | 111 | } |
|---|
| 112 | 112 | |
|---|
| … | … | |
| 120 | 120 | int yearType = getYearType(year); |
|---|
| 121 | 121 | int days = getStartOfYear(year) - DaysToOneAD; |
|---|
| 122 | | int day = cast(int)(time.ticks / TimeSpan.day.ticks) - days; |
|---|
| | 122 | int day = cast(int)(time.ticks / TimeSpan.TicksPerDay) - days; |
|---|
| 123 | 123 | int n; |
|---|
| 124 | 124 | while (n < 12 && day >= MonthDays[yearType][n + 1]) { |
|---|
| … | … | |
| 135 | 135 | */ |
|---|
| 136 | 136 | public override int getYear(Time time) { |
|---|
| 137 | | int day = cast(int)(time.ticks / TimeSpan.day.ticks) + DaysToOneAD; |
|---|
| | 137 | int day = cast(int)(time.ticks / TimeSpan.TicksPerDay) + DaysToOneAD; |
|---|
| 138 | 138 | int low = minYear_, high = maxYear_; |
|---|
| 139 | 139 | // Perform a binary search. |
|---|
| … | … | |
| 282 | 282 | for (int i = 1; i <= month; i++) |
|---|
| 283 | 283 | days += MonthDays[yearType][i - 1]; |
|---|
| 284 | | return Time((days * TimeSpan.day.ticks) + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| | 284 | return Time((days * TimeSpan.TicksPerDay) + getTimeTicks(hour, minute, second)) + TimeSpan.millis(millisecond); |
|---|
| 285 | 285 | } |
|---|
| 286 | 286 | |
|---|
| r2978 |
r2983 |
|
| 44 | 44 | */ |
|---|
| 45 | 45 | public override Time getTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) { |
|---|
| 46 | | return Time((daysSinceJan1(year, month, day) - 1) * TimeSpan.day.ticks + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| | 46 | return Time((daysSinceJan1(year, month, day) - 1) * TimeSpan.TicksPerDay + getTimeTicks(hour, minute, second)) + TimeSpan.millis(millisecond); |
|---|
| 47 | 47 | } |
|---|
| 48 | 48 | |
|---|
| … | … | |
| 53 | 53 | */ |
|---|
| 54 | 54 | public override DayOfWeek getDayOfWeek(Time time) { |
|---|
| 55 | | return cast(DayOfWeek) (cast(int) (time.ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| | 55 | return cast(DayOfWeek) (cast(int) (time.ticks / TimeSpan.TicksPerDay + 1) % 7); |
|---|
| 56 | 56 | } |
|---|
| 57 | 57 | |
|---|
| r2978 |
r2983 |
|
| 153 | 153 | |
|---|
| 154 | 154 | QueryPerformanceCounter (&timerStart); |
|---|
| 155 | | multiplier = cast(double)TimeSpan.second.ticks / freq; |
|---|
| | 155 | multiplier = cast(double) TimeSpan.TicksPerSecond / freq; |
|---|
| 156 | 156 | beginTime = Clock.now; |
|---|
| 157 | 157 | |
|---|
| r2978 |
r2983 |
|
| 69 | 69 | { |
|---|
| 70 | 70 | assert (s.length > 0); |
|---|
| 71 | | long ms = time.milliseconds; |
|---|
| | 71 | long ms = time.millis; |
|---|
| 72 | 72 | |
|---|
| 73 | 73 | int len = s.length; |
|---|
Download in other formats:
|
 |