Can't get expected strings

helxi via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jul 18 06:49:11 PDT 2017


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

void main()
{
     immutable DEADLINE = DateTime(2017, 7, 16, 23, 59, 
59).to!SysTime;
     immutable NOW = Clock.currTime;
     immutable INTERVAL = (DEADLINE - NOW)
                         .abs
                         .to!string;
                         //if I put .until("secs") here, it prints 
the full-type
                         //immutable(Until!("a == b", string, 
string))("1 day, 23 hours, 47 minutes, 30 secs, 508 ms, 119 μs, 
and 6 hnsecs", "secs", yes, false)


     writeln(INTERVAL);

     //But I don't want these until("secs") below:
     if (NOW > DEADLINE) writeln(INTERVAL.until("secs"), "seconds 
ago.");
     //1 day, 23 hours, 48 minutes, 55 seconds ago.
     else if (NOW < DEADLINE) writeln(INTERVAL.until("secs"), 
"seconds ahead.");
     else writeln("Now.");
}

-----


Why is to!string providing inconsistent string?


More information about the Digitalmars-d-learn mailing list