77+/
88module std.datetime.date ;
99
10- import core.time ;
10+ import core.time : TimeException ;
1111import std.traits : isSomeString, Unqual;
1212import std.typecons : Flag;
1313
1414version (unittest ) import std.exception : assertThrown;
1515
16-
1716@safe unittest
1817{
1918 initializeTests();
@@ -2064,6 +2063,7 @@ public:
20642063 }
20652064
20662065
2066+ import core.time : Duration;
20672067 /+ +
20682068 Gives the result of adding or subtracting a $(REF Duration, core,time)
20692069 from this $(LREF DateTime).
@@ -2108,6 +2108,8 @@ public:
21082108
21092109 @safe unittest
21102110 {
2111+ import core.time : dur;
2112+
21112113 auto dt = DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 ));
21122114
21132115 assert (dt + dur! " weeks" (7 ) == DateTime (Date (1999 , 8 , 24 ), TimeOfDay (12 , 30 , 33 )));
@@ -2155,6 +2157,7 @@ public:
21552157 assert (idt - duration == DateTime (1999 , 7 , 6 , 12 , 30 , 21 ));
21562158 }
21572159
2160+ import core.time : TickDuration;
21582161 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
21592162 deprecated (" Use Duration instead of TickDuration." )
21602163 DateTime opBinary (string op)(in TickDuration td) const @safe pure nothrow @nogc
@@ -2213,11 +2216,13 @@ public:
22132216 else static if (is (Unqual! D == TickDuration))
22142217 immutable hnsecs = duration.hnsecs;
22152218
2219+ import core.time : convert;
22162220 mixin (format(` return _addSeconds(convert!("hnsecs", "seconds")(%shnsecs));` , op));
22172221 }
22182222
22192223 @safe unittest
22202224 {
2225+ import core.time : dur;
22212226 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) + dur! " weeks" (7 ) ==
22222227 DateTime (Date (1999 , 8 , 24 ), TimeOfDay (12 , 30 , 33 )));
22232228 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) + dur! " weeks" (- 7 ) ==
@@ -2357,13 +2362,15 @@ public:
23572362 immutable dateResult = _date - rhs.date;
23582363 immutable todResult = _tod - rhs._tod;
23592364
2365+ import core.time : dur;
23602366 return dur! " hnsecs" (dateResult.total! " hnsecs" + todResult.total! " hnsecs" );
23612367 }
23622368
23632369 @safe unittest
23642370 {
23652371 auto dt = DateTime (1999 , 7 , 6 , 12 , 30 , 33 );
23662372
2373+ import core.time : dur;
23672374 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) - DateTime (Date (1998 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) ==
23682375 dur! " seconds" (31_536_000));
23692376 assert (DateTime (Date (1998 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) - DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) ==
@@ -3458,6 +3465,7 @@ private:
34583465 +/
34593466 ref DateTime _addSeconds (long seconds) return @safe pure nothrow @nogc
34603467 {
3468+ import core.time : convert;
34613469 long hnsecs = convert! (" seconds" , " hnsecs" )(seconds);
34623470 hnsecs += convert! (" hours" , " hnsecs" )(_tod._hour);
34633471 hnsecs += convert! (" minutes" , " hnsecs" )(_tod._minute);
@@ -6040,7 +6048,7 @@ public:
60406048 static assert (! __traits(compiles, idate.roll! " days" (12 )));
60416049 }
60426050
6043-
6051+ import core.time : Duration;
60446052 /+ +
60456053 Gives the result of adding or subtracting a $(REF Duration, core,time)
60466054 from
@@ -6080,6 +6088,7 @@ public:
60806088 {
60816089 auto date = Date (1999 , 7 , 6 );
60826090
6091+ import core.time : dur;
60836092 assert (date + dur! " weeks" (7 ) == Date (1999 , 8 , 24 ));
60846093 assert (date + dur! " weeks" (- 7 ) == Date (1999 , 5 , 18 ));
60856094 assert (date + dur! " days" (7 ) == Date (1999 , 7 , 13 ));
@@ -6128,12 +6137,14 @@ public:
61286137 assert (idate - duration == Date (1999 , 6 , 24 ));
61296138 }
61306139
6140+ import core.time : TickDuration;
61316141 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
61326142 deprecated (" Use Duration instead of TickDuration." )
61336143 Date opBinary (string op)(TickDuration td) const @safe pure nothrow @nogc
61346144 if (op == " +" || op == " -" )
61356145 {
61366146 Date retval = this ;
6147+ import core.time : convert;
61376148 immutable days = convert! (" hnsecs" , " days" )(td.hnsecs);
61386149 mixin (" return retval._addDays(" ~ op ~ " days);" );
61396150 }
@@ -6180,6 +6191,7 @@ public:
61806191
61816192 @safe unittest
61826193 {
6194+ import core.time : dur;
61836195 assert (Date (1999 , 7 , 6 ) + dur! " weeks" (7 ) == Date (1999 , 8 , 24 ));
61846196 assert (Date (1999 , 7 , 6 ) + dur! " weeks" (- 7 ) == Date (1999 , 5 , 18 ));
61856197 assert (Date (1999 , 7 , 6 ) + dur! " days" (7 ) == Date (1999 , 7 , 13 ));
@@ -6240,6 +6252,7 @@ public:
62406252 ref Date opOpAssign (string op)(TickDuration td) @safe pure nothrow @nogc
62416253 if (op == " +" || op == " -" )
62426254 {
6255+ import core.time : convert;
62436256 immutable days = convert! (" seconds" , " days" )(td.seconds);
62446257 mixin (" return _addDays(" ~ op ~ " days);" );
62456258 }
@@ -6276,7 +6289,6 @@ public:
62766289 }
62776290 }
62786291
6279-
62806292 /+ +
62816293 Gives the difference between two $(LREF Date)s.
62826294
@@ -6289,13 +6301,15 @@ public:
62896301 Duration opBinary (string op)(in Date rhs) const @safe pure nothrow @nogc
62906302 if (op == " -" )
62916303 {
6304+ import core.time : dur;
62926305 return dur! " days" (this .dayOfGregorianCal - rhs.dayOfGregorianCal);
62936306 }
62946307
62956308 @safe unittest
62966309 {
62976310 auto date = Date (1999 , 7 , 6 );
62986311
6312+ import core.time : dur;
62996313 assert (Date (1999 , 7 , 6 ) - Date (1998 , 7 , 6 ) == dur! " days" (365 ));
63006314 assert (Date (1998 , 7 , 6 ) - Date (1999 , 7 , 6 ) == dur! " days" (- 365 ));
63016315 assert (Date (1999 , 6 , 6 ) - Date (1999 , 5 , 6 ) == dur! " days" (31 ));
@@ -8353,6 +8367,7 @@ public:
83538367 ref TimeOfDay roll (string units)(long value) @safe pure nothrow @nogc
83548368 if (units == " hours" )
83558369 {
8370+ import core.time : dur;
83568371 return this += dur! " hours" (value);
83578372 }
83588373
@@ -8577,6 +8592,7 @@ public:
85778592 }
85788593
85798594
8595+ import core.time : Duration;
85808596 /+ +
85818597 Gives the result of adding or subtracting a $(REF Duration, core,time)
85828598 from this $(LREF TimeOfDay).
@@ -8621,6 +8637,7 @@ public:
86218637 {
86228638 auto tod = TimeOfDay (12 , 30 , 33 );
86238639
8640+ import core.time : dur;
86248641 assert (tod + dur! " hours" (7 ) == TimeOfDay (19 , 30 , 33 ));
86258642 assert (tod + dur! " hours" (- 7 ) == TimeOfDay (5 , 30 , 33 ));
86268643 assert (tod + dur! " minutes" (7 ) == TimeOfDay (12 , 37 , 33 ));
@@ -8661,6 +8678,7 @@ public:
86618678 assert (itod - duration == TimeOfDay (1 , 30 , 33 ));
86628679 }
86638680
8681+ import core.time : TickDuration;
86648682 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
86658683 deprecated (" Use Duration instead of TickDuration." )
86668684 TimeOfDay opBinary (string op)(TickDuration td) const @safe pure nothrow @nogc
@@ -8714,6 +8732,7 @@ public:
87148732
87158733 @safe unittest
87168734 {
8735+ import core.time : dur;
87178736 auto duration = dur! " hours" (12 );
87188737
87198738 assert (TimeOfDay (12 , 30 , 33 ) + dur! " hours" (7 ) == TimeOfDay (19 , 30 , 33 ));
@@ -8817,13 +8836,15 @@ public:
88178836 immutable lhsSec = _hour * 3600 + _minute * 60 + _second;
88188837 immutable rhsSec = rhs._hour * 3600 + rhs._minute * 60 + rhs._second;
88198838
8839+ import core.time : dur;
88208840 return dur! " seconds" (lhsSec - rhsSec);
88218841 }
88228842
88238843 @safe unittest
88248844 {
88258845 auto tod = TimeOfDay (12 , 30 , 33 );
88268846
8847+ import core.time : dur;
88278848 assert (TimeOfDay (7 , 12 , 52 ) - TimeOfDay (12 , 30 , 33 ) == dur! " seconds" (- 19_061));
88288849 assert (TimeOfDay (12 , 30 , 33 ) - TimeOfDay (7 , 12 , 52 ) == dur! " seconds" (19_061));
88298850 assert (TimeOfDay (12 , 30 , 33 ) - TimeOfDay (14 , 30 , 33 ) == dur! " seconds" (- 7200 ));
@@ -9253,6 +9274,7 @@ private:
92539274 +/
92549275 ref TimeOfDay _addSeconds (long seconds) return @safe pure nothrow @nogc
92559276 {
9277+ import core.time : convert;
92569278 long hnsecs = convert! (" seconds" , " hnsecs" )(seconds);
92579279 hnsecs += convert! (" hours" , " hnsecs" )(_hour);
92589280 hnsecs += convert! (" minutes" , " hnsecs" )(_minute);
0 commit comments