Skip to content

CSHARP-5319: Remove AsDateTime and similar from BsonValue #1494

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

Merged
merged 5 commits into from
Oct 15, 2024

Conversation

papafe
Copy link
Contributor

@papafe papafe commented Oct 10, 2024

No description provided.

@papafe papafe requested a review from rstam October 10, 2024 16:29
@papafe papafe requested a review from a team as a code owner October 10, 2024 16:29
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a discussion going on about what exactly we should do.

I am proposing that we should keep AsLocalTime and AsUniversalTime because that it is the existing pattern established by all our other AsXyz properties.

/// Casts the BsonValue to a DateTime in the local timezone (throws an InvalidCastException if the cast is not valid).
/// </summary>
[Obsolete("Use ToLocalTime instead.")]
public DateTime AsLocalTime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was obsoleted by mistake and we should keep the property and remove the [Obsolete] attribute.

/// <summary>
/// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid).
/// </summary>
[Obsolete("Use ToUniversalTime instead.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was obsoleted by mistake and we should keep the property and remove the [Obsolete] attribute.

/// Casts the BsonValue to a Nullable{DateTime} (throws an InvalidCastException if the cast is not valid).
/// </summary>
[Obsolete("Use ToNullableUniversalTime instead.")]
public DateTime? AsNullableDateTime
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This property should be replaced with two properties: AsNullableLocalTime and AsNullableUniversalTime.

/// <summary>
/// Casts the BsonValue to a DateTime in UTC (throws an InvalidCastException if the cast is not valid).
/// </summary>
[Obsolete("Use ToUniversalTime instead.")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This obsoletion was proper and the member can be deleted.

The error message was wrong though. It should have been "Use AsUniversalTime" instead.

@rstam
Copy link
Contributor

rstam commented Oct 11, 2024

Given our time zone difference and that I'm out of the office tomorrow I have prototyped in code what we were discussing earlier today:

https://github.com/rstam/mongo-csharp-driver/commits/csharp5319/

Summary of proposed changes:

Remove AsDateTime (use AsUniversalTime instead)
Remove AsNullableDateTime (use AsNullableUniversalTime instead)

Keep AsLocalTime (remove [Obsolete] attribute)
Keep AsUniversalTime (remove [Obsolete] attribute)

Add AsNullableLocalTime
Add AsNullableUniversalTime

Leave any existing "to date" methods alone.

@papafe papafe requested a review from rstam October 14, 2024 17:44
/// </summary>
public bool? AsNullableBoolean
[EditorBrowsable(EditorBrowsableState.Never)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we want DebuggerBrowsable here.

Also, we want it for ALL AsXyz properties, not just the DateTime ones.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right, DebuggerBrowsable is the correct one, I've misunderstood the situation

@papafe papafe requested a review from rstam October 15, 2024 06:51
@@ -77,6 +82,7 @@ public BsonBinaryData AsBsonBinaryData
/// <summary>
/// Casts the BsonValue to a BsonDateTime (throws an InvalidCastException if the cast is not valid).
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing attribute on line 94.

@@ -165,6 +180,7 @@ public BsonUndefined AsBsonUndefined
/// <summary>
/// Casts the BsonValue to a BsonValue (a way of upcasting subclasses of BsonValue to BsonValue at compile time).
/// </summary>
[DebuggerBrowsable(DebuggerBrowsableState.Never)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing attribute on line 192.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 just added

@papafe papafe requested a review from rstam October 15, 2024 16:19
Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@papafe papafe merged commit 3c4c80d into mongodb:main Oct 15, 2024
1 check was pending
@papafe papafe deleted the csharp5319 branch October 15, 2024 16:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants