www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.datetime TimeOfDay missing 'add' method?

reply "ixid" <nuaccount gmail.com> writes:
TimeOfDay's roll function refers to an add method which would 
increment or decrement the next greater unit of time when it 
wraps a unit of time. This method seems to be absent, while 
DateTime has it.
Sep 20 2012
next sibling parent "ixid" <nuaccount gmail.com> writes:
Actually I see DateTime's method is days and months only, why 
aren't hours, minutes and seconds available?
Sep 20 2012
prev sibling next sibling parent =?UTF-8?B?QWxpIMOHZWhyZWxp?= <acehreli yahoo.com> writes:
On 09/20/2012 09:02 AM, ixid wrote:
 TimeOfDay's roll function refers to an add method
I see how "The difference between rolling and adding ..." implies that there is also an add() function just like there is a roll() function. In fact, adding is handled simply by operator overloading. You can add Duration objects: t += duration; auto newTime = t + duration; Ali
Sep 20 2012
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Thursday, September 20, 2012 18:02:04 ixid wrote:
 TimeOfDay's roll function refers to an add method which would
 increment or decrement the next greater unit of time when it
 wraps a unit of time. This method seems to be absent, while
 DateTime has it.
Create a Duration and use +. e.g. auto t = timeOfDay + dur!"seconds"(12); Maybe rolling's docs aren't clear enough, but they never actually mention an add function. They mention adding but not an add function. An add method exists on SysTime, DateTime, and Date only because you can't have a Duration of anything greater than weeks, because you can't convert between months and smaller units without a specific date. So, a separate function is needed. Everything else uses the arithmetic operators. - Jonathan M Davis
Sep 20 2012