Consider the following code:
final d = DateTime(2025, 1, -1);
print(d); // prints 2024-12-30 00:00:00.000
print(d.year); // prints 2024
// while in NepaliDateTime
final d2 = NepaliDateTime(2082, 5, -1);
print(d2); // prints 2082-05-0-1 00:00:00.000
print(d2.month); // prints 5
print(d2.day); // prints -1
This is the expected behavior of DateTime class. But even if NepaliDateTime extends from DateTime, it doesn't follow this rule. This lack of same implementation has 2 issues.
First, user who uses the DateTime with basic arithmetics to calculate the proper date without having to deal will negative values and different cases like checking if the end of hour/day/month/year etc. will be misguided by this lack of implementation by letting them believe it will work as it extends DateTime itself.
Second, working with the basic date calculation on NepaliDateTime will be so tedious, like wanting to calculate yesterday Nepali date by just subtracting 1 day from today's date which is quite easy in DateTime.
Currently, it can be done using subtract/add methods (overridden) but not using the constructor themselves.
I would like to suggest that the constructor should also behave similarly to unify the semantics with the parent DateTime class and to avoid confusion.
I am using version 3.0.8
Consider the following code:
This is the expected behavior of DateTime class. But even if NepaliDateTime extends from DateTime, it doesn't follow this rule. This lack of same implementation has 2 issues.
First, user who uses the DateTime with basic arithmetics to calculate the proper date without having to deal will negative values and different cases like checking if the end of hour/day/month/year etc. will be misguided by this lack of implementation by letting them believe it will work as it extends DateTime itself.
Second, working with the basic date calculation on NepaliDateTime will be so tedious, like wanting to calculate yesterday Nepali date by just subtracting 1 day from today's date which is quite easy in DateTime.
Currently, it can be done using subtract/add methods (overridden) but not using the constructor themselves.
I would like to suggest that the constructor should also behave similarly to unify the semantics with the parent DateTime class and to avoid confusion.
I am using version 3.0.8