TickDuration deprecation

Timon Gehr timon.gehr at gmx.ch
Sat Nov 18 14:03:05 UTC 2017


This is quite annoying:

void main(){
     import std.datetime;
     StopWatch sw;
     import std.stdio;
     writeln(sw.peek().to!("seconds",double));
}

This gives the deprecation warning:
Deprecation: struct std.datetime.StopWatch is deprecated - Use 
std.datetime.stopwatch.StopWatch.

Then, if I do that:

void main(){
     import std.datetime.stopwatch: StopWatch;
     StopWatch sw;
     import std.stdio;
     writeln(sw.peek().to!("seconds",double));
}

Error: no property 'to' for type 'Duration'

This is among the most basic use cases for StopWatch. For example, if I 
want to quickly plot some timing data, I'll invariably want to convert 
times to floating point values of the correct units.

The reason given for this situation is:
https://issues.dlang.org/show_bug.cgi?id=11353

(Jonathan M Davis from comment #4)
 > TickDuration will soon be deprecated, and none of the other time stuff
 > supports floating point. Anyone who wants that functionality can 
calculate
 > the floating point values from the integral values that the types do
 > provide. It's not something that most code should be doing, but the API
 > makes it possible for those who care.


"Not something that most code should be doing"? I have never used 
StopWatch and then /not/ wanted to do something like to!("seconds",double)!

There seems to be no good reason to break my code beyond requiring a 
different import here. What are the perceived shortcomings of the 
to!("seconds", double) interface?


More information about the Digitalmars-d mailing list