-
Notifications
You must be signed in to change notification settings - Fork 239
Add implicit conversion of DateTime/DateOnly to CalDateTime #822
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: main
Are you sure you want to change the base?
Conversation
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ @@ Coverage Diff @@
## main #822 +/- ##
===================================
Coverage 68% 68%
===================================
Files 106 106
Lines 4209 4211 +2
Branches 945 945
===================================
+ Hits 2842 2844 +2
Misses 1039 1039
Partials 328 328
🚀 New features to boost your workflow:
|
@NRG-Drink The implicit conversion operators have intentionally been removed. The reason is that there is no obvious conversion between the two. E.g. one has a TZ the other hasn't. And then there's the problem with So I suggest to not introduce an implicit conversion. I'd also discourage an explicit conversion. To simplify things, I could imagine publishing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Referring to the #822 (comment):
There are use cases where implicit operators are great. For CalDateTime
vs. DateTime
they can be quite confusing.
So what @minichma proposes could be viable option to simplify conversion.
Currently we use the method from DateUtil
public static CalDateTime AsCalDateTime(this DateTime t)
=> new CalDateTime(t);
in our unit tests, and yes, we could add it to the public API e.g. in a static
class DateTimeExtensions
with
public static CalDateTime ToCalDateTime(this DateTime t)
=> new CalDateTime(t);
public static CalDateTime ToCalDateTime(this DateOnly t)
=> new CalDateTime(t);
and add the corresponding xmldoc form the CalDateTime
CTORs. As opposed to implicit operator we can explain how the conversion works.
Is this case it would be good to migrate DateUtil.AsCalDateTime
to the new extension method(s).
What do you think?
Thanks for the comments @minichma @axunonb . new CalDateTime(dt);
dt.AsCalDateTime();
DateUtil.AsCalDateTime(dt); A more straight forward way is to use the So I suggest to close this PR (#822) and the corresponding issue (#821). |
closes #821