I have MyDateTime
class and it has a variable hour
. I need to set this variable with some condition when I create an object. For example, I have this object:
MyDateTime dt = MyDateTime(2020, 2, 3, 3, 2);
now I need to increment the hour
i.e. dt.hour++;
my question how I can change the hour
of the object without adding new functions, at the same time i need to increment the hour
with condition
class MyDateTime {
int year;
int month;
int day;
int hour;
int minute;
int second;
MyDateTime({this.year, this.month, this.day ,this.hour=0, this.minute=0, this.second=0});
// this is the condition
set addHour(int h){
if(this.hour == 23) this.hour = 0;
else if(this.hour == 0) this.hour = 1;
else this.hour++;
}
}
I don't want to have function (ex: addHour
)
Is there way to do it?