 |
Changeset 2900
- Timestamp:
- 11/20/07 17:56:55
(4 years ago)
- Author:
- schveiguy
- Message:
Updated to use new TimeSpan? struct and DateTime? for all date/time related functi
ons. THIS IS A BREAKING CHANGE.
closes #671
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2731 |
r2900 |
|
| 6 | 6 | install tango/core/Memory.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| 7 | 7 | install tango/core/Runtime.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| 8 | | install tango/core/Thread.di $INCLUDE_PREFIX/tango/core |
|---|
| | 8 | install tango/core/Thread.di $INCLUDE_PREFIX/tango/core ; \ |
|---|
| | 9 | install tango/core/TimeSpan.di $INCLUDE_PREFIX/tango/core |
|---|
| 9 | 10 | version (GNU) { |
|---|
| 10 | 11 | prebuild = $DSSS_BUILD -obj -explicit lib/common/tango/core/BitManip.d -fintfc-file=tango/core/BitManip.di ; \ |
|---|
| … | … | |
| 12 | 13 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Memory.d -fintfc-file=tango/core/Memory.di ; \ |
|---|
| 13 | 14 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Runtime.d -fintfc-file=tango/core/Runtime.di ; \ |
|---|
| 14 | | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -fintfc-file=tango/core/Thread.di |
|---|
| | 15 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -fintfc-file=tango/core/Thread.di ; \ |
|---|
| | 16 | $DSSS_BUILD -obj -explicit lib/common/tango/core/TimeSpan.d -fintfc-file=tango/core/TimeSpan.di |
|---|
| 15 | 17 | } else version (DigitalMars) { |
|---|
| 16 | 18 | prebuild = $DSSS_BUILD -obj -explicit lib/common/tango/core/BitManip.d -Hftango/core/BitManip.di ; \ |
|---|
| … | … | |
| 18 | 20 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Memory.d -Hftango/core/Memory.di ; \ |
|---|
| 19 | 21 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Runtime.d -Hftango/core/Runtime.di ; \ |
|---|
| 20 | | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -Hftango/core/Thread.di |
|---|
| | 22 | $DSSS_BUILD -obj -explicit lib/common/tango/core/Thread.d -Hftango/core/Thread.di ; \ |
|---|
| | 23 | $DSSS_BUILD -obj -explicit lib/common/tango/core/TimeSpan.d -Hftango/core/TimeSpan.di |
|---|
| 21 | 24 | } |
|---|
| 22 | 25 | |
|---|
| r2525 |
r2900 |
|
| 103 | 103 | uint closeCount = 0; |
|---|
| 104 | 104 | uint errorCount = 0; |
|---|
| 105 | | Time start = Clock.now; |
|---|
| | 105 | DateTime start = Clock.now; |
|---|
| 106 | 106 | Thread clientThread; |
|---|
| 107 | 107 | |
|---|
| … | … | |
| 113 | 113 | try |
|---|
| 114 | 114 | { |
|---|
| 115 | | Interval timeout = 1.0; // 1 sec |
|---|
| | 115 | TimeSpan timeout = TimeSpan.seconds(1); |
|---|
| 116 | 116 | InternetAddress addr = new InternetAddress(SERVER_ADDR, SERVER_PORT); |
|---|
| 117 | 117 | ServerSocket serverSocket = new ServerSocket(addr, 5); |
|---|
| … | … | |
| 294 | 294 | failedConnectCount, failedReceiveCount, failedSendCount, errorCount)); |
|---|
| 295 | 295 | |
|---|
| 296 | | log.info(sprint("Total time: {0} ms", cast(uint) ((Clock.now - start) / start.TicksPerMillisecond))); |
|---|
| | 296 | log.info(sprint("Total time: {0} ms", cast(uint) (Clock.now - start).milliseconds)); |
|---|
| 297 | 297 | |
|---|
| 298 | 298 | clientThread.join(); |
|---|
| r2465 |
r2900 |
|
| 22 | 22 | |
|---|
| 23 | 23 | // get GMT difference in minutes |
|---|
| 24 | | auto tz = cast(int) (WallClock.zone / Time.TicksPerMinute); |
|---|
| | 24 | auto tz = cast(int) WallClock.zone.minutes; |
|---|
| 25 | 25 | char sign = '+'; |
|---|
| 26 | 26 | if (tz < 0) |
|---|
| r2624 |
r2900 |
|
| 15 | 15 | public |
|---|
| 16 | 16 | { |
|---|
| 17 | | import tango.core.Type : Interval; |
|---|
| | 17 | import tango.core.TimeSpan; |
|---|
| 18 | 18 | } |
|---|
| 19 | 19 | private |
|---|
| … | … | |
| 763 | 763 | * ------------------------------------------------------------------------- |
|---|
| 764 | 764 | */ |
|---|
| 765 | | static void sleep( Interval period ) |
|---|
| | 765 | static void sleep( TimeSpan period ) |
|---|
| 766 | 766 | in |
|---|
| 767 | 767 | { |
|---|
| 768 | | assert( period * 1_000 < uint.max - 1 ); |
|---|
| | 768 | assert( period.milliseconds < uint.max - 1 ); |
|---|
| 769 | 769 | } |
|---|
| 770 | 770 | body |
|---|
| … | … | |
| 772 | 772 | version( Win32 ) |
|---|
| 773 | 773 | { |
|---|
| 774 | | Sleep( cast(uint)( period * 1_000 ) ); |
|---|
| | 774 | Sleep( cast(uint)( period.milliseconds ) ); |
|---|
| 775 | 775 | } |
|---|
| 776 | 776 | else version( Posix ) |
|---|
| … | … | |
| 779 | 779 | timespec tout = void; |
|---|
| 780 | 780 | |
|---|
| 781 | | if( tin.tv_sec.max < period ) |
|---|
| | 781 | if( tin.tv_sec.max < period.seconds ) |
|---|
| 782 | 782 | { |
|---|
| 783 | 783 | tin.tv_sec = tin.tv_sec.max; |
|---|
| … | … | |
| 786 | 786 | else |
|---|
| 787 | 787 | { |
|---|
| 788 | | tin.tv_sec = cast(typeof(tin.tv_sec)) period; |
|---|
| 789 | | tin.tv_nsec = cast(typeof(tin.tv_nsec)) ((period % 1.0) * 1_000_000_000); |
|---|
| | 788 | tin.tv_sec = cast(typeof(tin.tv_sec)) period.seconds; |
|---|
| | 789 | tin.tv_nsec = cast(typeof(tin.tv_nsec)) period.nanoseconds % 1_000_000_000; |
|---|
| 790 | 790 | } |
|---|
| 791 | 791 | |
|---|
| … | … | |
| 799 | 799 | } |
|---|
| 800 | 800 | } |
|---|
| | 801 | } |
|---|
| | 802 | |
|---|
| | 803 | /** |
|---|
| | 804 | * Floating point version. The period is in terms of seconds |
|---|
| | 805 | * |
|---|
| | 806 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 807 | * function would return with a timeout before the specified period. For |
|---|
| | 808 | * more accuracy, use the TimeSpan version. |
|---|
| | 809 | * |
|---|
| | 810 | */ |
|---|
| | 811 | static void sleep( double period ) |
|---|
| | 812 | { |
|---|
| | 813 | sleep(TimeSpan.interval(period)); |
|---|
| 801 | 814 | } |
|---|
| 802 | 815 | |
|---|
| r2863 |
r2900 |
|
| 76 | 76 | core/Runtime.o \ |
|---|
| 77 | 77 | core/Thread.o \ |
|---|
| 78 | | core/ThreadASM.o |
|---|
| | 78 | core/ThreadASM.o \ |
|---|
| | 79 | core/TimeSpan.o |
|---|
| 79 | 80 | |
|---|
| 80 | 81 | OBJ_STDC= \ |
|---|
| … | … | |
| 96 | 97 | core/Memory.html \ |
|---|
| 97 | 98 | core/Runtime.html \ |
|---|
| 98 | | core/Thread.html |
|---|
| | 99 | core/Thread.html \ |
|---|
| | 100 | core/TimeSpan.html |
|---|
| 99 | 101 | |
|---|
| 100 | 102 | ALL_DOCS= |
|---|
| r2809 |
r2900 |
|
| 10 | 10 | |
|---|
| 11 | 11 | |
|---|
| 12 | | public import tango.core.Type; |
|---|
| | 12 | public import tango.core.TimeSpan; |
|---|
| 13 | 13 | public import tango.core.Exception : SyncException; |
|---|
| 14 | 14 | public import tango.core.sync.Mutex; |
|---|
| … | … | |
| 135 | 135 | * Wait up to period seconds for a notification. |
|---|
| 136 | 136 | * |
|---|
| | 137 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 138 | * function would return with a timeout before the specified period. For |
|---|
| | 139 | * more accuracy, use the TimeSpan version. |
|---|
| | 140 | * |
|---|
| 137 | 141 | * Params: |
|---|
| 138 | 142 | * period = The number of seconds to wait. |
|---|
| … | … | |
| 144 | 148 | * SyncException on error. |
|---|
| 145 | 149 | */ |
|---|
| 146 | | bool wait( Interval period ) |
|---|
| | 150 | bool wait( double period ) |
|---|
| | 151 | { |
|---|
| | 152 | return wait(TimeSpan.interval(period)); |
|---|
| | 153 | } |
|---|
| | 154 | |
|---|
| | 155 | /** |
|---|
| | 156 | * Wait up to the specified time period for a notification. |
|---|
| | 157 | * |
|---|
| | 158 | * Params: |
|---|
| | 159 | * period = The time to wait. |
|---|
| | 160 | * |
|---|
| | 161 | * Returns: |
|---|
| | 162 | * true if notified before the timeout and false if not. |
|---|
| | 163 | * |
|---|
| | 164 | * Throws: |
|---|
| | 165 | * SyncException on error. |
|---|
| | 166 | */ |
|---|
| | 167 | bool wait( TimeSpan period ) |
|---|
| 147 | 168 | { |
|---|
| 148 | 169 | version( Win32 ) |
|---|
| 149 | 170 | { |
|---|
| 150 | | return timedWait( period < INFINITE ? |
|---|
| 151 | | cast(uint)( period * 1_000 ) : INFINITE - 1 ); |
|---|
| | 171 | return timedWait( period.milliseconds < INFINITE ? |
|---|
| | 172 | cast(uint)( period.milliseconds ) : INFINITE - 1 ); |
|---|
| 152 | 173 | } |
|---|
| 153 | 174 | else version( Posix ) |
|---|
| … | … | |
| 519 | 540 | { |
|---|
| 520 | 541 | waiting = true; |
|---|
| 521 | | alertedOne = condReady.wait( 1.0 ); |
|---|
| 522 | | alertedTwo = condReady.wait( 1.0 ); |
|---|
| | 542 | alertedOne = condReady.wait( 1 ); |
|---|
| | 543 | alertedTwo = condReady.wait( 1 ); |
|---|
| 523 | 544 | } |
|---|
| 524 | 545 | } |
|---|
| r2809 |
r2900 |
|
| 10 | 10 | |
|---|
| 11 | 11 | |
|---|
| 12 | | public import tango.core.Type; |
|---|
| | 12 | public import tango.core.TimeSpan; |
|---|
| 13 | 13 | public import tango.core.Exception : SyncException; |
|---|
| 14 | 14 | |
|---|
| … | … | |
| 38 | 38 | |
|---|
| 39 | 39 | |
|---|
| 40 | | void adjTimespec( inout timespec t, Interval i ) |
|---|
| | 40 | void adjTimespec( inout timespec t, TimeSpan i ) |
|---|
| 41 | 41 | { |
|---|
| 42 | 42 | enum |
|---|
| … | … | |
| 45 | 45 | } |
|---|
| 46 | 46 | |
|---|
| 47 | | if( t.tv_sec.max - t.tv_sec < i ) |
|---|
| | 47 | if( t.tv_sec.max - t.tv_sec < i.seconds ) |
|---|
| 48 | 48 | { |
|---|
| 49 | 49 | t.tv_sec = t.tv_sec.max; |
|---|
| … | … | |
| 52 | 52 | else |
|---|
| 53 | 53 | { |
|---|
| 54 | | t.tv_sec += i; |
|---|
| 55 | | i = (i % 1.0) * SECS_TO_NANOS; |
|---|
| 56 | | if( SECS_TO_NANOS - t.tv_nsec < i ) |
|---|
| | 54 | t.tv_sec += i.seconds; |
|---|
| | 55 | long ns = i.nanoseconds % SECS_TO_NANOS; |
|---|
| | 56 | if( SECS_TO_NANOS - t.tv_nsec < ns ) |
|---|
| 57 | 57 | { |
|---|
| 58 | 58 | t.tv_sec += 1; |
|---|
| 59 | | i -= SECS_TO_NANOS; |
|---|
| | 59 | ns -= SECS_TO_NANOS; |
|---|
| 60 | 60 | } |
|---|
| 61 | | t.tv_nsec += cast(typeof(t.tv_sec)) i; |
|---|
| | 61 | t.tv_nsec += cast(typeof(t.tv_sec)) ns; |
|---|
| 62 | 62 | } |
|---|
| 63 | 63 | } |
|---|
| r2809 |
r2900 |
|
| 9 | 9 | |
|---|
| 10 | 10 | |
|---|
| 11 | | public import tango.core.Type; |
|---|
| | 11 | public import tango.core.TimeSpan; |
|---|
| 12 | 12 | public import tango.core.Exception : SyncException; |
|---|
| 13 | 13 | |
|---|
| … | … | |
| 126 | 126 | * Otherwise, return false. |
|---|
| 127 | 127 | * |
|---|
| | 128 | * Note: The period is not always accurate, so it is possible that the |
|---|
| | 129 | * function would return with a timeout before the specified period. For |
|---|
| | 130 | * more accuracy, use the TimeSpan version. |
|---|
| | 131 | * |
|---|
| 128 | 132 | * Params: |
|---|
| 129 | 133 | * period = The number of seconds to wait. |
|---|
| … | … | |
| 135 | 139 | * SyncException on error. |
|---|
| 136 | 140 | */ |
|---|
| 137 | | bool wait( Interval period ) |
|---|
| 138 | | { |
|---|
| 139 | | version( Win32 ) |
|---|
| 140 | | { |
|---|
| 141 | | DWORD t = period < INFINITE ? |
|---|
| 142 | | cast(uint)( period * 1_000 ) : INFINITE - 1; |
|---|
| | 141 | bool wait( double period ) |
|---|
| | 142 | { |
|---|
| | 143 | return wait(TimeSpan.interval(period)); |
|---|
| | 144 | } |
|---|
| | 145 | |
|---|
| | 146 | /** |
|---|
| | 147 | * Wait up to the specified time for the current count to be above zero. |
|---|
| | 148 | * If this occurs, then atomically decrement the count by one and return |
|---|
| | 149 | * true. Otherwise, return false. |
|---|
| | 150 | * |
|---|
| | 151 | * Params: |
|---|
| | 152 | * period = The amount of time to wait. |
|---|
| | 153 | * |
|---|
| | 154 | * Returns: |
|---|
| | 155 | * true if notified before the timeout and false if not. |
|---|
| | 156 | * |
|---|
| | 157 | * Throws: |
|---|
| | 158 | * SyncException on error. |
|---|
| | 159 | */ |
|---|
| | 160 | bool wait( TimeSpan period ) |
|---|
| | 161 | { |
|---|
| | 162 | version( Win32 ) |
|---|
| | 163 | { |
|---|
| | 164 | DWORD t = period.milliseconds < INFINITE ? |
|---|
| | 165 | cast(uint)( period.milliseconds ) : INFINITE - 1; |
|---|
| 143 | 166 | switch( WaitForSingleObject( m_hndl, t ) ) |
|---|
| 144 | 167 | { |
|---|
| r2899 |
r2900 |
|
| 23 | 23 | private import tango.core.Exception; |
|---|
| 24 | 24 | |
|---|
| 25 | | private import tango.core.Type : Time; |
|---|
| | 25 | private import tango.util.time.DateTime; |
|---|
| 26 | 26 | |
|---|
| 27 | 27 | /******************************************************************************* |
|---|
| … | … | |
| 813 | 813 | ***********************************************************************/ |
|---|
| 814 | 814 | |
|---|
| 815 | | final Time modified () |
|---|
| | 815 | final DateTime modified () |
|---|
| 816 | 816 | { |
|---|
| 817 | 817 | return timeStamps.modified; |
|---|
| … | … | |
| 825 | 825 | ***********************************************************************/ |
|---|
| 826 | 826 | |
|---|
| 827 | | final Time accessed () |
|---|
| | 827 | final DateTime accessed () |
|---|
| 828 | 828 | { |
|---|
| 829 | 829 | return timeStamps.accessed; |
|---|
| … | … | |
| 837 | 837 | ***********************************************************************/ |
|---|
| 838 | 838 | |
|---|
| 839 | | final Time created () |
|---|
| | 839 | final DateTime created () |
|---|
| 840 | 840 | { |
|---|
| 841 | 841 | return timeStamps.created; |
|---|
| … | … | |
| 1100 | 1100 | final Stamps timeStamps () |
|---|
| 1101 | 1101 | { |
|---|
| 1102 | | static Time convert (FILETIME time) |
|---|
| | 1102 | static DateTime convert (FILETIME time) |
|---|
| 1103 | 1103 | { |
|---|
| 1104 | | return cast(Time) (Time.TicksTo1601 + *cast(ulong*) &time); |
|---|
| | 1104 | return DateTime.epoch1601 + TimeSpan(*cast(ulong*) &time); |
|---|
| 1105 | 1105 | } |
|---|
| 1106 | 1106 | |
|---|
| … | … | |
| 1418 | 1418 | final Stamps timeStamps () |
|---|
| 1419 | 1419 | { |
|---|
| 1420 | | static Time convert (timeval* tv) |
|---|
| | 1420 | static DateTime convert (timeval* tv) |
|---|
| 1421 | 1421 | { |
|---|
| 1422 | | return cast(Time) (Time.TicksTo1970 + (1_000_000L * |
|---|
| 1423 | | tv.tv_sec + tv.tv_usec) * 10); |
|---|
| | 1422 | return DateTime.epoch1970 + |
|---|
| | 1423 | TimeSpan.seconds(tv.tv_sec) + |
|---|
| | 1424 | TimeSpan.microseconds(tv.tv_usec); |
|---|
| 1424 | 1425 | } |
|---|
| 1425 | 1426 | |
|---|
| … | … | |
| 1649 | 1650 | struct Stamps |
|---|
| 1650 | 1651 | { |
|---|
| 1651 | | Time created, /// time created |
|---|
| 1652 | | accessed, /// last time accessed |
|---|
| 1653 | | modified; /// last time modified |
|---|
| | 1652 | DateTime created, /// time created |
|---|
| | 1653 | accessed, /// last time accessed |
|---|
| | 1654 | modified; /// last time modified |
|---|
| 1654 | 1655 | } |
|---|
| 1655 | 1656 | |
|---|
| … | … | |
| 1776 | 1777 | ***********************************************************************/ |
|---|
| 1777 | 1778 | |
|---|
| 1778 | | abstract Time modified (); |
|---|
| | 1779 | abstract DateTime modified (); |
|---|
| 1779 | 1780 | |
|---|
| 1780 | 1781 | /*********************************************************************** |
|---|
| … | … | |
| 1785 | 1786 | ***********************************************************************/ |
|---|
| 1786 | 1787 | |
|---|
| 1787 | | abstract Time accessed (); |
|---|
| | 1788 | abstract DateTime accessed (); |
|---|
| 1788 | 1789 | |
|---|
| 1789 | 1790 | /*********************************************************************** |
|---|
| … | … | |
| 1794 | 1795 | ***********************************************************************/ |
|---|
| 1795 | 1796 | |
|---|
| 1796 | | abstract Time created (); |
|---|
| | 1797 | abstract DateTime created (); |
|---|
| 1797 | 1798 | |
|---|
| 1798 | 1799 | /*********************************************************************** |
|---|
| r2809 |
r2900 |
|
| 246 | 246 | public int select() |
|---|
| 247 | 247 | { |
|---|
| 248 | | return select(Interval.max); |
|---|
| | 248 | return select(TimeSpan.max); |
|---|
| | 249 | } |
|---|
| | 250 | |
|---|
| | 251 | deprecated public int select(double timeout) |
|---|
| | 252 | { |
|---|
| | 253 | return select(timeout is timeout.max ? TimeSpan.max : TimeSpan.interval(timeout)); |
|---|
| 249 | 254 | } |
|---|
| 250 | 255 | |
|---|
| … | … | |
| 265 | 270 | * wakeup() method has been called from another thread. |
|---|
| 266 | 271 | */ |
|---|
| 267 | | public abstract int select(Interval timeout); |
|---|
| | 272 | public abstract int select(TimeSpan timeout); |
|---|
| 268 | 273 | |
|---|
| 269 | 274 | /** |
|---|
| … | … | |
| 304 | 309 | * Cast the time duration to a C timeval struct. |
|---|
| 305 | 310 | */ |
|---|
| 306 | | public timeval* toTimeval(timeval* tv, Interval interval) |
|---|
| | 311 | public timeval* toTimeval(timeval* tv, TimeSpan interval) |
|---|
| 307 | 312 | in |
|---|
| 308 | 313 | { |
|---|
| … | … | |
| 311 | 316 | body |
|---|
| 312 | 317 | { |
|---|
| 313 | | tv.tv_sec = cast(typeof(tv.tv_sec)) (interval); |
|---|
| 314 | | tv.tv_usec = cast(typeof(tv.tv_usec)) ((interval - tv.tv_sec) * 1_000_000); |
|---|
| | 318 | tv.tv_sec = cast(typeof(tv.tv_sec)) interval.seconds; |
|---|
| | 319 | tv.tv_usec = cast(typeof(tv.tv_usec)) (interval.microseconds % 1_000_000); |
|---|
| 315 | 320 | return tv; |
|---|
| 316 | 321 | } |
|---|
| r2809 |
r2900 |
|
| 339 | 339 | * |
|---|
| 340 | 340 | * Params: |
|---|
| 341 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 341 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 342 | 342 | * selector will wait for events from the conduits; the |
|---|
| 343 | 343 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 356 | 356 | * resources available to wait for events from the conduits. |
|---|
| 357 | 357 | */ |
|---|
| 358 | | public int select(Interval timeout) |
|---|
| 359 | | { |
|---|
| 360 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| | 358 | public int select(TimeSpan timeout) |
|---|
| | 359 | { |
|---|
| | 360 | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| 361 | 361 | |
|---|
| 362 | 362 | while (true) |
|---|
| r2809 |
r2900 |
|
| 292 | 292 | * |
|---|
| 293 | 293 | * Params: |
|---|
| 294 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 294 | * timeout = Timespan with the maximum amount of time that the |
|---|
| 295 | 295 | * selector will wait for events from the conduits; the |
|---|
| 296 | 296 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 309 | 309 | * resources available to wait for events from the conduits. |
|---|
| 310 | 310 | */ |
|---|
| 311 | | public int select(Interval timeout) |
|---|
| 312 | | { |
|---|
| 313 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| | 311 | public int select(TimeSpan timeout) |
|---|
| | 312 | { |
|---|
| | 313 | int to = (timeout != TimeSpan.max ? cast(int) timeout.milliseconds : -1); |
|---|
| 314 | 314 | |
|---|
| 315 | 315 | debug (selector) |
|---|
| r2873 |
r2900 |
|
| 411 | 411 | * |
|---|
| 412 | 412 | * Params: |
|---|
| 413 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 413 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 414 | 414 | * selector will wait for events from the conduits; the |
|---|
| 415 | 415 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 428 | 428 | * resources available to wait for events from the conduits. |
|---|
| 429 | 429 | */ |
|---|
| 430 | | public int select(Interval timeout) |
|---|
| | 430 | public int select(TimeSpan timeout) |
|---|
| 431 | 431 | { |
|---|
| 432 | 432 | fd_set *readfds; |
|---|
| … | … | |
| 435 | 435 | timeval tv; |
|---|
| 436 | 436 | |
|---|
| 437 | | int to = cast(int) (timeout != Interval.max ? cast(int) (timeout * 1000) : -1); |
|---|
| 438 | 437 | |
|---|
| 439 | 438 | debug (selector) |
|---|
| 440 | | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", to); |
|---|
| | 439 | Stdout.format("--- SelectSelector.select(timeout={0} msec)\n", timeout.milliseconds); |
|---|
| 441 | 440 | |
|---|
| 442 | 441 | if (_readSet !is null) |
|---|
| … | … | |
| 472 | 471 | |
|---|
| 473 | 472 | // FIXME: add support for the wakeup() call. |
|---|
| 474 | | _eventCount = .select(_maxfd + 1, readfds, writefds, exceptfds, to is -1 ? null : &tv); |
|---|
| | 473 | _eventCount = .select(_maxfd + 1, readfds, writefds, exceptfds, timeout is TimeSpan.max ? null : &tv); |
|---|
| 475 | 474 | |
|---|
| 476 | 475 | debug (selector) |
|---|
| … | … | |
| 498 | 497 | |
|---|
| 499 | 498 | // FIXME: Can a system call be interrupted on Windows? |
|---|
| 500 | | _eventCount = .select(ISelectable.Handle.max, readfds, writefds, exceptfds, to is -1 ? null : &tv); |
|---|
| | 499 | _eventCount = .select(ISelectable.Handle.max, readfds, writefds, exceptfds, timeout is TimeSpan.max ? null : &tv); |
|---|
| 501 | 500 | |
|---|
| 502 | 501 | debug (selector) |
|---|
| r2809 |
r2900 |
|
| 9 | 9 | public import tango.io.model.IConduit; |
|---|
| 10 | 10 | |
|---|
| 11 | | public import tango.core.Type : Interval; |
|---|
| | 11 | public import tango.core.TimeSpan; |
|---|
| 12 | 12 | |
|---|
| 13 | 13 | /** |
|---|
| … | … | |
| 400 | 400 | * |
|---|
| 401 | 401 | * Params: |
|---|
| 402 | | * timeout = Interval with the maximum amount of time that the |
|---|
| | 402 | * timeout = TimeSpan with the maximum amount of time that the |
|---|
| 403 | 403 | * selector will wait for events from the conduits; the |
|---|
| 404 | 404 | * amount of time is relative to the current system time |
|---|
| … | … | |
| 410 | 410 | * have received events within the specified timeout. |
|---|
| 411 | 411 | */ |
|---|
| 412 | | public abstract int select(Interval timeout); |
|---|
| | 412 | public abstract int select(TimeSpan timeout); |
|---|
| | 413 | |
|---|
| | 414 | /* |
|---|
| | 415 | * Deprecated: use select(TimeSpan) instead |
|---|
| | 416 | * |
|---|
| | 417 | * Params: |
|---|
| | 418 | * timeout = the maximum amount of time in seconds that the |
|---|
| | 419 | * selector will wait for events from the conduits; the |
|---|
| | 420 | * amount of time is relative to the current system time |
|---|
| | 421 | * (i.e. just the number of milliseconds that the selector |
|---|
| | 422 | * has to wait for the events). |
|---|
| | 423 | * |
|---|
| | 424 | * Returns: |
|---|
| | 425 | * The amount of conduits that have received events; 0 if no conduits |
|---|
| | 426 | * have received events within the specified timeout. |
|---|
| | 427 | */ |
|---|
| | 428 | deprecated public abstract int select(double timeout); |
|---|
| 413 | 429 | |
|---|
| 414 | 430 | /** |
|---|
| r2588 |
r2900 |
|
| 67 | 67 | private import tango.core.Exception; |
|---|
| 68 | 68 | |
|---|
| 69 | | private import tango.core.Type : Interval; |
|---|
| | 69 | private import tango.core.TimeSpan; |
|---|
| 70 | 70 | |
|---|
| 71 | 71 | |
|---|
| … | … | |
| 1359 | 1359 | ***********************************************************************/ |
|---|
| 1360 | 1360 | |
|---|
| 1361 | | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, Interval time) |
|---|
| | 1361 | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, TimeSpan time) |
|---|
| 1362 | 1362 | { |
|---|
| 1363 | 1363 | auto tv = toTimeval (time); |
|---|
| … | … | |
| 1365 | 1365 | } |
|---|
| 1366 | 1366 | |
|---|
| | 1367 | /*********************************************************************** |
|---|
| | 1368 | select with specified timeout |
|---|
| | 1369 | |
|---|
| | 1370 | Note: The period is not always accurate, so it is possible |
|---|
| | 1371 | that the function will return with a timeout before the |
|---|
| | 1372 | specified period. For more accuracy, use the TimeSpan |
|---|
| | 1373 | version. |
|---|
| | 1374 | ***********************************************************************/ |
|---|
| | 1375 | |
|---|
| | 1376 | static int select (SocketSet checkRead, SocketSet checkWrite, SocketSet checkError, double time) |
|---|
| | 1377 | { |
|---|
| | 1378 | return select(checkRead, checkWrite, checkError, TimeSpan.interval(time)); |
|---|
| | 1379 | } |
|---|
| | 1380 | |
|---|
| 1367 | 1381 | |
|---|
| 1368 | 1382 | /*********************************************************************** |
|---|
| … | … | |
| 1379 | 1393 | /*********************************************************************** |
|---|
| 1380 | 1394 | |
|---|
| 1381 | | Handy utility for converting Time into timeval |
|---|
| 1382 | | |
|---|
| 1383 | | ***********************************************************************/ |
|---|
| 1384 | | |
|---|
| 1385 | | static timeval toTimeval (Interval time) |
|---|
| | 1395 | Handy utility for converting TimeSpan into timeval |
|---|
| | 1396 | |
|---|
| | 1397 | ***********************************************************************/ |
|---|
| | 1398 | |
|---|
| | 1399 | static timeval toTimeval (TimeSpan time) |
|---|
| 1386 | 1400 | { |
|---|
| 1387 | 1401 | timeval tv; |
|---|
| 1388 | | tv.tv_sec = cast(uint) time; |
|---|
| 1389 | | tv.tv_usec = cast(uint) ((time - tv.tv_sec) * 1_000_000.0); |
|---|
| | 1402 | tv.tv_sec = cast(uint) time.seconds; |
|---|
| | 1403 | tv.tv_usec = cast(uint) time.microseconds % 1_000_000; |
|---|
| 1390 | 1404 | return tv; |
|---|
| 1391 | 1405 | } |
|---|
| r2739 |
r2900 |
|
| 19 | 19 | private import tango.net.Socket; |
|---|
| 20 | 20 | |
|---|
| 21 | | private import tango.core.Type : Interval; |
|---|
| | 21 | private import tango.core.TimeSpan; |
|---|
| 22 | 22 | |
|---|
| 23 | 23 | /******************************************************************************* |
|---|
| … | … | |
| 121 | 121 | ***********************************************************************/ |
|---|
| 122 | 122 | |
|---|
| 123 | | SocketConduit setTimeout (Interval interval) |
|---|
| | 123 | SocketConduit setTimeout (TimeSpan interval) |
|---|
| 124 | 124 | { |
|---|
| 125 | 125 | tv = socket_.toTimeval (interval); |
|---|
| 126 | 126 | return this; |
|---|
| | 127 | } |
|---|
| | 128 | |
|---|
| | 129 | deprecated SocketConduit setTimeout (double interval) |
|---|
| | 130 | { |
|---|
| | 131 | return setTimeout(TimeSpan.interval(interval)); |
|---|
| 127 | 132 | } |
|---|
| 128 | 133 | |
|---|
| r2809 |
r2900 |
|
| 64 | 64 | ***********************************************************************/ |
|---|
| 65 | 65 | |
|---|
| 66 | | void invalidate (char[] key, Time timeLimit = Time.max) |
|---|
| | 66 | void invalidate (char[] key, DateTime timeLimit = DateTime.max) |
|---|
| 67 | 67 | { |
|---|
| 68 | 68 | assert (key.length); |
|---|
| r2878 |
r2900 |
|
| 93 | 93 | ***********************************************************************/ |
|---|
| 94 | 94 | |
|---|
| 95 | | Time time () |
|---|
| | 95 | DateTime time () |
|---|
| 96 | 96 | { |
|---|
| 97 | 97 | return Clock.now; |
|---|
| r2878 |
r2900 |
|
| 43 | 43 | class NetworkMessage : IMessage |
|---|
| 44 | 44 | { |
|---|
| 45 | | private uint id_; |
|---|
| 46 | | private long time_; |
|---|
| 47 | | private char[] reply_; |
|---|
| | 45 | private uint id_; |
|---|
| | 46 | private DateTime time_; |
|---|
| | 47 | private char[] reply_; |
|---|
| 48 | 48 | |
|---|
| 49 | 49 | /*********************************************************************** |
|---|
| … | … | |
| 98 | 98 | ***********************************************************************/ |
|---|
| 99 | 99 | |
|---|
| 100 | | void time (Time time) |
|---|
| | 100 | void time (DateTime time) |
|---|
| 101 | 101 | { |
|---|
| 102 | 102 | time_ = time; |
|---|
| … | … | |
| 109 | 109 | ***********************************************************************/ |
|---|
| 110 | 110 | |
|---|
| 111 | | Time time () |
|---|
| | 111 | DateTime time () |
|---|
| 112 | 112 | { |
|---|
| 113 | | return cast(Time) time_; |
|---|
| | 113 | return time_; |
|---|
| 114 | 114 | } |
|---|
| 115 | 115 | |
|---|
| … | … | |
| 140 | 140 | void read (IReader input) |
|---|
| 141 | 141 | { |
|---|
| 142 | | input (id_) (time_) (reply_); |
|---|
| | 142 | input (id_) (time_.ticks) (reply_); |
|---|
| 143 | 143 | } |
|---|
| 144 | 144 | |
|---|
| … | … | |
| 151 | 151 | void write (IWriter output) |
|---|
| 152 | 152 | { |
|---|
| 153 | | output (id_) (time_) (reply_); |
|---|
| | 153 | output (id_) (time_.ticks) (reply_); |
|---|
| 154 | 154 | } |
|---|
| 155 | 155 | |
|---|
| r2809 |
r2900 |
|
| 13 | 13 | module tango.net.cluster.QueuedCache; |
|---|
| 14 | 14 | |
|---|
| 15 | | private import tango.core.Type : Time; |
|---|
| | 15 | private import tango.util.time.DateTime; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private import tango.net.cluster.model.ICache; |
|---|
| … | … | |
| 116 | 116 | **********************************************************************/ |
|---|
| 117 | 117 | |
|---|
| 118 | | synchronized bool put (K key, V value, Time time = Time.init) |
|---|
| | 118 | synchronized bool put (K key, V value, DateTime time = DateTime.init) |
|---|
| 119 | 119 | { |
|---|
| 120 | 120 | assert (key !is key.init); |
|---|
| … | … | |
| 138 | 138 | **********************************************************************/ |
|---|
| 139 | 139 | |
|---|
| 140 | | synchronized bool put (K peek, K delegate() key, V delegate() value, Time time = Time.init) |
|---|
| | 140 | synchronized bool put (K peek, K delegate() key, V delegate() value, DateTime time = DateTime.init) |
|---|
| 141 | 141 | { |
|---|
| 142 | 142 | assert (peek !is peek.init); |
|---|
| … | … | |
| 162 | 162 | **********************************************************************/ |
|---|
| 163 | 163 | |
|---|
| 164 | | synchronized V remove (K key, Time time = Time.max) |
|---|
| | 164 | synchronized V remove (K key, DateTime time = DateTime.max) |
|---|
| 165 | 165 | { |
|---|
| 166 | 166 | auto e = lookup (key); |
|---|
| … | … | |
| 171 | 171 | // don't actually kill the list entry -- just place |
|---|
| 172 | 172 | // it at the list 'tail' ready for subsequent reuse |
|---|
| 173 | | deReference(e).set (K.init, V.init, Time.min); |
|---|
| | 173 | deReference(e).set (K.init, V.init, DateTime.min); |
|---|
| 174 | 174 | |
|---|
| 175 | 175 | map.remove (key); |
|---|
| … | … | |
| 288 | 288 | QueuedEntry* prev, |
|---|
| 289 | 289 | next; |
|---|
| 290 | | Time time; |
|---|
| | 290 | DateTime time; |
|---|
| 291 | 291 | V value; |
|---|
| 292 | 292 | |
|---|
| … | … | |
| 297 | 297 | **************************************************************/ |
|---|
| 298 | 298 | |
|---|
| 299 | | QueuedEntry* set (K key, V value, Time time) |
|---|
| | 299 | QueuedEntry* set (K key, V value, DateTime time) |
|---|
| 300 | 300 | { |
|---|
| 301 | 301 | this.value = value; |
|---|
| r2809 |
r2900 |
|
| 11 | 11 | module tango.net.cluster.model.ICache; |
|---|
| 12 | 12 | |
|---|
| 13 | | private import tango.core.Type : Time; |
|---|
| | 13 | private import tango.util.time.DateTime; |
|---|
| 14 | 14 | |
|---|
| 15 | 15 | /****************************************************************************** |
|---|
| … | … | |
| 38 | 38 | **********************************************************************/ |
|---|
| 39 | 39 | |
|---|
| 40 | | bool put (K key, V entry, Time time = Time.init); |
|---|
| | 40 | bool put (K key, V entry, DateTime time = DateTime.init); |
|---|
| 41 | 41 | |
|---|
| 42 | 42 | /********************************************************************** |
|---|
| … | … | |
| 50 | 50 | **********************************************************************/ |
|---|
| 51 | 51 | |
|---|
| 52 | | V remove (K key, Time time = Time.max); |
|---|
| | 52 | V remove (K key, DateTime time = DateTime.max); |
|---|
| 53 | 53 | } |
|---|
| 54 | 54 | |
|---|
| r2809 |
r2900 |
|
| 13 | 13 | module tango.net.cluster.model.IMessage; |
|---|
| 14 | 14 | |
|---|
| 15 | | public import tango.core.Type : Time; |
|---|
| | 15 | public import tango.util.time.DateTime; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | public import tango.io.protocol.model.IReader, |
|---|
| … | … | |
| 52 | 52 | ***********************************************************************/ |
|---|
| 53 | 53 | |
|---|
| 54 | | void time (Time value); |
|---|
| | 54 | void time (DateTime value); |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | /*********************************************************************** |
|---|
| … | … | |
| 58 | 58 | ***********************************************************************/ |
|---|
| 59 | 59 | |
|---|
| 60 | | Time time (); |
|---|
| | 60 | DateTime time (); |
|---|
| 61 | 61 | |
|---|
| 62 | 62 | /*********************************************************************** |
|---|
| r2809 |
r2900 |
|
| 73 | 73 | |
|---|
| 74 | 74 | // return the content if we can't put it in the cache |
|---|
| 75 | | if (cache.put (channel, element, content, cast(Time) time)) |
|---|
| | 75 | if (cache.put (channel, element, content, DateTime(time))) |
|---|
| 76 | 76 | writer.success ("success"); |
|---|
| 77 | 77 | else |
|---|
| r2809 |
r2900 |
|
| 987 | 987 | abstract bool reset(); |
|---|
| 988 | 988 | |
|---|
| 989 | | abstract void done (Time time); |
|---|
| | 989 | abstract void done (DateTime time); |
|---|
| 990 | 990 | |
|---|
| 991 | 991 | abstract SocketConduit conduit (); |
|---|
| … | … | |
| 1009 | 1009 | private InternetAddress address; |
|---|
| 1010 | 1010 | private PoolConnection freelist; |
|---|
| 1011 | | private Time timeout = cast(Time) (60 * Time.TicksPerSecond); |
|---|
| | 1011 | private TimeSpan timeout = TimeSpan.seconds(60); |
|---|
| 1012 | 1012 | |
|---|
| 1013 | 1013 | /*********************************************************************** |
|---|
| … | … | |
| 1020 | 1020 | static class PoolConnection : Connection |
|---|
| 1021 | 1021 | { |
|---|
| 1022 | | Time time; |
|---|
| | 1022 | DateTime time; |
|---|
| 1023 | 1023 | PoolConnection next; |
|---|
| 1024 | 1024 | ConnectionPool parent; |
|---|
| … | … | |
| 1055 | 1055 | |
|---|
| 1056 | 1056 | // set a 500ms timeout for read operations |
|---|
| 1057 | | conduit_.setTimeout (0.500); |
|---|
| | 1057 | conduit_.setTimeout (TimeSpan.milliseconds(500)); |
|---|
| 1058 | 1058 | |
|---|
| 1059 | 1059 | // open a connection to this server |
|---|
| … | … | |
| 1100 | 1100 | ***************************************************************/ |
|---|
| 1101 | 1101 | |
|---|
| 1102 | | final void done (Time time) |
|---|
| | 1102 | final void done (DateTime time) |
|---|
| 1103 | 1103 | { |
|---|
| 1104 | 1104 | synchronized (parent) |
|---|
| … | … | |
| 1132 | 1132 | ***********************************************************************/ |
|---|
| 1133 | 1133 | |
|---|
| 1134 | | final synchronized Connection borrow (Time time) |
|---|
| | 1134 | final synchronized Connection borrow (DateTime time) |
|---|
| 1135 | 1135 | { |
|---|
| 1136 | 1136 | if (freelist) |
|---|
| … | … | |
| 1293 | 1293 | { |
|---|
| 1294 | 1294 | ProtocolWriter.Command cmd; |
|---|
| 1295 | | Time time; |
|---|
| | 1295 | DateTime time; |
|---|
| 1296 | 1296 | char[] channel; |
|---|
| 1297 | 1297 | char[] element; |
|---|
| r2878 |
r2900 |
|
| 64 | 64 | **********************************************************************/ |
|---|
| 65 | 65 | |
|---|
| 66 | | bool put (char[] channel, char[] element, ClusterContent content, Time time) |
|---|
| | 66 | bool put (char[] channel, char[] element, ClusterContent content, DateTime time) |
|---|
| 67 | 67 | { |
|---|
| 68 | 68 | return lookup(channel).put (element, {return element.dup;}, |
|---|
| … | … | |
| 102 | 102 | **********************************************************************/ |
|---|
| 103 | 103 | |
|---|
| 104 | | bool lock (char[] channel, char[] element, Time time) |
|---|
| | 104 | bool lock (char[] channel, char[] element, DateTime time) |
|---|
| 105 | 105 | { |
|---|
| 106 | 106 | return true; |
|---|
| r2809 |
r2900 |
|
| 30 | 30 | private uint used, |
|---|
| 31 | 31 | limit; |
|---|
| 32 | | private Interval sleep; |
|---|
| | 32 | private TimeSpan sleep; |
|---|
| 33 | 33 | private Thread thread; |
|---|
| 34 | 34 | private Cluster cluster; |
|---|
| … | … | |
| 56 | 56 | **********************************************************************/ |
|---|
| 57 | 57 | |
|---|
| 58 | | this (Cluster cluster, uint limit, Interval sleep) |
|---|
| | 58 | this (Cluster cluster, uint limit, TimeSpan sleep) |
|---|
| 59 | 59 | { |
|---|
| 60 | 60 | thread = new Thread (&run); |
|---|
| … | … | |
| 112 | 112 | **********************************************************************/ |
|---|
| 113 | 113 | |
|---|
| 114 | | this (Cluster cluster, uint limit, Interval sleep) |
|---|
| | 114 | this (Cluster cluster, uint limit, TimeSpan sleep) |
|---|
| 115 | 115 | { |
|---|
| 116 | 116 | super (cluster, limit, sleep); |
|---|
| r2809 |
r2900 |
|
| 119 | 119 | getLogger.trace ("heartbeat"); |
|---|
| 120 | 120 | channel.broadcast (rollcall); |
|---|
| 121 | | Thread.sleep (30.0); |
|---|
| | 121 | Thread.sleep (TimeSpan.seconds(30)); |
|---|
| 122 | 122 | } |
|---|
| 123 | 123 | } |
|---|
| r2809 |
r2900 |
|
| 100 | 100 | ProtocolWriter put (Command cmd, char[] channel, char[] element = null, IMessage msg = null) |
|---|
| 101 | 101 | { |
|---|
| 102 | | auto time = (msg ? msg.time : Time.init); |
|---|
| | 102 | auto time = (msg ? msg.time : DateTime.init); |
|---|
| 103 | 103 | |
|---|
| 104 | 104 | // reset the buffer first! |
|---|
| … | … | |
| 109 | 109 | (cast(ubyte) cmd) |
|---|
| 110 | 110 | (cast(ubyte) Version) |
|---|
| 111 | | (cast(ulong) time) |
|---|
| | 111 | (cast(ulong) time.ticks) |
|---|
| 112 | 112 | (channel) |
|---|
| 113 | 113 | (element); |
|---|
| … | … | |
| 141 | 141 | (cast(ubyte) ProtocolWriter.Command.OK) |
|---|
| 142 | 142 | (cast(ubyte) Version) |
|---|
| 143 | | (cast(ulong) Time.init); |
|---|
| | 143 | (cast(ulong) ulong.init); |
|---|
| 144 | 144 | |
|---|
| 145 | 145 | // and the payload (which includes both channel & element) |
|---|
| r2809 |
r2900 |
|
| 17 | 17 | tango.net.cluster.tina.ClusterQueue, |
|---|
| 18 | 18 | tango.net.cluster.tina.ClusterServer; |
|---|
| | 19 | |
|---|
| | 20 | private import tango.core.TimeSpan; |
|---|
| 19 | 21 | |
|---|
| 20 | 22 | /****************************************************************************** |
|---|
| … | … | |
| 41 | 43 | // create a queue instance |
|---|
| 42 | 44 | // queue = new MemoryQueue (cluster, 64 * 1024 * 1024, 1.0); |
|---|
| 43 | | queue = new PersistQueue (cluster, 64 * 1024 * 1024, 3.0); |
|---|
| | 45 | queue = new PersistQueue (cluster, 64 * 1024 * 1024, TimeSpan.seconds(3)); |
|---|
| 44 | 46 | |
|---|
| 45 | 47 | } |
|---|
| r2809 |
r2900 |
|
| 31 | 31 | private import Timestamp = tango.text.convert.TimeStamp; |
|---|
| 32 | 32 | |
|---|
| | 33 | private import tango.core.TimeSpan; |
|---|
| 33 | 34 | |
|---|
| 34 | 35 | /// An FTP progress delegate. |
|---|
| … | … | |
| 141 | 142 | long size = -1; |
|---|
| 142 | 143 | /// Modification time, if available. |
|---|
| 143 | | Time modify = Time.max; |
|---|
| | 144 | DateTime modify = DateTime.max; |
|---|
| 144 | 145 | /// Creation time, if available (not often.) |
|---|
| 145 | | Time create = Time.max; |
|---|
| | 146 | DateTime create = DateTime.max; |
|---|
| 146 | 147 | /// The file's mime type, if known. |
|---|
| 147 | 148 | char[] mime = null; |
|---|
| … | … | |
| 616 | 617 | |
|---|
| 617 | 618 | // At end_time, we bail. |
|---|
| 618 | | Time end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 619 | DateTime end_time = Clock.now + this.timeout; |
|---|
| 619 | 620 | |
|---|
| 620 | 621 | while (Clock.now < end_time) |
|---|
| … | … | |
| 624 | 625 | |
|---|
| 625 | 626 | // Can we accept yet? |
|---|
| 626 | | int code = Socket.select(set, null, null, this.timeout/Time.TicksPerSecond); |
|---|
| | 627 | int code = Socket.select(set, null, null, this.timeout); |
|---|
| 627 | 628 | if (code == -1 || code == 0) |
|---|
| 628 | 629 | break; |
|---|
| … | … | |
| 1224 | 1225 | |
|---|
| 1225 | 1226 | if (Timestamp.dostime (r.match(0), info.modify) is 0) |
|---|
| 1226 | | info.modify = Time.max; |
|---|
| | 1227 | info.modify = DateTime.max; |
|---|
| 1227 | 1228 | |
|---|
| 1228 | 1229 | pos = r.match(0).length; |
|---|
| … | … | |
| 1344 | 1345 | /// |
|---|
| 1345 | 1346 | /// Returns: a d_time representing the same date |
|---|
| 1346 | | protected Time parseTimeval(char[] timeval) |
|---|
| | 1347 | protected DateTime parseTimeval(char[] timeval) |
|---|
| 1347 | 1348 | { |
|---|
| 1348 | 1349 | Date date; |
|---|
| … | … | |
| 1368 | 1369 | /// |
|---|
| 1369 | 1370 | /// Returns: a d_time representing the mtime |
|---|
| 1370 | | public Time filemtime(char[] path) |
|---|
| | 1371 | public DateTime filemtime(char[] path) |
|---|
| 1371 | 1372 | in |
|---|
| 1372 | 1373 | { |
|---|
| … | … | |
| 1544 | 1545 | |
|---|
| 1545 | 1546 | // At end_time, we bail. |
|---|
| 1546 | | Time end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 1547 | DateTime end_time = Clock.now + this.timeout; |
|---|
| 1547 | 1548 | |
|---|
| 1548 | 1549 | // This is the buffer the stream data is stored in. |
|---|
| … | … | |
| 1559 | 1560 | |
|---|
| 1560 | 1561 | // Can we write yet, can we write yet? |
|---|
| 1561 | | int code = Socket.select(null, set, null, this.timeout/Time.TicksPerSecond); |
|---|
| | 1562 | int code = Socket.select(null, set, null, this.timeout); |
|---|
| 1562 | 1563 | if (code == -1 || code == 0) |
|---|
| 1563 | 1564 | break; |
|---|
| … | … | |
| 1583 | 1584 | // Give it more time as long as data is going through. |
|---|
| 1584 | 1585 | if (delta != 0) |
|---|
| 1585 | | end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 1586 | end_time = Clock.now + this.timeout; |
|---|
| 1586 | 1587 | } |
|---|
| 1587 | 1588 | |
|---|
| … | … | |
| 1611 | 1612 | |
|---|
| 1612 | 1613 | // At end_time, we bail. |
|---|
| 1613 | | Time end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 1614 | DateTime end_time = Clock.now + this.timeout; |
|---|
| 1614 | 1615 | |
|---|
| 1615 | 1616 | // This is the buffer the stream data is stored in. |
|---|
| … | … | |
| 1625 | 1626 | |
|---|
| 1626 | 1627 | // Can we read yet, can we read yet? |
|---|
| 1627 | | int code = Socket.select(set, null, null, this.timeout/Time.TicksPerSecond); |
|---|
| | 1628 | int code = Socket.select(set, null, null, this.timeout); |
|---|
| 1628 | 1629 | if (code == -1 || code == 0) |
|---|
| 1629 | 1630 | break; |
|---|
| … | … | |
| 1646 | 1647 | |
|---|
| 1647 | 1648 | // Give it more time as long as data is going through. |
|---|
| 1648 | | end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 1649 | end_time = Clock.now + this.timeout; |
|---|
| 1649 | 1650 | } |
|---|
| 1650 | 1651 | |
|---|
| … | … | |
| 1755 | 1756 | |
|---|
| 1756 | 1757 | // Pick a time at which we stop reading. It can't take too long, but it could take a bit for the whole response. |
|---|
| 1757 | | Time end_time = cast(Time) (Clock.now + this.timeout * 10); |
|---|
| | 1758 | DateTime end_time = Clock.now + this.timeout * 10; |
|---|
| 1758 | 1759 | |
|---|
| 1759 | 1760 | FtpResponse response; |
|---|
| r2809 |
r2900 |
|
| 20 | 20 | |
|---|
| 21 | 21 | private import Integer = tango.text.convert.Integer; |
|---|
| | 22 | |
|---|
| | 23 | private import tango.core.TimeSpan; |
|---|
| 22 | 24 | |
|---|
| 23 | 25 | |
|---|
| … | … | |
| 34 | 36 | |
|---|
| 35 | 37 | /// The number of milliseconds to wait for socket communication or connection. |
|---|
| 36 | | protected Time timeout = cast(Time) (5000 * Time.TicksPerMillisecond); |
|---|
| | 38 | protected TimeSpan timeout = TimeSpan.milliseconds(5000); |
|---|
| 37 | 39 | |
|---|
| 38 | 40 | /// provided by host |
|---|
| … | … | |
| 62 | 64 | { |
|---|
| 63 | 65 | // At end_time, we bail. |
|---|
| 64 | | Time end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 66 | DateTime end_time = Clock.now + this.timeout; |
|---|
| 65 | 67 | |
|---|
| 66 | 68 | // Set up a SocketSet so we can use select() - it's pretty efficient. |
|---|
| … | … | |
| 76 | 78 | |
|---|
| 77 | 79 | // Can we write yet, can we write yet? |
|---|
| 78 | | int code = Socket.select(null, set, null, this.timeout / Time.TicksPerSecond); |
|---|
| | 80 | int code = Socket.select(null, set, null, this.timeout); |
|---|
| 79 | 81 | if (code == -1 || code == 0) |
|---|
| 80 | 82 | break; |
|---|
| … | … | |
| 101 | 103 | { |
|---|
| 102 | 104 | // Figure, first, how long we're allowed to take. |
|---|
| 103 | | Time end_time = cast(Time) (Clock.now + this.timeout); |
|---|
| | 105 | DateTime end_time = Clock.now + this.timeout; |
|---|
| 104 | 106 | |
|---|
| 105 | 107 | // An overall buffer and a one-char buffer. |
|---|
| … | … | |
| 135 | 137 | |
|---|
| 136 | 138 | // Try to read from the socket. |
|---|
| 137 | | int code = Socket.select(set, null, null, this.timeout / Time.TicksPerSecond); |
|---|
| | 139 | int code = Socket.select(set, null, null, this.timeout); |
|---|
| 138 | 140 | if (code == -1 || code == 0) |
|---|
| 139 | 141 | break; |
|---|
| … | … | |
| 210 | 212 | |
|---|
| 211 | 213 | // Anyone available? |
|---|
| 212 | | int code = Socket.select(null, set, null, this.timeout / Time.TicksPerSecond); |
|---|
| | 214 | int code = Socket.select(null, set, null, this.timeout); |
|---|
| 213 | 215 | if (code == -1 || code == 0) |
|---|
| 214 | 216 | break; |
|---|
| … | … | |
| 237 | 239 | { |
|---|
| 238 | 240 | char[10] tmp; |
|---|
| 239 | | exception ("CLIENT: Unable to connect within the specified time limit (" ~ Integer.itoa(tmp, cast(uint) (this.timeout/Time.TicksPerMillisecond)) ~ " ms.)"); |
|---|
| | 241 | exception ("CLIENT: Unable to connect within the specified time limit (" ~ Integer.itoa(tmp, cast(uint) this.timeout.milliseconds) ~ " ms.)"); |
|---|
| 240 | 242 | } |
|---|
| 241 | 243 | |
|---|
| r2738 |
r2900 |
|
| 25 | 25 | tango.net.InternetAddress; |
|---|
| 26 | 26 | |
|---|
| 27 | | private import tango.core.Type : Interval; |
|---|
| | 27 | private import tango.core.TimeSpan; |
|---|
| 28 | 28 | |
|---|
| 29 | 29 | private import tango.net.http.HttpConst, |
|---|
| … | … | |
| 104 | 104 | |
|---|
| 105 | 105 | // default to three second timeout on read operations ... |
|---|
| 106 | | private Interval timeout = 3; |
|---|
| | 106 | private TimeSpan timeout = TimeSpan.seconds(3); |
|---|
| 107 | 107 | |
|---|
| 108 | 108 | // should we perform internal redirection? |
|---|
| … | … | |
| 305 | 305 | ***********************************************************************/ |
|---|
| 306 | 306 | |
|---|
| 307 | | void setTimeout (Interval interval) |
|---|
| | 307 | void setTimeout (TimeSpan interval) |
|---|
| 308 | 308 | { |
|---|
| 309 | 309 | timeout = interval; |
|---|
| | 310 | } |
|---|
| | 311 | |
|---|
| | 312 | /** |
|---|
| | 313 | * Deprecated: use setTimeout(TimeSpan) instead |
|---|
| | 314 | */ |
|---|
| | 315 | deprecated void setTimeout(double interval) |
|---|
| | 316 | { |
|---|
| | 317 | setTimeout(TimeSpan.interval(interval)); |
|---|
| 310 | 318 | } |
|---|
| 311 | 319 | |
|---|
| r2023 |
r2900 |
|
| 21 | 21 | private import tango.text.stream.LineIterator; |
|---|
| 22 | 22 | |
|---|
| | 23 | private import tango.util.time.DateTime; |
|---|
| | 24 | |
|---|
| 23 | 25 | /****************************************************************************** |
|---|
| 24 | 26 | |
|---|
| … | … | |
| 128 | 130 | /********************************************************************** |
|---|
| 129 | 131 | |
|---|
| 130 | | Return the date value of the provided header, or Time.max |
|---|
| | 132 | Return the date value of the provided header, or DateTime.max |
|---|
| 131 | 133 | if the header does not exist |
|---|
| 132 | 134 | |
|---|
| 133 | 135 | **********************************************************************/ |
|---|
| 134 | 136 | |
|---|
| 135 | | Time getDate (HttpHeaderName name, Time def = Time.max) |
|---|
| | 137 | DateTime getDate (HttpHeaderName name, DateTime def = DateTime.max) |
|---|
| 136 | 138 | { |
|---|
| 137 | 139 | return super.getDate (name.value, def); |
|---|
| … | … | |
| 309 | 311 | **********************************************************************/ |
|---|
| 310 | 312 | |
|---|
| 311 | | void addDate (HttpHeaderName name, Time value) |
|---|
| | 313 | void addDate (HttpHeaderName name, DateTime value) |
|---|
| 312 | 314 | { |
|---|
| 313 | 315 | super.addDate (name.value, value); |
|---|
| r2281 |
r2900 |
|
| 20 | 20 | |
|---|
| 21 | 21 | private import tango.text.stream.SimpleIterator; |
|---|
| | 22 | |
|---|
| | 23 | private import tango.util.time.DateTime; |
|---|
| 22 | 24 | |
|---|
| 23 | 25 | public import tango.net.http.model.HttpParamsView; |
|---|
| … | … | |
| 115 | 117 | **********************************************************************/ |
|---|
| 116 | 118 | |
|---|
| 117 | | void addDate (char[] name, Time value) |
|---|
| | 119 | void addDate (char[] name, DateTime value) |
|---|
| 118 | 120 | { |
|---|
| 119 | 121 | super.addDate (name, value); |
|---|
| … | … | |
| 151 | 153 | **********************************************************************/ |
|---|
| 152 | 154 | |
|---|
| 153 | | Time getDate (char[] name, Time ret = Time.max) |
|---|
| | 155 | DateTime getDate (char[] name, DateTime ret = DateTime.max) |
|---|
| 154 | 156 | { |
|---|
| 155 | 157 | return super.getDate (name, ret); |
|---|
| r2281 |
r2900 |
|
| 22 | 22 | private import Text = tango.text.Util; |
|---|
| 23 | 23 | |
|---|
| 24 | | private import tango.core.Type : Time; |
|---|
| | 24 | private import tango.util.time.DateTime; |
|---|
| 25 | 25 | |
|---|
| 26 | 26 | private import tango.io.protocol.model.IWriter; |
|---|
| … | … | |
| 217 | 217 | **********************************************************************/ |
|---|
| 218 | 218 | |
|---|
| 219 | | Time getDate (char[] name, Time date = Time.max) |
|---|
| | 219 | DateTime getDate (char[] name, DateTime date = DateTime.max) |
|---|
| 220 | 220 | { |
|---|
| 221 | 221 | char[] value = get (name); |
|---|
| … | … | |
| 534 | 534 | **********************************************************************/ |
|---|
| 535 | 535 | |
|---|
| 536 | | protected void addDate (char[] name, Time value) |
|---|
| | 536 | protected void addDate (char[] name, DateTime value) |
|---|
| 537 | 537 | { |
|---|
| 538 | 538 | char[40] tmp = void; |
|---|
| r2809 |
r2900 |
|
| 13 | 13 | module tango.net.http.model.HttpParamsView; |
|---|
| 14 | 14 | |
|---|
| 15 | | private import tango.core.Type : Time; |
|---|
| | 15 | private import tango.util.time.DateTime; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | private import tango.io.model.IBuffer; |
|---|
| … | … | |
| 59 | 59 | **********************************************************************/ |
|---|
| 60 | 60 | |
|---|
| 61 | | Time getDate (char[] name, Time ret = Time.max); |
|---|
| | 61 | DateTime getDate (char[] name, DateTime ret = DateTime.max); |
|---|
| 62 | 62 | |
|---|
| 63 | 63 | /********************************************************************** |
|---|
| r2809 |
r2900 |
|
| 65 | 65 | ******************************************************************************/ |
|---|
| 66 | 66 | |
|---|
| 67 | | char[] toUtf8 (Time time) |
|---|
| | 67 | char[] toUtf8 (DateTime time) |
|---|
| 68 | 68 | { |
|---|
| 69 | 69 | char[32] tmp = void; |
|---|
| … | … | |
| 81 | 81 | ******************************************************************************/ |
|---|
| 82 | 82 | |
|---|
| 83 | | wchar[] toUtf16 (Time time) |
|---|
| | 83 | wchar[] toUtf16 (DateTime time) |
|---|
| 84 | 84 | { |
|---|
| 85 | 85 | wchar[32] tmp = void; |
|---|
| … | … | |
| 97 | 97 | ******************************************************************************/ |
|---|
| 98 | 98 | |
|---|
| 99 | | dchar[] toUtf32 (Time time) |
|---|
| | 99 | dchar[] toUtf32 (DateTime time) |
|---|
| 100 | 100 | { |
|---|
| 101 | 101 | dchar[32] tmp = void; |
|---|
| … | … | |
| 117 | 117 | ******************************************************************************/ |
|---|
| 118 | 118 | |
|---|
| 119 | | T[] format(T, U=Time) (T[] output, U time) |
|---|
| 120 | | {return format!(T)(output, cast(Time) time);} |
|---|
| 121 | | |
|---|
| 122 | | T[] format(T) (T[] output, Time time) |
|---|
| | 119 | T[] format(T, U=DateTime) (T[] output, U time) |
|---|
| | 120 | {return format!(T)(output, cast(DateTime) time);} |
|---|
| | 121 | |
|---|
| | 122 | T[] format(T) (T[] output, DateTime time) |
|---|
| 123 | 123 | { |
|---|
| 124 | 124 | // these arrays also reside in Date, but need to be templated here |
|---|
| … | … | |
| 138 | 138 | |
|---|
| 139 | 139 | if (time is time.max) |
|---|
| 140 | | throw new IllegalArgumentException ("TimeStamp.format :: invalid Time argument"); |
|---|
| | 140 | throw new IllegalArgumentException ("TimeStamp.format :: invalid DateTime argument"); |
|---|
| 141 | 141 | |
|---|
| 142 | 142 | // convert time to field values |
|---|
| … | … | |
| 160 | 160 | |
|---|
| 161 | 161 | Parse provided input and return a UTC epoch time. A return value |
|---|
| 162 | | of Time.max indicated a parse-failure. |
|---|
| | 162 | of DateTime.max indicated a parse-failure. |
|---|
| 163 | 163 | |
|---|
| 164 | 164 | An option is provided to return the count of characters parsed - |
|---|
| … | … | |
| 167 | 167 | ******************************************************************************/ |
|---|
| 168 | 168 | |
|---|
| 169 | | Time parse(T) (T[] src, uint* ate = null) |
|---|
| | 169 | DateTime parse(T) (T[] src, uint* ate = null) |
|---|
| 170 | 170 | { |
|---|
| 171 | 171 | int len; |
|---|
| 172 | | Time value; |
|---|
| | 172 | DateTime value; |
|---|
| 173 | 173 | |
|---|
| 174 | 174 | if ((len = rfc1123 (src, value)) > 0 || |
|---|
| … | … | |
| 181 | 181 | } |
|---|
| 182 | 182 | |
|---|
| 183 | | return Time.max; |
|---|
| | 183 | return DateTime.max; |
|---|
| 184 | 184 | } |
|---|
| 185 | 185 | |
|---|
| … | … | |
| 194 | 194 | ******************************************************************************/ |
|---|
| 195 | 195 | |
|---|
| 196 | | int rfc1123(T) (T[] src, inout Time value) |
|---|
| | 196 | int rfc1123(T) (T[] src, inout DateTime value) |
|---|
| 197 | 197 | { |
|---|
| 198 | 198 | Date date; |
|---|
| … | … | |
| 234 | 234 | ******************************************************************************/ |
|---|
| 235 | 235 | |
|---|
| 236 | | int rfc850(T) (T[] src, inout Time value) |
|---|
| | 236 | int rfc850(T) (T[] src, inout DateTime value) |
|---|
| 237 | 237 | { |
|---|
| 238 | 238 | Date date; |
|---|
| … | … | |
| 280 | 280 | ******************************************************************************/ |
|---|
| 281 | 281 | |
|---|
| 282 | | int asctime(T) (T[] src, inout Time value) |
|---|
| | 282 | int asctime(T) (T[] src, inout DateTime value) |
|---|
| 283 | 283 | { |
|---|
| 284 | 284 | Date date; |
|---|
| … | … | |
| 318 | 318 | ******************************************************************************/ |
|---|
| 319 | 319 | |
|---|
| 320 | | int dostime(T) (T[] src, inout Time value) |
|---|
| | 320 | int dostime(T) (T[] src, inout DateTime value) |
|---|
| 321 | 321 | { |
|---|
| 322 | 322 | Date date; |
|---|
| … | … | |
| 364 | 364 | ******************************************************************************/ |
|---|
| 365 | 365 | |
|---|
| 366 | | int iso8601(T) (T[] src, inout Time value) |
|---|
| | 366 | int iso8601(T) (T[] src, inout DateTime value) |
|---|
| 367 | 367 | { |
|---|
| 368 | 368 | Date date; |
|---|
| r2878 |
r2900 |
|
| 414 | 414 | else |
|---|
| 415 | 415 | { |
|---|
| 416 | | auto minutes = cast(int) (WallClock.zone / Time.TicksPerMinute); |
|---|
| | 416 | auto minutes = cast(int) (WallClock.zone.minutes); |
|---|
| 417 | 417 | if (minutes < 0) |
|---|
| 418 | 418 | minutes = -minutes, result ~= '-'; |
|---|
| r2878 |
r2900 |
|
| 50 | 50 | private char[] msg, |
|---|
| 51 | 51 | name; |
|---|
| 52 | | private Time time; |
|---|
| | 52 | private DateTime time; |
|---|
| 53 | 53 | private Level level; |
|---|
| 54 | 54 | private IHierarchy hierarchy; |
|---|
| 55 | 55 | |
|---|
| 56 | 56 | // timestamps |
|---|
| 57 | | private static Time beginTime; |
|---|
| | 57 | private static DateTime beginTime; |
|---|
| 58 | 58 | |
|---|
| 59 | 59 | // scratch buffer for constructing output strings |
|---|
| … | … | |
| 153 | 153 | |
|---|
| 154 | 154 | QueryPerformanceCounter (&timerStart); |
|---|
| 155 | | multiplier = 10_000_000.0 / freq; |
|---|
| | 155 | multiplier = cast(double)TimeSpan.second.ticks / freq; |
|---|
| 156 | 156 | beginTime = Clock.now; |
|---|
| 157 | 157 | |
|---|
| … | … | |
| 165 | 165 | ***********************************************************************/ |
|---|
| 166 | 166 | |
|---|
| 167 | | final static Time startedAt () |
|---|
| | 167 | final static DateTime startedAt () |
|---|
| 168 | 168 | { |
|---|
| 169 | 169 | return beginTime; |
|---|
| … | … | |
| 176 | 176 | ***********************************************************************/ |
|---|
| 177 | 177 | |
|---|
| 178 | | final static Time timer () |
|---|
| | 178 | final static DateTime timer () |
|---|
| 179 | 179 | { |
|---|
| 180 | 180 | version (Posix) |
|---|
| … | … | |
| 188 | 188 | |
|---|
| 189 | 189 | QueryPerformanceCounter (&now); |
|---|
| 190 | | return cast(Time) ((now - timerStart) * multiplier + beginTime); |
|---|
| | 190 | return beginTime + TimeSpan(cast(long)((now - timerStart) * multiplier)); |
|---|
| 191 | 191 | } |
|---|
| 192 | 192 | } |
|---|
| … | … | |
| 299 | 299 | ***********************************************************************/ |
|---|
| 300 | 300 | |
|---|
| 301 | | final Time getTime () |
|---|
| 302 | | { |
|---|
| 303 | | return cast(Time) (time - beginTime); |
|---|
| | 301 | final TimeSpan getTime () |
|---|
| | 302 | { |
|---|
| | 303 | return time - beginTime; |
|---|
| 304 | 304 | } |
|---|
| 305 | 305 | |
|---|
| … | … | |
| 310 | 310 | ***********************************************************************/ |
|---|
| 311 | 311 | |
|---|
| 312 | | final Time getEpochTime () |
|---|
| | 312 | final DateTime getEpochTime () |
|---|
| 313 | 313 | { |
|---|
| 314 | 314 | return time; |
|---|
| r2809 |
r2900 |
|
| 15 | 15 | private import tango.util.log.Event; |
|---|
| 16 | 16 | |
|---|
| 17 | | private import tango.core.Type : Time; |
|---|
| | 17 | private import tango.core.TimeSpan; |
|---|
| | 18 | |
|---|
| | 19 | private import tango.util.time.DateTime; |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | /******************************************************************************* |
|---|
| … | … | |
| 64 | 66 | ***********************************************************************/ |
|---|
| 65 | 67 | |
|---|
| 66 | | final char[] toMilli (char[] s, Time time) |
|---|
| | 68 | final char[] toMilli (char[] s, TimeSpan time) |
|---|
| 67 | 69 | { |
|---|
| 68 | 70 | assert (s.length > 0); |
|---|
| 69 | | time /= time.TicksPerMillisecond; |
|---|
| | 71 | long ms = time.milliseconds; |
|---|
| 70 | 72 | |
|---|
| 71 | 73 | int len = s.length; |
|---|
| 72 | 74 | do { |
|---|
| 73 | | s[--len] = time % 10 + '0'; |
|---|
| 74 | | time /= 10; |
|---|
| 75 | | } while (time && len); |
|---|
| | 75 | s[--len] = ms % 10 + '0'; |
|---|
| | 76 | ms /= 10; |
|---|
| | 77 | } while (ms && len); |
|---|
| 76 | 78 | return s[len..s.length]; |
|---|
| | 79 | } |
|---|
| | 80 | |
|---|
| | 81 | final char[] toMilli (char[] s, DateTime time) |
|---|
| | 82 | { |
|---|
| | 83 | return toMilli(s, TimeSpan(time.ticks)); |
|---|
| 77 | 84 | } |
|---|
| 78 | 85 | } |
|---|
| r2878 |
r2900 |
|
| 22 | 22 | |
|---|
| 23 | 23 | private import tango.util.log.model.IHierarchy; |
|---|
| | 24 | |
|---|
| | 25 | private import tango.util.time.Clock; |
|---|
| 24 | 26 | |
|---|
| 25 | 27 | /******************************************************************************* |
|---|
| … | … | |
| 344 | 346 | /*********************************************************************** |
|---|
| 345 | 347 | |
|---|
| 346 | | Get number of milliseconds since this application started |
|---|
| 347 | | |
|---|
| 348 | | ***********************************************************************/ |
|---|
| 349 | | |
|---|
| 350 | | final Time runtime () |
|---|
| 351 | | { |
|---|
| 352 | | return Event.startedAt; |
|---|
| | 348 | Get time since this application started |
|---|
| | 349 | |
|---|
| | 350 | ***********************************************************************/ |
|---|
| | 351 | |
|---|
| | 352 | final TimeSpan runtime () |
|---|
| | 353 | { |
|---|
| | 354 | return Clock.now - Event.startedAt; |
|---|
| 353 | 355 | } |
|---|
| 354 | 356 | |
|---|
| r2809 |
r2900 |
|
| 17 | 17 | |
|---|
| 18 | 18 | private import tango.util.log.model.ILevel; |
|---|
| | 19 | |
|---|
| | 20 | private import tango.core.TimeSpan; |
|---|
| 19 | 21 | |
|---|
| 20 | 22 | /******************************************************************************* |
|---|
| … | … | |
| 249 | 251 | ***********************************************************************/ |
|---|
| 250 | 252 | |
|---|
| 251 | | abstract Time runtime (); |
|---|
| | 253 | abstract TimeSpan runtime (); |
|---|
| 252 | 254 | } |
|---|
| r2809 |
r2900 |
|
| 21 | 21 | private import tango.util.log.Appender, |
|---|
| 22 | 22 | tango.util.log.FileAppender; |
|---|
| | 23 | |
|---|
| | 24 | private import tango.util.time.DateTime; |
|---|
| 23 | 25 | |
|---|
| 24 | 26 | /******************************************************************************* |
|---|
| … | … | |
| 56 | 58 | |
|---|
| 57 | 59 | char[1] x; |
|---|
| 58 | | Time mostRecent; |
|---|
| | 60 | DateTime mostRecent; |
|---|
| 59 | 61 | |
|---|
| 60 | 62 | for (int i=0; i < count; ++i) |
|---|
| r2809 |
r2900 |
|
| 19 | 19 | private import tango.core.Exception; |
|---|
| 20 | 20 | |
|---|
| 21 | | public import tango.core.Type : Time; |
|---|
| | 21 | public import tango.core.TimeSpan; |
|---|
| | 22 | |
|---|
| | 23 | public import tango.util.time.DateTime; |
|---|
| 22 | 24 | |
|---|
| 23 | 25 | /****************************************************************************** |
|---|
| … | … | |
| 25 | 27 | Exposes UTC time relative to Jan 1st, 1 AD. These values are |
|---|
| 26 | 28 | based upon a clock-tick of 100ns, giving them a span of greater |
|---|
| 27 | | than 10,000 years. Units of Time are the foundation of most time |
|---|
| 28 | | and date functionality in Tango. |
|---|
| | 29 | than 10,000 years. These units of time are the foundation of most |
|---|
| | 30 | time and date functionality in Tango. |
|---|
| 29 | 31 | |
|---|
| 30 | 32 | Interval is another type of time period, used for measuring a |
|---|
| … | … | |
| 45 | 47 | ***************************************************************/ |
|---|
| 46 | 48 | |
|---|
| 47 | | static Time now () |
|---|
| | 49 | static DateTime now () |
|---|
| 48 | 50 | { |
|---|
| 49 | 51 | FILETIME fTime = void; |
|---|
| … | … | |
| 67 | 69 | Set fields to represent the provided UTC time. Note |
|---|
| 68 | 70 | that the conversion is limited by the underlying OS, |
|---|
| 69 | | and will fail to operate correctly with Time values |
|---|
| 70 | | beyond the domain. On Win32 the earliest representable |
|---|
| 71 | | date is 1601. On linux it is 1970. Both systems have |
|---|
| 72 | | limitations upon future dates also. Date is limited |
|---|
| 73 | | to millisecond accuracy at best. |
|---|
| 74 | | |
|---|
| 75 | | ***************************************************************/ |
|---|
| 76 | | |
|---|
| 77 | | static Date toDate (Time time) |
|---|
| | 71 | and will fail to operate correctly with DateTime |
|---|
| | 72 | values beyond the domain. On Win32 the earliest |
|---|
| | 73 | representable date is 1601. On linux it is 1970. Both |
|---|
| | 74 | systems have limitations upon future dates also. Date |
|---|
| | 75 | is limited to millisecond accuracy at best. |
|---|
| | 76 | |
|---|
| | 77 | ***************************************************************/ |
|---|
| | 78 | |
|---|
| | 79 | static Date toDate (DateTime time) |
|---|
| 78 | 80 | { |
|---|
| 79 | 81 | Date date = void; |
|---|
| … | … | |
| 96 | 98 | /*************************************************************** |
|---|
| 97 | 99 | |
|---|
| 98 | | Convert Date fields to Time |
|---|
| | 100 | Convert Date fields to DateTime |
|---|
| 99 | 101 | |
|---|
| 100 | 102 | Note that the conversion is limited by the underlying |
|---|
| 101 | | OS, and will not operate correctly with Time values |
|---|
| 102 | | beyond the domain. On Win32 the earliest representable |
|---|
| 103 | | date is 1601. On linux it is 1970. Both systems have |
|---|
| 104 | | limitations upon future dates also. Date is limited |
|---|
| 105 | | to millisecond accuracy at best. |
|---|
| 106 | | |
|---|
| 107 | | ***************************************************************/ |
|---|
| 108 | | |
|---|
| 109 | | static Time fromDate (inout Date date) |
|---|
| | 103 | OS, and will not operate correctly with DateTime |
|---|
| | 104 | values beyond the domain. On Win32 the earliest |
|---|
| | 105 | representable date is 1601. On linux it is 1970. Both |
|---|
| | 106 | systems have limitations upon future dates also. Date |
|---|
| | 107 | is limited to millisecond accuracy at best. |
|---|
| | 108 | |
|---|
| | 109 | ***************************************************************/ |
|---|
| | 110 | |
|---|
| | 111 | static DateTime fromDate (inout Date date) |
|---|
| 110 | 112 | { |
|---|
| 111 | 113 | SYSTEMTIME sTime = void; |
|---|
| … | … | |
| 127 | 129 | /*************************************************************** |
|---|
| 128 | 130 | |
|---|
| 129 | | Convert FILETIME to a Time |
|---|
| 130 | | |
|---|
| 131 | | ***************************************************************/ |
|---|
| 132 | | |
|---|
| 133 | | package static Time convert (FILETIME time) |
|---|
| 134 | | { |
|---|
| 135 | | return cast(Time) (Time.TicksTo1601 + *cast(ulong*) &time); |
|---|
| 136 | | } |
|---|
| 137 | | |
|---|
| 138 | | /*************************************************************** |
|---|
| 139 | | |
|---|
| 140 | | Convert Time to a FILETIME |
|---|
| 141 | | |
|---|
| 142 | | ***************************************************************/ |
|---|
| 143 | | |
|---|
| 144 | | package static FILETIME convert (Time span) |
|---|
| | 131 | Convert FILETIME to a DateTime |
|---|
| | 132 | |
|---|
| | 133 | ***************************************************************/ |
|---|
| | 134 | |
|---|
| | 135 | package static DateTime convert (FILETIME time) |
|---|
| | 136 | { |
|---|
| | 137 | ulong t = *cast(ulong*)&time; |
|---|
| | 138 | t *= 100 / TimeSpan.NanosecondsPerTick; |
|---|
| | 139 | return DateTime.epoch1601 + TimeSpan(t); |
|---|
| | 140 | } |
|---|
| | 141 | |
|---|
| | 142 | /*************************************************************** |
|---|
| | 143 | |
|---|
| | 144 | Convert DateTime to a FILETIME |
|---|
| | 145 | |
|---|
| | 146 | ***************************************************************/ |
|---|
| | 147 | |
|---|
| | 148 | package static FILETIME convert (DateTime dt) |
|---|
| 145 | 149 | { |
|---|
| 146 | 150 | FILETIME time = void; |
|---|
| 147 | 151 | |
|---|
| 148 | | span -= span.TicksTo1601; |
|---|
| 149 | | assert (span >= 0); |
|---|
| 150 | | *cast(long*) &time.dwLowDateTime = span; |
|---|
| | 152 | TimeSpan span = dt - DateTime.epoch1601; |
|---|
| | 153 | assert (span >= TimeSpan.zero); |
|---|
| | 154 | *cast(long*) &time.dwLowDateTime = span.ticks; |
|---|
| 151 | 155 | return time; |
|---|
| 152 | 156 | } |
|---|
| … | … | |
| 161 | 165 | ***************************************************************/ |
|---|
| 162 | 166 | |
|---|
| 163 | | static Time now () |
|---|
| | 167 | static DateTime now () |
|---|
| 164 | 168 | { |
|---|
| 165 | 169 | timeval tv = void; |
|---|
| 166 | 170 | if (gettimeofday (&tv, null)) |
|---|
| 167 | | throw new PlatformException ("Time.utc :: Posix timer is not available"); |
|---|
| | 171 | throw new PlatformException ("Clock.now :: Posix timer is not available"); |
|---|
| 168 | 172 | |
|---|
| 169 | 173 | return convert (tv); |
|---|
| … | … | |
| 185 | 189 | Set fields to represent the provided UTC time. Note |
|---|
| 186 | 190 | that the conversion is limited by the underlying OS, |
|---|
| 187 | | and will fail to operate correctly with Time values |
|---|
| 188 | | beyond the domain. On Win32 the earliest representable |
|---|
| 189 | | date is 1601. On linux it is 1970. Both systems have |
|---|
| 190 | | limitations upon future dates also. Date is limited |
|---|
| 191 | | to millisecond accuracy at best. |
|---|
| | 191 | and will fail to operate correctly with DateTime |
|---|
| | 192 | values beyond the domain. On Win32 the earliest |
|---|
| | 193 | representable date is 1601. On linux it is 1970. Both |
|---|
| | 194 | systems have limitations upon future dates also. Date |
|---|
| | 195 | is limited to millisecond accuracy at best. |
|---|
| 192 | 196 | |
|---|
| 193 | 197 | **************************************************************/ |
|---|
| 194 | 198 | |
|---|
| 195 | | static Date toDate (Time time) |
|---|
| | 199 | static Date toDate (DateTime time) |
|---|
| 196 | 200 | { |
|---|
| 197 | 201 | Date date = void; |
|---|
| … | … | |
| 214 | 218 | /*************************************************************** |
|---|
| 215 | 219 | |
|---|
| 216 | | Convert Date fields to Time |
|---|
| | 220 | Convert Date fields to DateTime |
|---|
| 217 | 221 | |
|---|
| 218 | 222 | Note that the conversion is limited by the underlying |
|---|
| 219 | | OS, and will not operate correctly with Time values |
|---|
| 220 | | beyond the domain. On Win32 the earliest representable |
|---|
| 221 | | date is 1601. On linux it is 1970. Both systems have |
|---|
| 222 | | limitations upon future dates also. Date is limited |
|---|
| 223 | | to millisecond accuracy at best. |
|---|
| 224 | | |
|---|
| 225 | | ***************************************************************/ |
|---|
| 226 | | |
|---|
| 227 | | static Time fromDate (inout Date date) |
|---|
| | 223 | OS, and will not operate correctly with DateTime |
|---|
| | 224 | values beyond the domain. On Win32 the earliest |
|---|
| | 225 | representable date is 1601. On linux it is 1970. Both |
|---|
| | 226 | systems have limitations upon future dates also. Date |
|---|
| | 227 | is limited to millisecond accuracy at best. |
|---|
| | 228 | |
|---|
| | 229 | ***************************************************************/ |
|---|
| | 230 | |
|---|
| | 231 | static DateTime fromDate (inout Date date) |
|---|
| 228 | 232 | { |
|---|
| 229 | 233 | tm t = void; |
|---|
| … | … | |
| 237 | 241 | |
|---|
| 238 | 242 | auto seconds = timegm (&t); |
|---|
| 239 | | return cast(Time) (Time.TicksTo1970 + |
|---|
| 240 | | Time.TicksPerSecond * seconds + |
|---|
| 241 | | Time.TicksPerMillisecond * date.ms); |
|---|
| 242 | | } |
|---|
| 243 | | |
|---|
| 244 | | /*************************************************************** |
|---|
| 245 | | |
|---|
| 246 | | Convert timeval to a Time |
|---|
| 247 | | |
|---|
| 248 | | ***************************************************************/ |
|---|
| 249 | | |
|---|
| 250 | | package static Time convert (inout timeval tv) |
|---|
| 251 | | { |
|---|
| 252 | | return cast(Time) (Time.TicksTo1970 + (1_000_000L * tv.tv_sec + tv.tv_usec) * 10); |
|---|
| 253 | | } |
|---|
| 254 | | |
|---|
| 255 | | /*************************************************************** |
|---|
| 256 | | |
|---|
| 257 | | Convert Time to a timeval |
|---|
| 258 | | |
|---|
| 259 | | ***************************************************************/ |
|---|
| 260 | | |
|---|
| 261 | | package static timeval convert (Time time) |
|---|
| | 243 | return DateTime.epoch1970 + TimeSpan.seconds(seconds) + TimeSpan.milliseconds(date.ms); |
|---|
| | 244 | } |
|---|
| | 245 | |
|---|
| | 246 | /*************************************************************** |
|---|
| | 247 | |
|---|
| | 248 | Convert timeval to a DateTime |
|---|
| | 249 | |
|---|
| | 250 | ***************************************************************/ |
|---|
| | 251 | |
|---|
| | 252 | package static DateTime convert (inout timeval tv) |
|---|
| | 253 | { |
|---|
| | 254 | return DateTime.epoch1970 + TimeSpan.seconds(tv.tv_sec) + TimeSpan.microseconds(tv.tv_usec); |
|---|
| | 255 | } |
|---|
| | 256 | |
|---|
| | 257 | /*************************************************************** |
|---|
| | 258 | |
|---|
| | 259 | Convert DateTime to a timeval |
|---|
| | 260 | |
|---|
| | 261 | ***************************************************************/ |
|---|
| | 262 | |
|---|
| | 263 | package static timeval convert (DateTime time) |
|---|
| 262 | 264 | { |
|---|
| 263 | 265 | timeval tv = void; |
|---|
| 264 | 266 | |
|---|
| 265 | | time -= time.TicksTo1970; |
|---|
| 266 | | assert (time >= 0); |
|---|
| 267 | | time /= 10L; |
|---|
| 268 | | tv.tv_sec = cast (typeof(tv.tv_sec)) (time / 1_000_000L); |
|---|
| 269 | | tv.tv_usec = cast (typeof(tv.tv_usec)) (time - 1_000_000L * tv.tv_sec); |
|---|
| | 267 | TimeSpan span = time - time.epoch1970; |
|---|
| | 268 | assert (span >= TimeSpan.zero); |
|---|
| | 269 | tv.tv_sec = span.seconds; |
|---|
| | 270 | tv.tv_usec = span.microseconds % 1_000_000L; |
|---|
| 270 | 271 | return tv; |
|---|
| 271 | 272 | } |
|---|
| … | … | |
| 282 | 283 | assert (Clock.convert(Clock.convert(time)) is time); |
|---|
| 283 | 284 | |
|---|
| 284 | | time = cast(Time) ((time / Time.TicksPerSecond) * Time.TicksPerSecond); |
|---|
| | 285 | time -= TimeSpan(time.ticks % TimeSpan.second.ticks); |
|---|
| 285 | 286 | auto date = Clock.toDate(time); |
|---|
| 286 | 287 | |
|---|
| r2897 |
r2900 |
|
| 16 | 16 | private import tango.util.time.Clock, |
|---|
| 17 | 17 | tango.util.time.WallClock; |
|---|
| | 18 | |
|---|
| | 19 | public import tango.core.TimeSpan; |
|---|
| 18 | 20 | |
|---|
| 19 | 21 | /****************************************************************************** |
|---|
| … | … | |
| 25 | 27 | 9999 AD. |
|---|
| 26 | 28 | |
|---|
| 27 | | Time values are measured in 100-nanosecond intervals, or ticks. |
|---|
| | 29 | DateTime values are measured in 100-nanosecond intervals, or ticks. |
|---|
| 28 | 30 | A date value is the number of ticks that have elapsed since |
|---|
| 29 | 31 | 12:00:00 midnight on January 1, 0001 AD in the Gregorian |
|---|
| … | … | |
| 56 | 58 | |
|---|
| 57 | 59 | /// Represents the smallest and largest DateTime value. |
|---|
| 58 | | public static final DateTime min = {0}, |
|---|
| 59 | | max = {Time.DaysTo10000 * Time.TicksPerDay - 1}; |
|---|
| | 60 | public static const DateTime min = {0}, |
|---|
| | 61 | max = {(TimeSpan.DaysPer400Years * 25 - 366) * TimeSpan.TicksPerDay - 1}, |
|---|
| | 62 | epoch1601 = {TimeSpan.DaysPer400Years * 4 * TimeSpan.TicksPerDay}, |
|---|
| | 63 | epoch1970 = {TimeSpan.DaysPer400Years * 4 * TimeSpan.TicksPerDay + TimeSpan.TicksPerSecond * 11644473600L}; |
|---|
| 60 | 64 | |
|---|
| 61 | 65 | private static final int[] DaysToMonthCommon = |
|---|
| … | … | |
| 105 | 109 | static DateTime opCall (long ticks) |
|---|
| 106 | 110 | { |
|---|
| 107 | | DateTime d; |
|---|
| 108 | | d.ticks = ticks; |
|---|
| | 111 | DateTime d = {ticks}; |
|---|
| 109 | 112 | return d; |
|---|
| 110 | | } |
|---|
| 111 | | |
|---|
| 112 | | /********************************************************************** |
|---|
| 113 | | |
|---|
| 114 | | $(I Constructor.) Initializes a new instance of the |
|---|
| 115 | | DateTime struct to the specified Time. |
|---|
| 116 | | |
|---|
| 117 | | Params: time = A Tango time expressed in units of 100 |
|---|
| 118 | | nanoseconds. |
|---|
| 119 | | |
|---|
| 120 | | **********************************************************************/ |
|---|
| 121 | | |
|---|
| 122 | | static DateTime opCall (Time time) |
|---|
| 123 | | { |
|---|
| 124 | | return opCall (cast(long) time); |
|---|
| 125 | 113 | } |
|---|
| 126 | 114 | |
|---|
| … | … | |
| 159 | 147 | static DateTime now () |
|---|
| 160 | 148 | { |
|---|
| 161 | | return DateTime (WallClock.now); |
|---|
| | 149 | return WallClock.now; |
|---|
| 162 | 150 | } |
|---|
| 163 | 151 | |
|---|
| … | … | |
| 174 | 162 | static DateTime utc () |
|---|
| 175 | 163 | { |
|---|
| 176 | | return DateTime (Clock.now); |
|---|
| | 164 | return Clock.now; |
|---|
| 177 | 165 | } |
|---|
| 178 | 166 | |
|---|
| … | … | |
| 199 | 187 | int opCmp (DateTime t) |
|---|
| 200 | 188 | { |
|---|
| 201 | | if (ticks < t.ticks) |
|---|
| 202 | | return -1; |
|---|
| 203 | | else |
|---|
| 204 | | if (ticks > t.ticks) |
|---|
| 205 | | return 1; |
|---|
| 206 | | return 0; |
|---|
| | 189 | return cast(int)((ticks - t.ticks) >>> 32); |
|---|
| 207 | 190 | } |
|---|
| 208 | 191 | |
|---|
| … | … | |
| 212 | 195 | returning a new date and time. |
|---|
| 213 | 196 | |
|---|
| 214 | | Params: t = A DateTime value. |
|---|
| | 197 | Params: t = A TimeSpan value. |
|---|
| 215 | 198 | Returns: A DateTime that is the sum of this instance and t. |
|---|
| 216 | 199 | |
|---|
| 217 | 200 | **********************************************************************/ |
|---|
| 218 | 201 | |
|---|
| 219 | | DateTime opAdd (DateTime t) |
|---|
| | 202 | DateTime opAdd (TimeSpan t) |
|---|
| 220 | 203 | { |
|---|
| 221 | 204 | return DateTime (ticks + t.ticks); |
|---|
| … | … | |
| 227 | 210 | the result to this instance. |
|---|
| 228 | 211 | |
|---|
| 229 | | Params: t = A DateTime value. |
|---|
| | 212 | Params: t = A TimeSpan value. |
|---|
| 230 | 213 | Returns: The current DateTime instance, with t added to the |
|---|
| 231 | 214 | date and time. |
|---|
| … | … | |
| 233 | 216 | **********************************************************************/ |
|---|
| 234 | 217 | |
|---|
| 235 | | DateTime opAddAssign (DateTime t) |
|---|
| | 218 | DateTime opAddAssign (TimeSpan t) |
|---|
| 236 | 219 | { |
|---|
| 237 | 220 | ticks += t.ticks; |
|---|
| … | … | |
| 244 | 227 | returning a new date and time. |
|---|
| 245 | 228 | |
|---|
| 246 | | Params: t = A DateTime value. |
|---|
| | 229 | Params: t = A TimeSpan value. |
|---|
| 247 | 230 | Returns: A DateTime whose value is the value of this instance |
|---|
| 248 | 231 | minus the value of t. |
|---|
| … | … | |
| 250 | 233 | **********************************************************************/ |
|---|
| 251 | 234 | |
|---|
| 252 | | DateTime opSub (DateTime t) |
|---|
| | 235 | DateTime opSub (TimeSpan t) |
|---|
| 253 | 236 | { |
|---|
| 254 | 237 | return DateTime (ticks - t.ticks); |
|---|
| | 238 | } |
|---|
| | 239 | |
|---|
| | 240 | /********************************************************************** |
|---|
| | 241 | |
|---|
| | 242 | Returns a time span which represents the difference in time |
|---|
| | 243 | between this and the given DateTime. |
|---|
| | 244 | |
|---|
| | 245 | Params: t = A DateTime value. |
|---|
| | 246 | Returns: A TimeSpan which represents the difference between |
|---|
| | 247 | this and t. |
|---|
| | 248 | |
|---|
| | 249 | **********************************************************************/ |
|---|
| | 250 | |
|---|
| | 251 | TimeSpan opSub (DateTime t) |
|---|
| | 252 | { |
|---|
| | 253 | return TimeSpan(ticks - t.ticks); |
|---|
| 255 | 254 | } |
|---|
| 256 | 255 | |
|---|
| … | … | |
| 260 | 259 | assigning the result to this instance. |
|---|
| 261 | 260 | |
|---|
| 262 | | Params: t = A DateTime value. |
|---|
| | 261 | Params: t = A TimeSpan value. |
|---|
| 263 | 262 | Returns: The current DateTime instance, with t subtracted |
|---|
| 264 | 263 | from the date and time. |
|---|
| … | … | |
| 266 | 265 | **********************************************************************/ |
|---|
| 267 | 266 | |
|---|
| 268 | | DateTime opSubAssign (DateTime t) |
|---|
| | 267 | DateTime opSubAssign (TimeSpan t) |
|---|
| 269 | 268 | { |
|---|
| 270 | 269 | ticks -= t.ticks; |
|---|
| … | … | |
| 276 | 275 | Adds the specified number of ticks to the _value of this |
|---|
| 277 | 276 | instance. |
|---|
| | 277 | |
|---|
| | 278 | Deprecated: use x + TimeSpan(value) instead. |
|---|
| 278 | 279 | |
|---|
| 279 | 280 | Params: value = The number of ticks to add. |
|---|
| … | … | |
| 283 | 284 | **********************************************************************/ |
|---|
| 284 | 285 | |
|---|
| 285 | | DateTime addTicks (long value) |
|---|
| | 286 | deprecated DateTime addTicks (long value) |
|---|
| 286 | 287 | { |
|---|
| 287 | 288 | return DateTime (ticks + value); |
|---|
| … | … | |
| 291 | 292 | Adds the specified number of hours to the _value of this |
|---|
| 292 | 293 | instance. |
|---|
| | 294 | |
|---|
| | 295 | Deprecated: use x + TimeSpan.hours(value) instead. |
|---|
| 293 | 296 | |
|---|
| 294 | 297 | Params: value = The number of hours to add. |
|---|
| … | … | |
| 299 | 302 | **********************************************************************/ |
|---|
| 300 | 303 | |
|---|
| 301 | | DateTime addHours (int value) |
|---|
| 302 | | { |
|---|
| 303 | | return addMilliseconds (value * Time.MillisPerHour); |
|---|
| | 304 | deprecated DateTime addHours (int value) |
|---|
| | 305 | { |
|---|
| | 306 | return *this + TimeSpan.hours(value); |
|---|
| 304 | 307 | } |
|---|
| 305 | 308 | |
|---|
| … | … | |
| 308 | 311 | Adds the specified number of minutes to the _value of this |
|---|
| 309 | 312 | instance. |
|---|
| | 313 | |
|---|
| | 314 | Deprecated: use x + TimeSpan.minutes(value); |
|---|
| 310 | 315 | |
|---|
| 311 | 316 | Params: value = The number of minutes to add. |
|---|
| … | … | |
| 316 | 321 | **********************************************************************/ |
|---|
| 317 | 322 | |
|---|
| 318 | | DateTime addMinutes (int value) |
|---|
| 319 | | { |
|---|
| 320 | | return addMilliseconds (value * Time.MillisPerMinute); |
|---|
| | 323 | deprecated DateTime addMinutes (int value) |
|---|
| | 324 | { |
|---|
| | 325 | return *this + TimeSpan.minutes(value); |
|---|
| 321 | 326 | } |
|---|
| 322 | 327 | |
|---|
| … | … | |
| 325 | 330 | Adds the specified number of seconds to the _value of this |
|---|
| 326 | 331 | instance. |
|---|
| | 332 | |
|---|
| | 333 | Deprecated: use x + TimeSpan.seconds(value) instead. |
|---|
| 327 | 334 | |
|---|
| 328 | 335 | Params: value = The number of seconds to add. |
|---|
| … | … | |
| 333 | 340 | **********************************************************************/ |
|---|
| 334 | 341 | |
|---|
| 335 | | DateTime addSeconds (int value) |
|---|
| 336 | | { |
|---|
| 337 | | return addMilliseconds (value * Time.MillisPerSecond); |
|---|
| | 342 | deprecated DateTime addSeconds (int value) |
|---|
| | 343 | { |
|---|
| | 344 | return *this + TimeSpan.seconds(value); |
|---|
| 338 | 345 | } |
|---|
| 339 | 346 | |
|---|
| … | … | |
| 342 | 349 | Adds the specified number of milliseconds to the _value of |
|---|
| 343 | 350 | this instance. |
|---|
| | 351 | |
|---|
| | 352 | Deprecated: use x + TimeSpan.milliseconds(value) instead. |
|---|
| 344 | 353 | |
|---|
| 345 | 354 | Params: value = The number of milliseconds to add. |
|---|
| … | … | |
| 350 | 359 | **********************************************************************/ |
|---|
| 351 | 360 | |
|---|
| 352 | | DateTime addMilliseconds (long value) |
|---|
| 353 | | { |
|---|
| 354 | | return addTicks (value * Time.TicksPerMillisecond); |
|---|
| | 361 | deprecated DateTime addMilliseconds (long value) |
|---|
| | 362 | { |
|---|
| | 363 | return *this + TimeSpan.milliseconds(value); |
|---|
| 355 | 364 | } |
|---|
| 356 | 365 | |
|---|
| … | … | |
| 359 | 368 | Adds the specified number of days to the _value of this |
|---|
| 360 | 369 | instance. |
|---|
| | 370 | |
|---|
| | 371 | Deprecated: use x + TimeSpan.days(value) instead. |
|---|
| 361 | 372 | |
|---|
| 362 | 373 | Params: value = The number of days to add. |
|---|
| … | … | |
| 367 | 378 | **********************************************************************/ |
|---|
| 368 | 379 | |
|---|
| 369 | | DateTime addDays (int value) |
|---|
| 370 | | { |
|---|
| 371 | | return addMilliseconds (value * Time.MillisPerDay); |
|---|
| | 380 | deprecated DateTime addDays (int value) |
|---|
| | 381 | { |
|---|
| | 382 | return *this + TimeSpan.days(value); |
|---|
| 372 | 383 | } |
|---|
| 373 | 384 | |
|---|
| … | … | |
| 405 | 416 | day = maxDays; |
|---|
| 406 | 417 | |
|---|
| 407 | | return DateTime (getDateTicks(year, month, day) + (ticks % Time.TicksPerDay)); |
|---|
| | 418 | return DateTime (getDateTicks(year, month, day) + (ticks % TimeSpan.day.ticks)); |
|---|
| 408 | 419 | } |
|---|
| 409 | 420 | |
|---|
| … | … | |
| 487 | 498 | DayOfWeek dayOfWeek () |
|---|
| 488 | 499 | { |
|---|
| 489 | | return cast(DayOfWeek) ((ticks / Time.TicksPerDay + 1) % 7); |
|---|
| | 500 | return cast(DayOfWeek) ((ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| 490 | 501 | } |
|---|
| 491 | 502 | |
|---|
| … | … | |
| 500 | 511 | int hour () |
|---|
| 501 | 512 | { |
|---|
| 502 | | return cast(int) ((ticks / Time.TicksPerHour) % 24); |
|---|
| | 513 | return cast(int) ((ticks / TimeSpan.hour.ticks) % 24); |
|---|
| 503 | 514 | } |
|---|
| 504 | 515 | |
|---|
| … | … | |
| 513 | 524 | int minute () |
|---|
| 514 | 525 | { |
|---|
| 515 | | return cast(int) ((ticks / Time.TicksPerMinute) % 60); |
|---|
| | 526 | return cast(int) ((ticks / TimeSpan.minute.ticks) % 60); |
|---|
| 516 | 527 | } |
|---|
| 517 | 528 | |
|---|
| … | … | |
| 526 | 537 | int second () |
|---|
| 527 | 538 | { |
|---|
| 528 | | return cast(int) ((ticks / Time.TicksPerSecond) % 60); |
|---|
| | 539 | return cast(int) ((ticks / TimeSpan.second.ticks) % 60); |
|---|
| 529 | 540 | } |
|---|
| 530 | 541 | |
|---|
| … | … | |
| 540 | 551 | int millisecond () |
|---|
| 541 | 552 | { |
|---|
| 542 | | return cast(int) ((ticks / Time.TicksPerMillisecond) % 1000); |
|---|
| | 553 | return cast(int) ((ticks / TimeSpan.ms.ticks) % 1000); |
|---|
| 543 | 554 | } |
|---|
| 544 | 555 | |
|---|
| … | … | |
| 554 | 565 | DateTime date () |
|---|
| 555 | 566 | { |
|---|
| 556 | | auto ticks = this.ticks; |
|---|
| 557 | | return DateTime (ticks - ticks % Time.TicksPerDay); |
|---|
| | 567 | return *this - timeOfDay; |
|---|
| 558 | 568 | } |
|---|
| 559 | 569 | |
|---|
| … | … | |
| 566 | 576 | **********************************************************************/ |
|---|
| 567 | 577 | |
|---|
| 568 | | DateTime timeOfDay () |
|---|
| 569 | | { |
|---|
| 570 | | return DateTime (ticks % Time.TicksPerDay); |
|---|
| 571 | | } |
|---|
| 572 | | |
|---|
| 573 | | /********************************************************************** |
|---|
| 574 | | |
|---|
| 575 | | $(I Property.) Retrieves a Time value representing the |
|---|
| 576 | | date and time of this instance. |
|---|
| 577 | | |
|---|
| 578 | | Returns: A Time represented by the date and time of this |
|---|
| | 578 | TimeSpan timeOfDay () |
|---|
| | 579 | { |
|---|
| | 580 | return TimeSpan (ticks % TimeSpan.day.ticks); |
|---|
| | 581 | } |
|---|
| | 582 | |
|---|
| | 583 | /********************************************************************** |
|---|
| | 584 | |
|---|
| | 585 | $(I Property.) Retrieves the number of ticks for this DateTime |
|---|
| | 586 | |
|---|
| | 587 | Deprecated: access ticks directly |
|---|
| | 588 | |
|---|
| | 589 | Returns: A long represented by the date and time of this |
|---|
| 579 | 590 | instance. |
|---|
| 580 | 591 | |
|---|
| 581 | 592 | **********************************************************************/ |
|---|
| 582 | 593 | |
|---|
| 583 | | Time time () |
|---|
| 584 | | { |
|---|
| 585 | | return cast(Time) ticks; |
|---|
| | 594 | deprecated long time () |
|---|
| | 595 | { |
|---|
| | 596 | return ticks; |
|---|
| 586 | 597 | } |
|---|
| 587 | 598 | |
|---|
| … | … | |
| 629 | 640 | --year; |
|---|
| 630 | 641 | return (year * 365 + year / 4 - year / 100 + year / 400 + |
|---|
| 631 | | monthDays[month - 1] + day - 1) * Time.TicksPerDay; |
|---|
| | 642 | monthDays[month - 1] + day - 1) * TimeSpan.day.ticks; |
|---|
| 632 | 643 | } |
|---|
| 633 | 644 | |
|---|
| … | … | |
| 638 | 649 | private static void splitDate (long ticks, out int year, out int month, out int day, out int dayOfYear) |
|---|
| 639 | 650 | { |
|---|
| 640 | | int numDays = cast(int) (ticks / Time.TicksPerDay); |
|---|
| 641 | | int whole400Years = numDays / cast(int) Time.DaysPer400Years; |
|---|
| 642 | | numDays -= whole400Years * cast(int) Time.DaysPer400Years; |
|---|
| 643 | | int whole100Years = numDays / cast(int) Time.DaysPer100Years; |
|---|
| | 651 | int numDays = cast(int) (ticks / TimeSpan.day.ticks); |
|---|
| | 652 | int whole400Years = numDays / cast(int) TimeSpan.DaysPer400Years; |
|---|
| | 653 | numDays -= whole400Years * cast(int) TimeSpan.DaysPer400Years; |
|---|
| | 654 | int whole100Years = numDays / cast(int) TimeSpan.DaysPer100Years; |
|---|
| 644 | 655 | if (whole100Years == 4) |
|---|
| 645 | 656 | whole100Years = 3; |
|---|
| 646 | 657 | |
|---|
| 647 | | numDays -= whole100Years * cast(int) Time.DaysPer100Years; |
|---|
| 648 | | int whole4Years = numDays / cast(int) Time.DaysPer4Years; |
|---|
| 649 | | numDays -= whole4Years * cast(int) Time.DaysPer4Years; |
|---|
| 650 | | int wholeYears = numDays / cast(int) Time.DaysPerYear; |
|---|
| | 658 | numDays -= whole100Years * cast(int) TimeSpan.DaysPer100Years; |
|---|
| | 659 | int whole4Years = numDays / cast(int) TimeSpan.DaysPer4Years; |
|---|
| | 660 | numDays -= whole4Years * cast(int) TimeSpan.DaysPer4Years; |
|---|
| | 661 | int wholeYears = numDays / cast(int) TimeSpan.DaysPerYear; |
|---|
| 651 | 662 | if (wholeYears == 4) |
|---|
| 652 | 663 | wholeYears = 3; |
|---|
| 653 | 664 | |
|---|
| 654 | 665 | year = whole400Years * 400 + whole100Years * 100 + whole4Years * 4 + wholeYears + 1; |
|---|
| 655 | | numDays -= wholeYears * Time.DaysPerYear; |
|---|
| | 666 | numDays -= wholeYears * TimeSpan.DaysPerYear; |
|---|
| 656 | 667 | dayOfYear = numDays + 1; |
|---|
| 657 | 668 | |
|---|
| … | … | |
| 700 | 711 | { |
|---|
| 701 | 712 | auto d = DateTime(10); |
|---|
| 702 | | auto e = DateTime(20); |
|---|
| | 713 | auto e = TimeSpan(20); |
|---|
| 703 | 714 | |
|---|
| 704 | 715 | return d + e; |
|---|
| r2809 |
r2900 |
|
| 17 | 17 | intervals, because I got too lazy to implement them. The functions |
|---|
| 18 | 18 | (iso8601Time, iso8601Date, and iso8601) update a Date passed instead |
|---|
| 19 | | of a Time, as does the current iso8601, because that's too limited a |
|---|
| 20 | | format. One can always convert to a Time if necessary, keeping in mind |
|---|
| 21 | | that information loss might occur if the Date is outside the interval |
|---|
| 22 | | Time can represent. |
|---|
| | 19 | of a DateTime, as does the current iso8601, because that's too limited |
|---|
| | 20 | a format. One can always convert to a DateTime if necessary, keeping |
|---|
| | 21 | in mind that information loss might occur if the Date is outside the |
|---|
| | 22 | interval DateTime can represent. |
|---|
| 23 | 23 | |
|---|
| 24 | 24 | In addition, because its dayOfWeek function only works for 1900-3-1 to |
|---|
| r2878 |
r2900 |
|
| 14 | 14 | |
|---|
| 15 | 15 | private import tango.core.Exception; |
|---|
| 16 | | |
|---|
| 17 | | public import tango.core.Type : Interval; |
|---|
| 18 | 16 | |
|---|
| 19 | 17 | /******************************************************************************* |
|---|
| … | … | |
| 47 | 45 | // ... |
|---|
| 48 | 46 | |
|---|
| 49 | | Interval i = elapsed.stop; |
|---|
| | 47 | double i = elapsed.stop; |
|---|
| 50 | 48 | --- |
|---|
| 51 | 49 | |
|---|
| … | … | |
| 68 | 66 | { |
|---|
| 69 | 67 | private ulong started; |
|---|
| 70 | | private static Interval multiplier = 1.0 / 1_000_000.0; |
|---|
| | 68 | private static double multiplier = 1.0 / 1_000_000.0; |
|---|
| 71 | 69 | |
|---|
| 72 | 70 | version (Win32) |
|---|
| 73 | | private static Interval microsecond; |
|---|
| | 71 | private static double microsecond; |
|---|
| 74 | 72 | |
|---|
| 75 | 73 | /*********************************************************************** |
|---|
| … | … | |
| 90 | 88 | ***********************************************************************/ |
|---|
| 91 | 89 | |
|---|
| 92 | | Interval stop () |
|---|
| | 90 | double stop () |
|---|
| 93 | 91 | { |
|---|
| 94 | 92 | return multiplier * (timer - started); |
|---|
| r2809 |
r2900 |
|
| 18 | 18 | tango.util.time.Clock; |
|---|
| 19 | 19 | |
|---|
| 20 | | public import tango.core.Type : Time; |
|---|
| | 20 | public import tango.core.TimeSpan; |
|---|
| | 21 | |
|---|
| | 22 | public import tango.util.time.DateTime; |
|---|
| 21 | 23 | |
|---|
| 22 | 24 | /****************************************************************************** |
|---|
| … | … | |
| 24 | 26 | Exposes wall-time relative to Jan 1st, 1 AD. These values are |
|---|
| 25 | 27 | based upon a clock-tick of 100ns, giving them a span of greater |
|---|
| 26 | | than 10,000 years. Units of Time are the foundation of most time |
|---|
| 27 | | and date functionality in Tango. |
|---|
| | 28 | than 10,000 years. These Units of time are the foundation of most |
|---|
| | 29 | time and date functionality in Tango. |
|---|
| 28 | 30 | |
|---|
| 29 | 31 | Please note that conversion between UTC and Wall time is performed |
|---|
| … | … | |
| 47 | 49 | ***************************************************************/ |
|---|
| 48 | 50 | |
|---|
| 49 | | static Time now () |
|---|
| 50 | | { |
|---|
| 51 | | return cast(Time) (Clock.now - localBias); |
|---|
| | 51 | static DateTime now () |
|---|
| | 52 | { |
|---|
| | 53 | return Clock.now - localBias; |
|---|
| 52 | 54 | } |
|---|
| 53 | 55 | |
|---|
| … | … | |
| 59 | 61 | ***************************************************************/ |
|---|
| 60 | 62 | |
|---|
| 61 | | static Time zone () |
|---|
| | 63 | static TimeSpan zone () |
|---|
| 62 | 64 | { |
|---|
| 63 | 65 | TIME_ZONE_INFORMATION tz = void; |
|---|
| 64 | 66 | |
|---|
| 65 | 67 | auto tmp = GetTimeZoneInformation (&tz); |
|---|
| 66 | | return cast(Time) (-Time.TicksPerMinute * tz.Bias); |
|---|
| | 68 | return TimeSpan.minutes(-tz.Bias); |
|---|
| 67 | 69 | } |
|---|
| 68 | 70 | |
|---|
| … | … | |
| 88 | 90 | ***************************************************************/ |
|---|
| 89 | 91 | |
|---|
| 90 | | static Date toDate (Time utc) |
|---|
| 91 | | { |
|---|
| 92 | | return Clock.toDate (cast(Time) (utc - localBias)); |
|---|
| | 92 | static Date toDate (DateTime utc) |
|---|
| | 93 | { |
|---|
| | 94 | return Clock.toDate (utc - localBias); |
|---|
| 93 | 95 | } |
|---|
| 94 | 96 | |
|---|
| … | … | |
| 99 | 101 | ***************************************************************/ |
|---|
| 100 | 102 | |
|---|
| 101 | | static Time fromDate (inout Date date) |
|---|
| 102 | | { |
|---|
| 103 | | return cast(Time) (Clock.fromDate(date) + localBias); |
|---|
| | 103 | static DateTime fromDate (inout Date date) |
|---|
| | 104 | { |
|---|
| | 105 | return (Clock.fromDate(date) + localBias); |
|---|
| 104 | 106 | } |
|---|
| 105 | 107 | |
|---|
| … | … | |
| 131 | 133 | } |
|---|
| 132 | 134 | |
|---|
| 133 | | return Time.TicksPerMinute * bias; |
|---|
| | 135 | return TimeSpan.minutes(bias); |
|---|
| 134 | 136 | } |
|---|
| 135 | 137 | } |
|---|
| … | … | |
| 143 | 145 | ***************************************************************/ |
|---|
| 144 | 146 | |
|---|
| 145 | | static Time now () |
|---|
| | 147 | static DateTime now () |
|---|
| 146 | 148 | { |
|---|
| 147 | 149 | tm t = void; |
|---|
| … | … | |
| 160 | 162 | ***************************************************************/ |
|---|
| 161 | 163 | |
|---|
| 162 | | static Time zone () |
|---|
| | 164 | static TimeSpan zone () |
|---|
| 163 | 165 | { |
|---|
| 164 | 166 | version (darwin) |
|---|
| … | … | |
| 166 | 168 | timezone_t tz = void; |
|---|
| 167 | 169 | gettimeofday (null, &tz); |
|---|
| 168 | | return cast(Time) (-Time.TicksPerMinute * tz.tz_minuteswest); |
|---|
| | 170 | return TimeSpan.minutes(-tz.tz_minuteswest); |
|---|
| 169 | 171 | } |
|---|
| 170 | 172 | else |
|---|
| 171 | | return cast(Time) (-Time.TicksPerSecond * timezone); |
|---|
| | 173 | return TimeSpan.seconds(-timezone); |
|---|
| 172 | 174 | } |
|---|
| 173 | 175 | |
|---|
| … | … | |
| 193 | 195 | ***************************************************************/ |
|---|
| 194 | 196 | |
|---|
| 195 | | static Date toDate (Time utc) |
|---|
| | 197 | static Date toDate (DateTime utc) |
|---|
| 196 | 198 | { |
|---|
| 197 | 199 | Date date = void; |
|---|
| … | … | |
| 218 | 220 | ***************************************************************/ |
|---|
| 219 | 221 | |
|---|
| 220 | | static Time fromDate (inout Date date) |
|---|
| | 222 | static DateTime fromDate (inout Date date) |
|---|
| 221 | 223 | { |
|---|
| 222 | 224 | tm t = void; |
|---|
| … | … | |
| 230 | 232 | |
|---|
| 231 | 233 | auto seconds = mktime (&t); |
|---|
| 232 | | return cast(Time) (Time.TicksTo1970 + |
|---|
| 233 | | Time.TicksPerSecond * seconds + |
|---|
| 234 | | Time.TicksPerMillisecond * date.ms); |
|---|
| | 234 | return DateTime.epoch1970 + TimeSpan.seconds(seconds) + TimeSpan.milliseconds(date.ms); |
|---|
| 235 | 235 | } |
|---|
| 236 | 236 | } |
|---|
| … | … | |
| 240 | 240 | ***********************************************************************/ |
|---|
| 241 | 241 | |
|---|
| 242 | | static Time toLocal (Time utc) |
|---|
| 243 | | { |
|---|
| 244 | | auto mod = utc % Time.TicksPerMillisecond; |
|---|
| 245 | | return cast(Time) (Clock.fromDate(toDate(utc)) + mod); |
|---|
| | 242 | static DateTime toLocal (DateTime utc) |
|---|
| | 243 | { |
|---|
| | 244 | auto mod = utc.ticks % TimeSpan.ms.ticks; |
|---|
| | 245 | return Clock.fromDate(toDate(utc)) + TimeSpan(mod); |
|---|
| 246 | 246 | } |
|---|
| 247 | 247 | |
|---|
| … | … | |
| 250 | 250 | ***********************************************************************/ |
|---|
| 251 | 251 | |
|---|
| 252 | | static Time toUtc (Time wall) |
|---|
| 253 | | { |
|---|
| 254 | | auto mod = wall % Time.TicksPerMillisecond; |
|---|
| 255 | | return cast(Time) (fromDate(Clock.toDate(wall)) + mod); |
|---|
| | 252 | static DateTime toUtc (DateTime wall) |
|---|
| | 253 | { |
|---|
| | 254 | auto mod = wall.ticks % TimeSpan.ms.ticks; |
|---|
| | 255 | return fromDate(Clock.toDate(wall)) + TimeSpan(mod); |
|---|
| 256 | 256 | } |
|---|
| 257 | 257 | } |
|---|
| r2878 |
r2900 |
|
| 15 | 15 | |
|---|
| 16 | 16 | private import tango.core.Exception; |
|---|
| 17 | | |
|---|
| 18 | | public import tango.core.Type : Time; |
|---|
| 19 | 17 | |
|---|
| 20 | 18 | public import tango.util.time.DateTime; |
|---|
| … | … | |
| 286 | 284 | package static long getTimeTicks (int hour, int minute, int second) |
|---|
| 287 | 285 | { |
|---|
| 288 | | return (cast(long) hour * 3600 + cast(long) minute * 60 + cast(long) second) * Time.TicksPerSecond; |
|---|
| | 286 | return (TimeSpan.hours(hour) + TimeSpan.minutes(minute) + TimeSpan.seconds(second)).ticks; |
|---|
| 289 | 287 | } |
|---|
| 290 | 288 | } |
|---|
| r2809 |
r2900 |
|
| 70 | 70 | override DateTime getDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) |
|---|
| 71 | 71 | { |
|---|
| 72 | | return DateTime (getDateTicks(year, month, day) + getTimeTicks(hour, minute, second) + (millisecond * Time.TicksPerMillisecond)); |
|---|
| | 72 | return DateTime (getDateTicks(year, month, day) + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| 73 | 73 | } |
|---|
| 74 | 74 | |
|---|
| … | … | |
| 80 | 80 | override DateTime.DayOfWeek getDayOfWeek(DateTime time) |
|---|
| 81 | 81 | { |
|---|
| 82 | | return cast(DateTime.DayOfWeek)((time.ticks / Time.TicksPerDay + 1) % 7); |
|---|
| | 82 | return cast(DateTime.DayOfWeek)((time.ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| 83 | 83 | } |
|---|
| 84 | 84 | |
|---|
| … | … | |
| 219 | 219 | package static void splitDate (long ticks, out int year, out int month, out int day, out int dayOfYear) |
|---|
| 220 | 220 | { |
|---|
| 221 | | int numDays = cast(int)(ticks / Time.TicksPerDay); |
|---|
| 222 | | int whole400Years = numDays / cast(int) Time.DaysPer400Years; |
|---|
| 223 | | numDays -= whole400Years * cast(int) Time.DaysPer400Years; |
|---|
| 224 | | int whole100Years = numDays / cast(int) Time.DaysPer100Years; |
|---|
| | 221 | int numDays = cast(int)(ticks / TimeSpan.day.ticks); |
|---|
| | 222 | int whole400Years = numDays / cast(int) TimeSpan.DaysPer400Years; |
|---|
| | 223 | numDays -= whole400Years * cast(int) TimeSpan.DaysPer400Years; |
|---|
| | 224 | int whole100Years = numDays / cast(int) TimeSpan.DaysPer100Years; |
|---|
| 225 | 225 | if (whole100Years == 4) |
|---|
| 226 | 226 | whole100Years = 3; |
|---|
| 227 | 227 | |
|---|
| 228 | | numDays -= whole100Years * cast(int) Time.DaysPer100Years; |
|---|
| 229 | | int whole4Years = numDays / cast(int) Time.DaysPer4Years; |
|---|
| 230 | | numDays -= whole4Years * cast(int) Time.DaysPer4Years; |
|---|
| 231 | | int wholeYears = numDays / cast(int) Time.DaysPerYear; |
|---|
| | 228 | numDays -= whole100Years * cast(int) TimeSpan.DaysPer100Years; |
|---|
| | 229 | int whole4Years = numDays / cast(int) TimeSpan.DaysPer4Years; |
|---|
| | 230 | numDays -= whole4Years * cast(int) TimeSpan.DaysPer4Years; |
|---|
| | 231 | int wholeYears = numDays / cast(int) TimeSpan.DaysPerYear; |
|---|
| 232 | 232 | if (wholeYears == 4) |
|---|
| 233 | 233 | wholeYears = 3; |
|---|
| 234 | 234 | |
|---|
| 235 | 235 | year = whole400Years * 400 + whole100Years * 100 + whole4Years * 4 + wholeYears + 1; |
|---|
| 236 | | numDays -= wholeYears * Time.DaysPerYear; |
|---|
| | 236 | numDays -= wholeYears * TimeSpan.DaysPerYear; |
|---|
| 237 | 237 | dayOfYear = numDays + 1; |
|---|
| 238 | 238 | |
|---|
| … | … | |
| 267 | 267 | int[] monthDays = isLeapYear(year, AD_ERA) ? DaysToMonthLeap : DaysToMonthCommon; |
|---|
| 268 | 268 | year--; |
|---|
| 269 | | return (year * 365 + year / 4 - year / 100 + year / 400 + monthDays[month - 1] + day - 1) * Time.TicksPerDay; |
|---|
| | 269 | return (year * 365 + year / 4 - year / 100 + year / 400 + monthDays[month - 1] + day - 1) * TimeSpan.day.ticks; |
|---|
| 270 | 270 | } |
|---|
| 271 | 271 | } |
|---|
| r2878 |
r2900 |
|
| 79 | 79 | */ |
|---|
| 80 | 80 | public override DateTime.DayOfWeek getDayOfWeek(DateTime time) { |
|---|
| 81 | | return cast(DateTime.DayOfWeek) cast(int) ((time.ticks / Time.TicksPerDay + 1) % 7); |
|---|
| | 81 | return cast(DateTime.DayOfWeek) cast(int) ((time.ticks / TimeSpan.day.ticks + 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 / Time.TicksPerDay) - days; |
|---|
| | 93 | int day = cast(int)(time.ticks / TimeSpan.day.ticks) - 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 / Time.TicksPerDay) - days) + 1; |
|---|
| | 110 | return (cast(int)(time.ticks / TimeSpan.day.ticks) - 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 / Time.TicksPerDay) - days; |
|---|
| | 122 | int day = cast(int)(time.ticks / TimeSpan.day.ticks) - days; |
|---|
| 123 | 123 | int n; |
|---|
| 124 | 124 | while (n < 12 && day >= MonthDays[yearType][n + 1]) { |
|---|
| … | … | |
| 135 | 135 | */ |
|---|
| 136 | 136 | public override int getYear(DateTime time) { |
|---|
| 137 | | int day = cast(int)(time.ticks / Time.TicksPerDay) + DaysToOneAD; |
|---|
| | 137 | int day = cast(int)(time.ticks / TimeSpan.day.ticks) + 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 DateTime((days * Time.TicksPerDay) + getTimeTicks(hour, minute, second) + (millisecond * Time.TicksPerMillisecond)); |
|---|
| | 284 | return DateTime((days * TimeSpan.day.ticks) + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| 285 | 285 | } |
|---|
| 286 | 286 | |
|---|
| r2809 |
r2900 |
|
| 44 | 44 | */ |
|---|
| 45 | 45 | public override DateTime getDateTime(int year, int month, int day, int hour, int minute, int second, int millisecond, int era) { |
|---|
| 46 | | return DateTime((daysSinceJan1(year, month, day) - 1) * Time.TicksPerDay + getTimeTicks(hour, minute, second) + (millisecond * Time.TicksPerMillisecond)); |
|---|
| | 46 | return DateTime((daysSinceJan1(year, month, day) - 1) * TimeSpan.day.ticks + getTimeTicks(hour, minute, second)) + TimeSpan.milliseconds(millisecond); |
|---|
| 47 | 47 | } |
|---|
| 48 | 48 | |
|---|
| … | … | |
| 53 | 53 | */ |
|---|
| 54 | 54 | public override DateTime.DayOfWeek getDayOfWeek(DateTime time) { |
|---|
| 55 | | return cast(DateTime.DayOfWeek) (cast(int) (time.ticks / Time.TicksPerDay + 1) % 7); |
|---|
| | 55 | return cast(DateTime.DayOfWeek) (cast(int) (time.ticks / TimeSpan.day.ticks + 1) % 7); |
|---|
| 56 | 56 | } |
|---|
| 57 | 57 | |
|---|
| … | … | |
| 180 | 180 | |
|---|
| 181 | 181 | private int extractPart(long ticks, DatePart part) { |
|---|
| 182 | | long days = (ticks / Time.TicksPerDay + 1); |
|---|
| | 182 | long days = TimeSpan(ticks).days + 1; |
|---|
| 183 | 183 | int year = cast(int)(((days - 227013) * 30) / 10631) + 1; |
|---|
| 184 | 184 | long daysUpToYear = daysToYear(year); |
|---|
Download in other formats:
|
 |