Skip to content

CSHARP-3268: Investigate Military Time Failures #1687

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rstam
Copy link
Contributor

@rstam rstam commented May 6, 2025

No description provided.

@rstam rstam requested review from BorisDog and rishitb-mongodb May 6, 2025 23:08
@rstam rstam requested a review from a team as a code owner May 6, 2025 23:08
@rstam rstam removed the request for review from a team May 6, 2025 23:08
@@ -1373,7 +1373,7 @@ private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
{
// if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
DateTime dateTime;
if (DateTime.TryParse(dateTimeString, out dateTime))
if (!dateTimeString.EndsWith("A") && DateTime.TryParse(dateTimeString, out dateTime))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason DateTime.TryParse returns true for time zone A but who knows what it thinks the A means.

If the string ends in A then we should use our own parsing method.

Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance there might be a collision with some other format ending with "A"?
Also there is not handling for "Z", is it a known abbreviation for UTC?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the existing test data nothing else ends with "A". But you are right, there might be a timezone abbreviation we don't know about that ends in A.

We could use a regular expression:

if (!Regex.Matches(dateString, "[0-9 ]A$") && ...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a test case for Z. I think it is a standard abbreviation for UTC and is handled by DateTime.TryParse.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks, just wanted to confirm that Z is for UTC.
Looking at .net code, seems that A is related to Era (AD is also valid).

What worries me is that "Mon, 10 Oct 2011 11:22:33 A" is parsed to a certain value in .NET, and we'll be overriding that. If going with this change we need to convince ourselves that this is the right thing to do.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also how will this "Mon, 10 Oct 2011 11:22:33 AD" get parsed?

case "W": offset = TimeSpan.FromHours(10); break;
case "X": offset = TimeSpan.FromHours(11); break;
case "Y": offset = TimeSpan.FromHours(12); break;
case "A": offset = TimeSpan.FromHours(1); break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The sign of all the offsets for A to Y was backwards.


private Test[] _tests = new Test[]
{
public static object[][] TestParseDatesData => [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Convert to supply data to a Theory.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Looks good, just a question about "A" and "Z" abbreviations.

@@ -1373,7 +1373,7 @@ private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
{
// if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
DateTime dateTime;
if (DateTime.TryParse(dateTimeString, out dateTime))
if (!dateTimeString.EndsWith("A") && DateTime.TryParse(dateTimeString, out dateTime))
Copy link
Contributor

Choose a reason for hiding this comment

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

Any chance there might be a collision with some other format ending with "A"?
Also there is not handling for "Z", is it a known abbreviation for UTC?

@@ -1373,7 +1373,7 @@ private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
{
// if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
DateTime dateTime;
if (DateTime.TryParse(dateTimeString, out dateTime))
if (!dateTimeString.EndsWith("A") && DateTime.TryParse(dateTimeString, out dateTime))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the existing test data nothing else ends with "A". But you are right, there might be a timezone abbreviation we don't know about that ends in A.

We could use a regular expression:

if (!Regex.Matches(dateString, "[0-9 ]A$") && ...)

@@ -1373,7 +1373,7 @@ private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
{
// if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
DateTime dateTime;
if (DateTime.TryParse(dateTimeString, out dateTime))
if (!dateTimeString.EndsWith("A") && DateTime.TryParse(dateTimeString, out dateTime))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a test case for Z. I think it is a standard abbreviation for UTC and is handled by DateTime.TryParse.

case "V": offset = TimeSpan.FromHours(-9); break;
case "W": offset = TimeSpan.FromHours(-10); break;
case "X": offset = TimeSpan.FromHours(-11); break;
case "Y": offset = TimeSpan.FromHours(-12); break;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you mean that we should add a case for "Z" here?

I don't see how we would ever reach here with a "Z" because DateTime.TryParse would have already handled it.

@rstam rstam requested a review from BorisDog May 7, 2025 23:14
Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Follow up on A (and AD) "timezones".

@@ -1373,7 +1373,7 @@ private DateTime ParseJavaScriptDateTimeString(string dateTimeString)
{
// if DateTime.TryParse succeeds we're done, otherwise assume it's an RFC 822 formatted DateTime string
DateTime dateTime;
if (DateTime.TryParse(dateTimeString, out dateTime))
if (!dateTimeString.EndsWith("A") && DateTime.TryParse(dateTimeString, out dateTime))
Copy link
Contributor

Choose a reason for hiding this comment

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

Also how will this "Mon, 10 Oct 2011 11:22:33 AD" get parsed?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants