Convert SysTime to TickDuration?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Nov 22 15:51:05 PST 2011
On Wednesday, November 23, 2011 00:24:13 Andrej Mitrovic wrote:
> I need the number of ticks for a file's modification date.
>
> module test;
> import std.datetime;
> import std.file;
> import std.stdio;
>
> void main()
> {
> auto res1 = TickDuration(timeLastModified("test.d")); // NG
> auto res2 =
> TickDuration.from!"hnsecs"(timeLastModified("test.d").stdTime);
> writeln(res2);
> }
>
> First one doesn't work, and it's really a pain having to find all
> these from/to/convert methods just to convert one value to another.
>
> The second one returns a negative number, but I can't tell whether
> this is right. Isn't the tick count supposed to be positive?
>
> Tango had this method:
> Path.modified(m.path).ticks;
>
> Very simple there.
Why would it even make sense to convert a SysTime to a TickDuration? One is a
time. The other is a duration. One is a specific point in time. The other is a
period of time, not a specific point. Sure, you could get the difference between
two SysTimes, and internally, SysTime holds its time as a duration from the
January 1st, 1 A.D. But you're then effectively determining the duration of
time between two time points, whereas SysTime itself is a time point.
I don't understand what purpose there would be in trying to convert a SysTime
to a TickDuration. SysTime is for giving you the time. TickDuration is for
precision timing - such as StopWatch. They are _completely_ different.
What are you really try to do here? Why would you even want such a conversion?
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list