[phobos] More datetime stuff
Jonathan M Davis
jmdavisprog at gmail.com
Wed Aug 25 04:53:25 PDT 2010
Okay. As I mentioned a week or so ago on this list, I've been working on a
date/time module based on Boost, and since Yao G. has posted some work in that
area, I thought that I would post what I have completed.
I have a struct based on Boost's date which has essentially same API with
certain additions of my own. I did not use any of Boost's implementation or any
of std.gregorian. In particular, Boost's implementation holds the date's values
in a single long as the number of days, so it has to convert that value every
time that you call a function on it. Mine holds the year, month, and day
separately in order to reduce the number of conversions necessary. It also makes
it take 4 bytes instead of 8. Also, my implementation is able to hold years from
32,768 B.C. to 32,767 A.D rather than being restricted to the range of 1400-
Jan-01 to 9999-Dec-31 which boost is restricted to.
I have also implemented a TimeOfDay struct which holds the time of day in 24-
hour time but has no concept of date (it holds the hour, minute, and second of
the time), as well as a DateTime struct which combines my Date and TimeOfDay
structs to give you both date and time functionality with the idea of using it
for calendar-based operations (and even DateTime still only takes 8 bytes, which
is the same as the boost implementation of just the date). It has no concept of
time zone and has no connection to system time.
I'm still working on a SysTime struct based on boost's posix time which will
hold the number of ticks (100 nanoseconds) since midnight on 0001-Jan-01 A.D.
(rather than the time_t boost's holds), which will be connected to system time
and definitely deal with time zones. I'm also still working on the duration and
time interval stuff.
So, I'm attaching my Date, TimeOfDay, and DateTime structs along with various
helper functions. I'm also including my unittests module which includes
functions that I used in my unit tests. The ddoc pages for those 2 modules are
also included. I have fully documented the modules and have extensive unit tests
for them. There is still some work to be done on them once the duration and
interval stuff is ironed out (like overloaded arithmetic operators), but it is
essentially complete as is.
I'm also posting the datetime module stripped of unit tests here:
http://ideone.com/9wou2
I have yet to really look at what Yao G. has done, but from his post, it sounds
like it's pretty much a direct port of Boost's date, duration, and interval
stuff. If that's the case, I expect that mine is better in that it has greater
functionality, but having not looked at his code, I obviously can't comment on
their comparative quality of implementation, though I do have a lot of unit
tests to verify that my code is correct. In any case, I'm posting this so that
others can look at it. Whether what I've done is used or what Yao G. has done is
used (or something else entirely is used) is obviously up to Andrei and company.
I will continue to work on my time duration and interval code, as well as my
posix time code and will post that when it is completed (though I expect that
that would happen this weekend at the absolute earliest).
So, here you go.
- Jonathan M Davis
-------------- next part --------------
A non-text attachment was scrubbed...
Name: datetime.tar.bz2
Type: application/x-bzip-compressed-tar
Size: 30911 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/phobos/attachments/20100825/04657eb1/attachment-0001.bin>
More information about the phobos
mailing list