www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Add property setting to chain

reply closescreen <close.screen gmail.com> writes:
Let i have code:

Clock.currTime.to!DateTime.Interval!DateTime( 24.hours 
).fwdRange( h=>h+1.hours ).writeln;

Now if i want to set the minute=0 and second=0 without breaking 
chain, what i should do?


I think about somewhat like:

with( Clock.currTime.to!DateTime){
  minute=0;
  second=0
}.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;

But it is wrong, because 'with' not return me anything.
Jul 15
next sibling parent closescreen <close.screen gmail.com> writes:
I found this solution:

Clock.currTime.to!DateTime.pipe!( dt=>(dt.minute=0,dt.second=0, 
dt) ).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours 
).writeln;

Or:

Clock.currTime.to!DateTime.pipe!( "a.minute=0, a.second=0, a" 
).Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;



Is this code looks good, idiomatic?
Jul 15
prev sibling parent reply =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
On 07/15/2017 12:53 PM, closescreen wrote:
 Let i have code:

 Clock.currTime.to!DateTime.Interval!DateTime( 24.hours ).fwdRange(
 h=>h+1.hours ).writeln;

 Now if i want to set the minute=0 and second=0 without breaking chain,
 what i should do?


 I think about somewhat like:

 with( Clock.currTime.to!DateTime){
  minute=0;
  second=0
 }.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln;

 But it is wrong, because 'with' not return me anything.
I would probably write a function: import std.datetime; import std.stdio; import std.range; import std.conv; DateTime hourPrecision(DateTime dt) { dt.minute = 0; dt.second = 0; return dt; } void main() { Clock.currTime.to!DateTime.hourPrecision.Interval!DateTime( 24.hours ).fwdRange( h=>h+1.hours ).writeln; } Ali
Jul 15
parent closescreen <close.screen gmail.com> writes:
Thanks for reply, Ali.
Jul 16