|
Boost : |
From: Jeff Garland (jeff_at_[hidden])
Date: 2007-07-11 15:11:51
On Wed, 11 Jul 2007 13:34:22 -0500, Martin Min wrote
> Jeff:
> Thanks for your reply.
> First, by "You can use gregorian::greg_year which is the first
> parameter to a date", do you mean a date can be constructed by just
> passing greg_year? or still I have to provide a month and day?
What I mean is you can just use greg_year to represent the year instead of the
date class. However, given your requirements below it probably won't be of
much help.
> I am working in Natural Language Understanding area, in which
> underspecifed Temporal Expressions abound in typical news text, and
> reasoning on these type of knowledge often has to deal with
> incomplete information. The granularity (or resolution) of time
> often changes in a discourse, sometimes year, or month, or date, or
> time, even century.
I see.
> What I like most boost::date_time are the various arithematic
> operations on durations and date periods, and timezone support. Of
> course, as well as the robustness.
>
> Probably, what I can do is to define another Date class, which have the
> boost::date_time::date has a member, and add members I may need?
Possibly. It seems like you might need something a bit different -- a
multi-resolution time point. Or you need to have series of different time
points with different resolutions. For example you could have something like
this:
boost::gregorian::date; //time point with 1 day resolution
class month_year; //time point with 1 month resolution
class quarter; //time point with 3 month resolution
class year; //time point with 1 year resolution
class decade; //time point with 10 year resolution
class century; //time point with 100 year resolution
So, simple usage would look something like:
month_year my(2007, Jul);
quarter q(2007, 2);
year y(2007)
decade d(21, 1); //21st century, 1st decade
....
Of course the alternative is to have a single type that provides the something
like this:
//pseudo code
class general_time_point
{
enum TIMEPOINT_RESOLUTION { DAY, MONTH, YEAR, QUARTER, DECADE, CENTURY}
general_time_point(year, month, day);
general_time_point(year, month);
general_time_point(value, TIMEPOINT_RESOLUTION); //general constructor
};
So if you had one of these 2 kinds of types, what would you like to do with
them? There a conceptual issues w.r.t the meaning of arithmetic operations on
these kinds of types. For example:
decade c(21, 1);
c += days(1); //meaningless
year y(2007)
y += years(2); //ok
The advantage of the multi-type solution is that the meaningless operations
can be prevented at compile time. However, the multi-type solution is likely
more difficult in your particular case.
Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk