Extract date returns the wrong date

I’ve been working on this for days, utterly confused. It might be a bug, but I think it’s not – there’s probably a logic in here that I’m overlooking… but it’s driving me insane at the moment.

I have a Promotion that is active certain days, and time of the day, for example Mondays from 10 am to 1pm and Thursdays from 10 am to 3 pm. The are saved like this:

Type: Promotion
Monday: (date range with time, for example June 1st 2017. 10 am ↔ June 1st 1 pm
Tuesdays: blank
Wednesdays: blank
Thursday: (date range with time, for example June 1st 2017. 10 am ↔ June 1st 3 pm

Every morning, an API script fetches the time_from and time_to from the relevant day:

It then generates the date range to save today’s validity:

All good, right? Except, when the time is 4 am or earlier, it adds an extra day to the date:

So I try to correct this by subtracting 1 from the date, if extract:hour is equal to or less than 4. The problem is, it applies this no matter what time extract:hour returns, so that the date is wrong if the time is after 4 am.

I’ve been trying to solve this for days. Sometimes it seems to work, and then suddenly the day after it doesn’t work anymore. It should be simple but is driving me crazy. Anyone know any tricks of logic here that I’m unaware of?

I appreciate all suggestions!

Did you resolve this, @petter?

What do you mean by “every morning”, what time/timezone is the schedule set for? By 4am do you mean your local timezone?

For “extract date” and “change date” to be meaningful, it has to be considered in context of a time zone, which should be UTC when running in an API workflow.

For debugging, try displaying all the date/times in UTC format to see if you can see what logic is happening.

Also, to make your date change more reliable around leap year days, etc, its best to set year, month, date in that order.

1 Like

Hi @mishav, sorry for the late reply, I posted just before I went travelling :slight_smile:

I haven’t had the chance to debug it further yet, but it might be a timezone problem, as you suggest. I just can’t seem to grip why it would return one date in some cases, and a different one in the API workflow. When I set it up on a page with visible text fields, it always returns the correct date, but in the API workflow, it returns a different one.

I suspect (just thinking about it now) that the page workflow uses the user’s local time zone, while API workflow uses Bubble’s time zone. I’ll try to supply the workflow with the date as an argument, instead of generating it in the API workflow itself, maybe that solves it.

What do you mean by “every morning”, what time/timezone is the schedule set for? By 4am do you mean your local timezone?

Actually, it is updated by the first customer of the day that visits. The promotion is connected to a venue. So let’s say you have

Venue: Petter’s place
Promotion: VIP member promotion

So upon the first loading of the day of Petter’s place, the API workflow is triggered, and saves a “last updated” date, that stops it from triggering on subsequent loading. I did it to avoid a heavy API workload all at once with all venues, and instead doing it as needed.

I’m at a complete loss… even when I ignore the date altogether, and just pass a number as a parameter to the API, it ends up with the wrong date…!

I schedule the API, setting “5” as Date parameter:

I use the parameter to make changes in the date:

And still they end up different…

@emmanuel What is it that I’m missing here?

This topic was automatically closed after 70 days. New replies are no longer allowed.