-
-
Notifications
You must be signed in to change notification settings - Fork 739
Fix dlang#10783: Datetime: Make adding a Duration to Date commutative #10818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The types Date, DateTime and TimeOfDay already implement adding and subtracting a Duration to them. This makes the addition of a Duration commutative via implementing opBinaryRight. I chose opBinaryRight over Duration.opBinary, since Duration is in druntime, which shouldn't depend on phobos. Only addition is implemented here. DateTime and Date already principally support negative Dates, i.e. Date(0, 1, 1) - days(7) // 0001-Dec-25 works and can be interpreted as Before Christ (BC) dates. On the other hand opUnary isn't implemented (yet), which seems like a precondition for making subtraction commutative in a way that makes sense via the transformation: days(7) - Date(0,1,1) => -Date(0,1,1) + days(7) and even then the semantics of subtracting a Date from a Duration is debatable.
Thanks for your pull request and interest in making D better, @Inkrementator! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + phobos#10818" |
Github hyperlink: #10783 |
Personally, I don't think that it makes any sense for adding a But even if we decide that we want this change, it's going to need to be made to |
I agree. Otoh, the result of adding a The upsides are similarly limited. Not running into a (quick to fix) error when you accidentally mix up the order of
Having quickly written code "just work" is valuable for the use case of using D instead of a scripting language. |
I completely disagree with making
This feels to me like an arguing that a misspelling for a function should be added as an alias just because someone might misspell the function when writing code quickly. Just because code is in a script doesn't make it special, and it's plenty fast to write the code correctly in the first place. |
It is an inconsistency without purpose. That should not be tolerated.
As a Canadian occasionally writing colour-related code, I've dealt with this issue a few times... |
The types Date, DateTime and TimeOfDay already implement adding and subtracting a Duration to them.
This makes the addition of a Duration commutative via implementing opBinaryRight.
I chose opBinaryRight over Duration.opBinary, since Duration is in druntime, which shouldn't depend on phobos.
Only addition is implemented here. DateTime and Date already principally support negative Dates, i.e.
works and can be interpreted as Before Christ (BC) dates. On the other hand opUnary isn't implemented (yet), which seems like a precondition for making subtraction commutative in a way that makes sense via the transformation:
and even then the semantics of subtracting a Date from a Duration is debatable.