www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Can't understand how to compare DateTime with opCmp

reply "Suliman" <evermind live.ru> writes:
I need to compare to DateTime. I looked at docs and found opCmp 
for DateTime type.
The problem is that I can't understand how to use it.

http://dlang.org/phobos/std_datetime.html#DateTime

opCmp(in DateTime rhs);

what is rhs?

I am trying to do something like this:
if( DateTime.opCmp(dtindb, outoftime));

But it's seems that I wrong understand how to use this function...
Feb 01 2015
next sibling parent "Rene Zwanenburg" <renezwanenburg gmail.com> writes:
On Sunday, 1 February 2015 at 15:04:39 UTC, Suliman wrote:
 I need to compare to DateTime. I looked at docs and found opCmp 
 for DateTime type.
 The problem is that I can't understand how to use it.

 http://dlang.org/phobos/std_datetime.html#DateTime

 opCmp(in DateTime rhs);

 what is rhs?

 I am trying to do something like this:
 if( DateTime.opCmp(dtindb, outoftime));

 But it's seems that I wrong understand how to use this 
 function...
opCmp is the operator overload for the comparison operators, so you can simple write: if(dtindb < outoftime) and it should work.
Feb 01 2015
prev sibling parent reply FG <home fgda.pl> writes:
On 2015-02-01 at 16:04, Suliman wrote:
 opCmp(in DateTime rhs);

 what is rhs?
RHS is probably short of "right hand side", ie. the argument on the right side of the operator in a binary operator expression. In `a < b` it would be b.
 I am trying to do something like this:
 if( DateTime.opCmp(dtindb, outoftime));

 But it's seems that I wrong understand how to use this function...
No. That would be `if (dtindb.opCmp(outoftime))`, but it's simpler to write `if (dtindb < outoftime)`
Feb 01 2015
parent reply "Suliman" <evermind live.ru> writes:
Thanks! Could anybody say how can I use roll if I need to date to 
date.
For example I need to plus:
DateTime currentdt = cast(DateTime)(Clock.currTime());
with another DateTime var foo.
Feb 01 2015
parent reply "Suliman" <evermind live.ru> writes:
"+ n.days" solved my problem.
Feb 01 2015
parent Jonathan M Davis via Digitalmars-d-learn writes:
On Sunday, February 01, 2015 19:22:40 Suliman via Digitalmars-d-learn wrote:
 "+ n.days" solved my problem.
Roll is specifically for cases where you want one of the fields to increase or decrease without affecting the others (e.g. if you had a spin control in your GUI with a DateTime backing it and didn't want any units other than the currently altered unit to change when its value wrapped around). In most cases, you're simply going to want to add a Duration to it - which dt + days(n) or dt + n.days will do. - Jonathan M Davis
Feb 01 2015