Closed jeffw-wherethebitsroam closed 5 months ago
The PR only fixes half of the problem.
When Entity framework fetches DateTime's from the database, they are fetched at DateTimeKind.Unspecified
. This is a problem when converting to other formats, for example DateTimeOffset
, especially when the value stored is 0001-01-01 00:00:00.0000000
. The implicit conversion to DateTimeOffset
is a non-UTC timezone can cause an ArgumentOutOfRangeException
.
There are 2 solutions to this issue:
DateTimeOffset
in the entities.DateTime
as UTC (e.g. https://stackoverflow.com/a/73154546/945878)Hi @jeffw-wherethebitsroam I think this is related to whats coming back from the marketplace API. For the resolve the dates really doest make much sense as they are only sent on activation or renewal. We will be implementing the same.
I am no longer working on this.
Describe the bug When running the CustomerSite landing page locally I get the exception:
Error 500 : The UTC time represented when the offset is applied must be between year 0 and 10,000. (Parameter 'offset')
If I remove the try/catch block in HomeController.Index, I get:
To Reproduce I loaded the landing page with a token. The subscription object returned from the fullfillment API had these dates:
It seems like there is some problem with the timezone conversion. I'm in UTC+1.
In
FulfillmentApiService
the term endDate and startDate returned frommarketplaceClient.Fulfillment.GetSubscriptionAsync
areDateTimeOffset?
.The
Subscription
is converted to aSubscriptionResult
viaConversionHelper.subscriptionResult
which retains them asDateTimeOffset?
.The
HomeController
then callssubscriptionService.AddOrUpdatePartnerSubscriptions(subscriptionData)
with theSubscriptionResult
.AddOrUpdatePartnerSubscriptions
then converts theDateTimeOffset?
toDateTime
using:This is problematic since
DateTimeOffset.DateTime
always return a DateTime with kindDateTimeKind.Unspecified
.A little time later in the
HomeController
the same subscription is fetched from the repo viasubscriptionService.GetSubscriptionsBySubscriptionId
. There, inPrepareSubscriptionResponse
the error occurs:Here it is implicitly converting the DateTime with unspecified kind to DateTimeOffset. This is where I see the exceptions.
Expected behavior Dates to be handled.
Screenshots If applicable, add screenshots to help explain your problem.
Environment (please complete the following information): UTC+1
Additional context Add any other context about the problem here.