#gofish
1 messages ยท Page 1 of 1 (latest)
Apologizes if that was the wrong spot :/
Hi gimme some time to get through it
If it makes things easier, we can jump on a quick voice call.
It's affecting revenue for this web application, but I'm hesitant to just add the ->addHour() function call because I'll need to reverse that change when DST flips.
Appreciate the help!
Hey sorry we can't provide call here but I am happy to help over this chat
No worries!
So it's likely to be affected by Daylight Saving Time, and you notice it happens from Summer?
I believe Subscriptions are all calculated based on Unix time, which shouldn't be affected by DST ๐ค
ah this is before translate into Unix time?
It's strange. I'll get the exact date I noticed the code begin producing 280.xx vs a flat 280
It looks like the issues began occurring October ~Oct 10
So in the code there is the method subscriptionAnchorDate()
/**
* Get the anchor date for any subscription
*
* @return \Carbon\Carbon
*/
public function subscriptionAnchorDate(): Carbon
{
$anchor = now()->day(12)->startOfDay();
if ($anchor->isPast() || $anchor->isToday()) {
$anchor = $anchor->addMonth();
}
return $anchor;
}
The subscription creation then anchors on this date and attempts to backdate the start by a single month
public function handle(Rider $rider, Closure $callback = null): Subscription
{
$rider->createOrGetStripeCustomer($rider->stripeConfiguration());
$builder = $rider->newSubscription(
Rider::SUBSCRIPTION_NAME, $rider->coordinator->pool->organization->stripe_price_id
)->allowPaymentFailures()
->anchorBillingCycleOn($rider->subscriptionAnchorDate());
if ($callback) {
$builder = $callback($builder, $rider);
}
return $builder
->create(
subscriptionOptions: [
'backdate_start_date' => $rider->subscriptionAnchorDate()->subMonth()->getTimestamp(),
],
);
}
Nothing in the code changed Oct 10th, but the creations began charging an additional $.38 which is the cost of a prorated hour
Hmm I see subscriptionAnchorDate() is a purely calculated function. what does subMonth() do btw?
Submonth, a carbon function (https://www.itsolutionstuff.com/post/laravel-carbon-subtract-months-from-date-exampleexample.html) will take the given Carbon Date object and take a single month
Example from tinker session:
Woh wait, hold on. Did it change the -8 to -7??
Yep xD
Aight time to go checkout if carbon added a breaking change ~Oct 10
Sept 2nd...
Thank you, I'm going to go bother Carbon now ๐
Woh! It's actually because adding a month pushes to the new DST offset and then sub month pulls it back
good luck!
Thank you, you can go ahead and close this issue. You're help was awesome, appreciate it!
The handle function became...
public function handle(Rider $rider, Closure $callback = null): Subscription
{
$rider->createOrGetStripeCustomer($rider->stripeConfiguration());
$builder = $rider->newSubscription(
Rider::SUBSCRIPTION_NAME, $rider->coordinator->pool->organization->stripe_price_id
)->allowPaymentFailures()
->anchorBillingCycleOn($rider->subscriptionAnchorDate());
if ($callback) {
$builder = $callback($builder, $rider);
}
// Calculate DST offset change
$offset = $rider->subscriptionAnchorDate()->offsetHours - $rider->subscriptionAnchorDate()->subMonth()->offsetHours;
return $builder
->create(
subscriptionOptions: [
'backdate_start_date' => $rider->subscriptionAnchorDate()
->subMonth()
->subHours($offset)
->getTimestamp(),
],
);
}
Included calculating the offset's offset and subing / adding that number of hours
So DST negative will sub a neg hours (so add an hour), and when we get to the March timeframe it will sub a positive number of hours
Happy you figured it out. If you need further help feel free to ask in the channel!