Skip to content

Conversation

@rsnet
Copy link

@rsnet rsnet commented Nov 10, 2025

Enhanced the UnixDateTimeConverter to handle values that are milliseconds since Unix Epoch, in addition to normal values (seconds since Unix Epoch).

Why?

In #3157 there are multiple reports (stack traces) of the UnixDateTimeConverter being responsible for incorrect values being put into the method System.DateTime.AddSeconds(Double value).

The root cause is Stripe API responses sometimes return long values that are the milliseconds since Unix Epoch, instead of the seconds since Unix Epoch (typical). I was able to determine this by debugging through the code during a request in a Sandbox - I found that some values (in the responses from the Stripe API) that were being converted by the UnixDateTimeConverter were larger than 253402300799. I noted some of these values, and converted these long values using DateTimeOffset.FromUnixTimeMilliseconds(long milliseconds), and found that the values converted nicely to dates very close to my requests (or data in my requests).

In the few requests that I debugged through, most Unix Epoch values are seconds; unfortunately one was milliseconds.

What?

This PR enhances the UnixDateTimeConverter, so that it can automatically handle both types of Unix Epoch values that the Stripe API returns:

  • seconds since Unix Epoch
  • milliseconds since Unix Epoch

It uses a the value 253402300799 as the maximum allowable value for seconds since Unix Epoch, and presumes all values greater than this are milliseconds since Unix Epoch.

Two new unit tests were created for the UnixDateTimeConverter to verify it can handle both cases correctly.

See Also

See my post on Issue 3157 showing the stack trace when the UnixDateTimeConverter.cs attempts to convert values that are milliseconds since Unix Epoch.

…onds since Unix Epoch, in addition to normal values (seconds since Unix Epoch).
@rsnet rsnet requested a review from a team as a code owner November 10, 2025 21:27
@rsnet rsnet requested review from jar-stripe and removed request for a team November 10, 2025 21:27
@cla-assistant
Copy link

cla-assistant bot commented Nov 10, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@cla-assistant
Copy link

cla-assistant bot commented Nov 10, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@jar-stripe
Copy link
Contributor

Hi @rsnet thank you for submitting this PR! I recall this being an issue but I thought we had previously addressed it; let me do a bit a research and then I'll review your PR. Thanks!

@prathmesh-stripe
Copy link
Contributor

@rsnet Can you please sign the CLA agreement in order to accept your PR

@rsnet
Copy link
Author

rsnet commented Nov 18, 2025

@prathmesh-stripe, I have tried to sign the CLA multiple times. On the second screen, it never presents a button to move forward (like the first screen). SAP needs to fix it.

@prathmesh-stripe
Copy link
Contributor

@rsnet Can you share a video screenshare of what you are seeing? I tried signing it myself, I had to authorize the cla-assistant app with my Github account and then fill in Country at the bottom before clicking I agree. It took me another screen that redirected me back to Github.

@prathmesh-stripe
Copy link
Contributor

We ended up releasing a fix for this in: https://github.com/stripe/stripe-dotnet/releases/tag/v50.0.0

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.

4 participants