#gofish

1 messages ยท Page 1 of 1 (latest)

orchid mangoBOT
vapid saffron
#

Apologizes if that was the wrong spot :/

jovial oxide
#

Hi gimme some time to get through it

vapid saffron
#

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!

jovial oxide
#

Hey sorry we can't provide call here but I am happy to help over this chat

vapid saffron
#

No worries!

jovial oxide
#

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?

vapid saffron
#

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

jovial oxide
#

Hmm I see subscriptionAnchorDate() is a purely calculated function. what does subMonth() do btw?

vapid saffron
#

Example from tinker session:

#

Woh wait, hold on. Did it change the -8 to -7??

jovial oxide
#

Yep xD

vapid saffron
#

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

jovial oxide
#

good luck!

vapid saffron
#

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

jovial oxide
#

Happy you figured it out. If you need further help feel free to ask in the channel!