Time::setDayOfWeek


#1

Hi,

Currently, the Time interface is a bit assymetric. There are a lot of get method, but no setter.
One could use the Time(year, month, day…) constructor to overcome the missing setters.
However, I think Time still miss a setDayOfWeek method, since the constructor doesn’t provide this functionality.

Hopefully this can be easily added by this method:

void Time::setDayOfWeek(int newDayOfWeek)
{
    // Go back to previous sunday
    millisSinceEpoch -= getDayOfWeek() * 86400000;
    // And set the current day of week
    millisSinceEpoch += newDayOfWeek * 86400000;
}

This of course, will ignore DST change if it happened during the week, but handling them would require a re-normalization step, using mktime/millisToLocal, which is not working in outside the 1970/2038 period.


#2

Similarly for getDayOfYear() which is missing (but it’s copy and paste from getDayOfWeek(), return tm_yday instead), and setDayOfYear().
The constant is the same.


#3

I think it’d have to be a “withDayOfWeek” method, as the class is generally used as an immutable object, but it’s a good request.