Subject: Re: [boost] [gsoc 2013] draft proposal for chrono::date
From: Howard Hinnant (howard.hinnant_at_[hidden])
Date: 2013-05-04 17:09:04


Thanks. I'm curious about some of your semantics...

On May 4, 2013, at 4:15 PM, "Vicente J. Botet Escriba" <vicente.botet_at_[hidden]> wrote:

> I have just extracted from my current interface some of the functions that we could have in a full featured date class.
>
> class date;
>
> date today();

In what timezone?

>
> class date {

What is the range of validity? Proleptic gregorian or auto-coverting to julian?

What is the internal representation?

> public:
> // construct/copy/destruct
> date(); // |year(0)/jan/1|
> date(year, month, day);
> date(year, month, day, no_check_t);

Do the year, month and day types range check?
Is the conversion from int to year implicit or explicit?
Is there a conversion from year to int? And if so, explicit or implicit?

> // and all the usual combinations
> bool set_if_valid_date(year, month, day);

Return true if was set?

> day day() const; // or explict operator day(); the same for the other accessors.

I've been experimenting with the explicit operator too. Haven't decided whether or not I like it yet.

> month month() const;
> year year() const;
>
> date(year, week, weekday);
> date(year, week, weekday, no_check_t);
> bool set_if_valid_date(year, week, weekday);
> week week() const;
> weekday weekday() const;
>
> date(year, day_of_year);
> date(year, day_of_year, no_check_t);
> bool set_if_valid_date(year, day_of_year);
> day_of_year day_of_year() const;
>
> explicit date(days);
> date(days, no_check_t);
> bool set_if_valid_date(days);
> days days_since_epoch(); // or time_since_epoch() or just days()

Is the epoch specified or left unspecified?

>
> explicit date(system_clock::time_point);
> operator system_clock::time_point() const;

Do the above two assume the UTC timezone?

>
> bool is_valid() const;
> bool is_leap_year() const;
>
> date & operator+=(days);
> date & operator++();
> date operator++(int);
> date & operator-=(days);
> date & operator--();
> date operator--(int);
> date & operator+=(months);
> date & operator-=(months);

What semantics do you use for month arithmetic?

> date & operator+=(years);
> date & operator-=(years);

What semantics do you use for year arithmetic?

> // friend functions
> friend date operator+(date, days);
> friend date operator+(days, date);
> friend date operator-(date, days);
> friend days operator-(date, date);
> friend date operator+(date, months);
> friend date operator+(months, date);
> friend date operator-(date, months);
> friend date operator+(date, years);
> friend date operator+(years, date);
> friend date operator-(date, years);
> friend bool operator==(const date &, const date &);
> friend bool operator<(const date &, const date &);
> friend bool operator!=(const date &, const date &);
> friend bool operator>(const date &, const date &);
> friend bool operator<=(const date &, const date &);
> friend bool operator>=(const date &, const date &);
>
> };

I'm not seeing the ability to get the number of days in the current month, aside from building my own table and indexing into it with the month() accessor.

Howard