#nova-subscription-billingcycleanchor

1 messages · Page 1 of 1 (latest)

quartz pilotBOT
wanton rivet
#

nova-subscription-billingcycleanchor

#

Hey @timid plinth ! What's your exact question?

timid plinth
#

I got this error yesterday

timid plinth
#

When i was trying to set the billing cycle anchor to Tuesday 24th

#

I am using this equation

#

export function getNextDay (dayName, late) {

// The current day
let date = new Date();
date.setHours(13);
date.setMinutes(0);
let now = date.getDay();

// Days of the weekå
let days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];

// The index for the day you want
let day = days.indexOf(dayName.toLowerCase());

// Find the difference between the current day and the one you want
// If it's the same day as today (or a negative number), jump to the next week
let diff = day - now;
let diffTmp = diff;

if(diff < 1 || (diff == 1 && late) || (diff == 2 && late) || (diff == 3 && late)){
diffTmp = diffTmp + 7;
}

// Get the timestamp for the desired day
let nextDayTimestamp = date.getTime() + (1000 * 60 * 60 * 24 * diffTmp);

// Get the next day
return new Date(nextDayTimestamp);
}

}

let next = getNextDay('tuesday', false);

#

I set it here

wanton rivet
#

please no pictures of code

timid plinth
#

Sorry

wanton rivet
#

Let's take a step back. You sent me a picture and a long code. What's your problem exactly in English words? As far as I can tell you are trying to set billing_cycle_anchor and the unix timestamp you calculate is farther in the future than one billing cycle, which is forbidden

timid plinth
#

Yes that is what is happening

#

But i do not understand how it is farther in the future

#

If i have tested my code a couple times and I get the date that i want

#

which is Tuesday 24th

#

I am missing something and i am not seeing it

wanton rivet
#

Okay, can you give me an exact request id req_123 to look at?

timid plinth
#

req_aDMRengMPtUU49

wanton rivet
#

Okay so you passed billing_cycle_anchor: "1675170012" which is Tue Jan 31 2023 13:00:12 UTC which is in more than a week after you sent that request at 2023-01-24 05:59:12 UTC

#

So your code is calculating the billing cycle anchor time incorrectly

timid plinth
#

Can you help me with my code please. The thing is that i have tested the code setting the date of monday 23

#

and i get Tuesday 24th

timid plinth
#

calling it like this "let next = getNextDay('tuesday', false);"

wanton rivet
#

I can't really tell you. You need to debug this on your own locally with various example dates

#

but make sure all your calculations are based in UTC

timid plinth
#

Okay thank you!

wanton rivet
#

Like right now we're Tuesday, if you choose next Tuesday as your anchor, it has to be before the current time that day. So if it's 14:00 UTC you can't anchor to next Tuesday 6pm UTC