DateTime

module main;

import std.stdio, std.datetime, std.conv, std.math;

void main(string[] args)
{
    /*
    // Prints "Hello World" string in console
    writeln("Hello World! kuku");

    // Lets the user press <Return> before program returns
    //stdin.readln();

    auto ti1 = Interval!DateTime( DateTime(2017,05,06), DateTime(2017,05,10) );
    writefln("%s", ti1);

    auto ti2 = Interval!DateTime( DateTime(2017,05,06,05,00,00), dur!"hours"(5));
    writeln( ti2);

    auto fwdhh = ti2.fwdRange( h => h + dur!"hours"(1) );
    foreach( h; fwdhh ){
        writeln(h);
    }

    //auto bwdhh = ti2.bwdRange( h=>h - dur!"hours"(1) );
    auto bwdhh = ti2.bwdRange( h => h - hours(1) );

    foreach( h; bwdhh ){
        writeln(h);
    }
    */

    //auto t1 = DateTime.fromISOExtString( "2017-06-12T05:00:00" );
    // writeln(t1);

    /*
    auto ti3 = Interval!DateTime( DateTime.fromISOExtString("2017-06-12T05:00:00"), hours(2) );

    foreach( h; ti3.fwdRange(h=>h+hours(1)) ){
        h.writeln;
    }
    */

    //auto ct = Clock.currTime.to!DateTime;
    //with (ct) {
    //    auto y = year, m = month, d = day, H = hour, M = minute;
    //}
    //with (ct){ hour=0, minute=0, second=0; }
    //ct.writeln;

    //auto ti4 = Interval!DateTime( Clock.currTime.to!DateTime, hours(2));
    //writeln(ti4);


    //Interval aaa( Duration hh, DateTime dt ){
    //    return Interval!DateTime( dt, hh
    //}

    //auto ti5 = DateTime(2017,05,06,05,00,00).Interval!DateTime( 2.hours );
    //ti5.writeln;



    /*
    auto ch = Clock.currTime.to!DateTime;
    with(ch){minute=0,second=0;}
    auto ti6 = ch.Interval!DateTime( 2.hours );
    auto r6 = ti6.fwdRange( h=>h+1.hours );
    foreach(h; r6 ){ h.writeln;}
    */

    2.hours.startingAt( Clock.currTime ).writeln;
    2.hours.startingAt( Clock.currTime.roundToHours ).writeln;
    2.hours.startingAt( Clock.currTime.rth ).writeln;
    2.hours.startingAt( currentHour ).writeln;

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

Interval!TP startingAt(TP)( Duration hh, TP dt ){
    return Interval!TP( dt, hh );
}

TP roundToHours(TP)( TP tp ){
    tp.minute=0;
    tp.second=0;
    return tp;
}

alias rth = roundToHours;


auto currentHour(){
    return Clock.currTime.rth;
}

results for ""

    No results matching ""