Proposal for custom time string formatting in std.datetime

Jonathan M Davis jmdavisProg at gmx.com
Wed Dec 28 03:11:35 PST 2011


On Wednesday, December 28, 2011 03:03:30 Jonathan M Davis wrote:
> On Wednesday, December 28, 2011 11:39:16 Kagamin wrote:
> > On Wednesday, 28 December 2011 at 00:15:00 UTC, Jonathan M Davis
> > 
> > wrote:
> > > By having SysTime, you don't need extra time types.
> > 
> > Hmm... if you don't have extra time types, how do you format a
> > SysTime? To convert a SysTime to a string you usually need year,
> > month and day. Calculating a year takes some time: leap years,
> > possibly time zone adjustment; when you need month, you have to
> > recalculate year, since SysTime doesn't hold it. That's how it
> > works?
> 
> SysTime's time is held internally as a long holding the number of hecto-
> nanoseconds (100 ns) from midnight, January 1st, 1 A.D.  It also holds a
> TimeZone which is used to convert that time to the correct time zone when
> any function requires that the time be in a specific time zone (e.g.
> getting the year of the SysTime or converting it to a string). SysTime does
> all of the appropriate calculations for that. And if you want to change the
> time zone of a SysTime, you set its timezone property to the TimeZone that
> you want. Its internal time is always in UTC.

And actually, this would be the same with UTCTime if we were to create it. It 
would hold its time internally as a long in hnsecs, and if it had any 
functions which required the time in any other format, it would have to 
convert. It would effectively be a SysTime with UTC as its time zone, except 
that the time zone would be hard-coded instead of using a TimeZone and its 
time zone being settable.

- Jonathan M Davis


More information about the Digitalmars-d mailing list