77+/
88module std.datetime.date ;
99
10- import core.time ;
10+ // Note: reconsider using specific imports below after
11+ // https://issues.dlang.org/show_bug.cgi?id=17630 has been fixed
12+ import core.time ;// : TimeException;
1113import std.traits : isSomeString, Unqual;
1214import std.typecons : Flag;
1315
1416version (unittest ) import std.exception : assertThrown;
1517
16-
1718@safe unittest
1819{
1920 initializeTests();
@@ -2064,6 +2065,7 @@ public:
20642065 }
20652066
20662067
2068+ import core.time : Duration;
20672069 /+ +
20682070 Gives the result of adding or subtracting a $(REF Duration, core,time)
20692071 from this $(LREF DateTime).
@@ -2108,6 +2110,8 @@ public:
21082110
21092111 @safe unittest
21102112 {
2113+ import core.time : dur;
2114+
21112115 auto dt = DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 ));
21122116
21132117 assert (dt + dur! " weeks" (7 ) == DateTime (Date (1999 , 8 , 24 ), TimeOfDay (12 , 30 , 33 )));
@@ -2155,6 +2159,7 @@ public:
21552159 assert (idt - duration == DateTime (1999 , 7 , 6 , 12 , 30 , 21 ));
21562160 }
21572161
2162+ import core.time : TickDuration;
21582163 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
21592164 deprecated (" Use Duration instead of TickDuration." )
21602165 DateTime opBinary (string op)(in TickDuration td) const @safe pure nothrow @nogc
@@ -2213,11 +2218,13 @@ public:
22132218 else static if (is (Unqual! D == TickDuration))
22142219 immutable hnsecs = duration.hnsecs;
22152220
2221+ import core.time : convert;
22162222 mixin (format(` return _addSeconds(convert!("hnsecs", "seconds")(%shnsecs));` , op));
22172223 }
22182224
22192225 @safe unittest
22202226 {
2227+ import core.time : dur;
22212228 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) + dur! " weeks" (7 ) ==
22222229 DateTime (Date (1999 , 8 , 24 ), TimeOfDay (12 , 30 , 33 )));
22232230 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) + dur! " weeks" (- 7 ) ==
@@ -2357,13 +2364,15 @@ public:
23572364 immutable dateResult = _date - rhs.date;
23582365 immutable todResult = _tod - rhs._tod;
23592366
2367+ import core.time : dur;
23602368 return dur! " hnsecs" (dateResult.total! " hnsecs" + todResult.total! " hnsecs" );
23612369 }
23622370
23632371 @safe unittest
23642372 {
23652373 auto dt = DateTime (1999 , 7 , 6 , 12 , 30 , 33 );
23662374
2375+ import core.time : dur;
23672376 assert (DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) - DateTime (Date (1998 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) ==
23682377 dur! " seconds" (31_536_000));
23692378 assert (DateTime (Date (1998 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) - DateTime (Date (1999 , 7 , 6 ), TimeOfDay (12 , 30 , 33 )) ==
@@ -3458,6 +3467,7 @@ private:
34583467 +/
34593468 ref DateTime _addSeconds (long seconds) return @safe pure nothrow @nogc
34603469 {
3470+ import core.time : convert;
34613471 long hnsecs = convert! (" seconds" , " hnsecs" )(seconds);
34623472 hnsecs += convert! (" hours" , " hnsecs" )(_tod._hour);
34633473 hnsecs += convert! (" minutes" , " hnsecs" )(_tod._minute);
@@ -6040,7 +6050,7 @@ public:
60406050 static assert (! __traits(compiles, idate.roll! " days" (12 )));
60416051 }
60426052
6043-
6053+ import core.time : Duration;
60446054 /+ +
60456055 Gives the result of adding or subtracting a $(REF Duration, core,time)
60466056 from
@@ -6080,6 +6090,7 @@ public:
60806090 {
60816091 auto date = Date (1999 , 7 , 6 );
60826092
6093+ import core.time : dur;
60836094 assert (date + dur! " weeks" (7 ) == Date (1999 , 8 , 24 ));
60846095 assert (date + dur! " weeks" (- 7 ) == Date (1999 , 5 , 18 ));
60856096 assert (date + dur! " days" (7 ) == Date (1999 , 7 , 13 ));
@@ -6128,12 +6139,14 @@ public:
61286139 assert (idate - duration == Date (1999 , 6 , 24 ));
61296140 }
61306141
6142+ import core.time : TickDuration;
61316143 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
61326144 deprecated (" Use Duration instead of TickDuration." )
61336145 Date opBinary (string op)(TickDuration td) const @safe pure nothrow @nogc
61346146 if (op == " +" || op == " -" )
61356147 {
61366148 Date retval = this ;
6149+ import core.time : convert;
61376150 immutable days = convert! (" hnsecs" , " days" )(td.hnsecs);
61386151 mixin (" return retval._addDays(" ~ op ~ " days);" );
61396152 }
@@ -6180,6 +6193,7 @@ public:
61806193
61816194 @safe unittest
61826195 {
6196+ import core.time : dur;
61836197 assert (Date (1999 , 7 , 6 ) + dur! " weeks" (7 ) == Date (1999 , 8 , 24 ));
61846198 assert (Date (1999 , 7 , 6 ) + dur! " weeks" (- 7 ) == Date (1999 , 5 , 18 ));
61856199 assert (Date (1999 , 7 , 6 ) + dur! " days" (7 ) == Date (1999 , 7 , 13 ));
@@ -6240,6 +6254,7 @@ public:
62406254 ref Date opOpAssign (string op)(TickDuration td) @safe pure nothrow @nogc
62416255 if (op == " +" || op == " -" )
62426256 {
6257+ import core.time : convert;
62436258 immutable days = convert! (" seconds" , " days" )(td.seconds);
62446259 mixin (" return _addDays(" ~ op ~ " days);" );
62456260 }
@@ -6276,7 +6291,6 @@ public:
62766291 }
62776292 }
62786293
6279-
62806294 /+ +
62816295 Gives the difference between two $(LREF Date)s.
62826296
@@ -6289,13 +6303,15 @@ public:
62896303 Duration opBinary (string op)(in Date rhs) const @safe pure nothrow @nogc
62906304 if (op == " -" )
62916305 {
6306+ import core.time : dur;
62926307 return dur! " days" (this .dayOfGregorianCal - rhs.dayOfGregorianCal);
62936308 }
62946309
62956310 @safe unittest
62966311 {
62976312 auto date = Date (1999 , 7 , 6 );
62986313
6314+ import core.time : dur;
62996315 assert (Date (1999 , 7 , 6 ) - Date (1998 , 7 , 6 ) == dur! " days" (365 ));
63006316 assert (Date (1998 , 7 , 6 ) - Date (1999 , 7 , 6 ) == dur! " days" (- 365 ));
63016317 assert (Date (1999 , 6 , 6 ) - Date (1999 , 5 , 6 ) == dur! " days" (31 ));
@@ -8353,6 +8369,7 @@ public:
83538369 ref TimeOfDay roll (string units)(long value) @safe pure nothrow @nogc
83548370 if (units == " hours" )
83558371 {
8372+ import core.time : dur;
83568373 return this += dur! " hours" (value);
83578374 }
83588375
@@ -8577,6 +8594,7 @@ public:
85778594 }
85788595
85798596
8597+ import core.time : Duration;
85808598 /+ +
85818599 Gives the result of adding or subtracting a $(REF Duration, core,time)
85828600 from this $(LREF TimeOfDay).
@@ -8621,6 +8639,7 @@ public:
86218639 {
86228640 auto tod = TimeOfDay (12 , 30 , 33 );
86238641
8642+ import core.time : dur;
86248643 assert (tod + dur! " hours" (7 ) == TimeOfDay (19 , 30 , 33 ));
86258644 assert (tod + dur! " hours" (- 7 ) == TimeOfDay (5 , 30 , 33 ));
86268645 assert (tod + dur! " minutes" (7 ) == TimeOfDay (12 , 37 , 33 ));
@@ -8661,6 +8680,7 @@ public:
86618680 assert (itod - duration == TimeOfDay (1 , 30 , 33 ));
86628681 }
86638682
8683+ import core.time : TickDuration;
86648684 // Explicitly undocumented. It will be removed in January 2018. @@@DEPRECATED_2018-01@@@
86658685 deprecated (" Use Duration instead of TickDuration." )
86668686 TimeOfDay opBinary (string op)(TickDuration td) const @safe pure nothrow @nogc
@@ -8714,6 +8734,7 @@ public:
87148734
87158735 @safe unittest
87168736 {
8737+ import core.time : dur;
87178738 auto duration = dur! " hours" (12 );
87188739
87198740 assert (TimeOfDay (12 , 30 , 33 ) + dur! " hours" (7 ) == TimeOfDay (19 , 30 , 33 ));
@@ -8817,13 +8838,15 @@ public:
88178838 immutable lhsSec = _hour * 3600 + _minute * 60 + _second;
88188839 immutable rhsSec = rhs._hour * 3600 + rhs._minute * 60 + rhs._second;
88198840
8841+ import core.time : dur;
88208842 return dur! " seconds" (lhsSec - rhsSec);
88218843 }
88228844
88238845 @safe unittest
88248846 {
88258847 auto tod = TimeOfDay (12 , 30 , 33 );
88268848
8849+ import core.time : dur;
88278850 assert (TimeOfDay (7 , 12 , 52 ) - TimeOfDay (12 , 30 , 33 ) == dur! " seconds" (- 19_061));
88288851 assert (TimeOfDay (12 , 30 , 33 ) - TimeOfDay (7 , 12 , 52 ) == dur! " seconds" (19_061));
88298852 assert (TimeOfDay (12 , 30 , 33 ) - TimeOfDay (14 , 30 , 33 ) == dur! " seconds" (- 7200 ));
@@ -9253,6 +9276,7 @@ private:
92539276 +/
92549277 ref TimeOfDay _addSeconds (long seconds) return @safe pure nothrow @nogc
92559278 {
9279+ import core.time : convert;
92569280 long hnsecs = convert! (" seconds" , " hnsecs" )(seconds);
92579281 hnsecs += convert! (" hours" , " hnsecs" )(_hour);
92589282 hnsecs += convert! (" minutes" , " hnsecs" )(_minute);
0 commit comments