Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
February 01, 2015 Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
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... |
February 01, 2015 Re: Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | 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.
|
February 01, 2015 Re: Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | 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)` |
February 01, 2015 Re: Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to FG | 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. |
February 01, 2015 Re: Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | "+ n.days" solved my problem. |
February 01, 2015 Re: Can't understand how to compare DateTime with opCmp | ||||
---|---|---|---|---|
| ||||
Posted in reply to Suliman | 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
|
Copyright © 1999-2021 by the D Language Foundation