Boost logo

Boost :

Subject: Re: [boost] [gsoc 2013] draft proposal for chrono::date
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2013-05-04 22:19:31


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

> What do you expect from a "full featured date class"?

In context, I was just referring to the full complement of constructor overloads.

> Would this correspond what I have called a Date concept?

Having a Date concept is likely s good thing.

> 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();

I'd expect to be able to influence the time zone.

> class date {
> public:
> // construct/copy/destruct
> date(); // |year(0)/jan/1|
> date(year, month, day);
> date(year, month, day, no_check_t);
> // and all the usual combinations

I'm warming up to the checked/unchecked dichotomy between date and make_date(), though the latter can be used for multiple date types and all must be checked or unchecked alike.

> bool set_if_valid_date(year, month, day);

This seems odd. I'd prefer set(), with an exception and, maybe, try_set(), returning bool.

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

I'd expect one or the other. day() is probably better, since day can offer an explicit, converting constructor to get the effect of the operator. That simplifies the date I/F a little.

> 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()
>
> explicit date(system_clock::time_point);
> operator system_clock::time_point() const;
>
> 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);
> date & operator+=(years);
> date & operator-=(years);
>
> // 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 &);
>
> };

It seems pretty complete. I haven't given this as much thought as you and Howard, so I'll assume the rest is appropriate.

___
Rob

(Sent from my portable computation engine)


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