Closed tomaszkam closed 5 years ago
Given other functions I think that we expect to return unspecified values, as it is done for other classes, like year_month_day
or year_month_weekday
. Also, I think we need to appy similiar change sys_days
conversion.
Example spec: http://eel.is/c++draft/time.cal.ymwdlast.members#15
Current implementation produced undefined result for !month().ok(), as it indexes table out of range. See: https://github.com/HowardHinnant/date/blob/master/include/date/date.h#L2514-L2525
Created pull request that makes behavior unspecified: https://github.com/HowardHinnant/date/pull/456
Discussion:
The current specification of year_month_day_last::day
method does not cover the behaviour in situation when year_month_day_last
value is not ok()
. To illustrate the sentence from http://eel.is/c++draft/time.cal#ymdlast.members-13:
A
day
representing the last day of the (year
,month
) pair represented by*this
.
is unclear in situation when month
member has !ok
value, e.g. what is last day of 14th month of 2019.
Proposed resolution makes the value of ymdl.day()
(and by consequence conversion to sys_days
/local_days
) unspecifed if ymdl.ok
is false
. This make is consistent with rest of the library, that produces unspecified values in similiar situation, e.g.: http://eel.is/c++draft/time.cal#ymd.members-18, http://eel.is/c++draft/time.cal#ymwd.members-19, http://eel.is/c++draft/time.cal#ymwdlast.members-14.
Proposed wording:
Apply the following changes to the specification of year_month_day_last::day
method in [time.cal.ymdlast.members]:
constexpr chrono::day day() const noexcept;
Returns: If ok() == true
, returns aA day
representing the last day of the (year
, month
) pair represented by *this
. Otherwise the returned value is unspecified.
[ Note: This value may be computed on demand. — end note ]
Original comment:
E-mail conversation: [isocpp-lib] year_month_day_last::day when it stores an invalid year or month