Boost logo

Boost :

From: Jeff Garland (jeff_at_[hidden])
Date: 2002-04-16 19:15:05


Beman Dawes wrote:
>When does conversion matter? One case is when a user of one time system
>needs to pass a time to a library which happens to use another time system.

Yes. And the problem applies to both date and time systems. For example, suppose we built a Mayan
Date system. The specification of a day in the Mayan calendar is very different from the Gregorian
(can use 'the long count' which is broken down into a tuple of 6 elements - something like:
12.15.11.15.6). In this case the 'resolution' in compatible so conversion between the two systems
makes sense. So, the way the conversion done is that a point in time is set as the 'point of
reference' using a basic counted system (eg: like a time_t count). Each date system needs to
provide a functions that can convert any point to the point of reference and back.

So at some point when additional calendars are built with GDTL it might be useful to provide a
single point of reference that multiple calendars could use as a conversion point. That is
precisely the approach used to convert between a bunch of Calendars in Calendrical Calculations by
Reingold and Dershowitz.

>But what happens when in fact, at least for some values, the epoch and
>resolutions are close enough that conversion is possible. Could you give
>an example of how to call a library function requiring a certain time
>system argument, when your program has the value stored in a different time
>system?

Sure, there are multiple ways this could be approached. I'm going to stick with the date example,
but the same thing can be done with time. One simple way is that the date system could provide this
functionality directly as a part of the date class. For example lets suppose we don't actually have
a full date/time system for modified julian day. We could have a simple convenience function on
date that would provide it:

using namespace gregorian;
date d(2000,Jan,1);
long modified_julian_day = d.to_modified_julian_day();

However, in the long run we would probably want free functions between full systems like:

gregorian::date gd(2002,1,1);
mayan::date md = to_mayan(gd);

The tricky part is that we don't want these date library to become codependent . That is I envision
the Mayan system would go in boost/gdtl/mayan and I shouldn't need the gregorian system to use the
mayan system, and vice versa. The only time I would need both is in doing conversion between
them...

Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk