bggann
Active Member
I've got a form with a jdate field - only the date is used
Conditions:
- jdate field
- Default to 'today' (doesn't matter for this case)
- No time selector.
- Validation "notempty"
- Ajax validation on.
- Date stored as UTC
- Local timezone MST (6 hours off)
What happens it:
- You open a record existing - (this does not seem to happen on new record).
- You pick a date - say 1 day in the future.
- AJAX validation runs
- The date jumps back by one day, so if you pick 2021-09-23 you get 2021-09-22
Stepping through the code:
What is happening is:
- The date is set to "2021-09-23 06:00:00" I presume the 06: hour is because 00:00:00 UTC is 06:00:00 MST
In jdate.php function validate() (/* comments below are mine)
if ($this->app->input->get('fabrik_ajax', '0') === '1') /* is this ajax? In my case, yes.
{
if (FabrikWorker::isDate($data)) /* This returns true. $data='2021-09-23 06:00:00'
{
$params = $this->getParams(); /*$params is empty.
$localDate = $this->displayDate($data); /* data='2021-09-23 06:00:00'
/*displayDate returns
$localDate[date] = 2021-09-23 00:00:00.000000
/* Notice the 06: has been removed. This is done inside DisplayDate
/* by $date->setTimeZone($timeZone);
--> At this point the Date we are working with is 2021-09-23 00:00:00.000000
/* Rest of code executes normally but it returns the UTC Date.
----------------------
All great - but this code runs 2 times. On the second run, we are fed in 2021-09-23 00:00:00 so after "setTimeZone()" the date returned is "2021-09-22 18:00:00". 6 hours earlier.
So - the date field jumps back 1 day.
-> It looks like the tzcorrection is being applied 2 times inappropriately.
-----------------------
I'm looking into this - but this is a bit deeper than I can handle. So I wanted to document it. Maybe somebody else wants to tackle it.....
-Bob
Conditions:
- jdate field
- Default to 'today' (doesn't matter for this case)
- No time selector.
- Validation "notempty"
- Ajax validation on.
- Date stored as UTC
- Local timezone MST (6 hours off)
What happens it:
- You open a record existing - (this does not seem to happen on new record).
- You pick a date - say 1 day in the future.
- AJAX validation runs
- The date jumps back by one day, so if you pick 2021-09-23 you get 2021-09-22
Stepping through the code:
What is happening is:
- The date is set to "2021-09-23 06:00:00" I presume the 06: hour is because 00:00:00 UTC is 06:00:00 MST
In jdate.php function validate() (/* comments below are mine)
if ($this->app->input->get('fabrik_ajax', '0') === '1') /* is this ajax? In my case, yes.
{
if (FabrikWorker::isDate($data)) /* This returns true. $data='2021-09-23 06:00:00'
{
$params = $this->getParams(); /*$params is empty.
$localDate = $this->displayDate($data); /* data='2021-09-23 06:00:00'
/*displayDate returns
$localDate[date] = 2021-09-23 00:00:00.000000
/* Notice the 06: has been removed. This is done inside DisplayDate
/* by $date->setTimeZone($timeZone);
--> At this point the Date we are working with is 2021-09-23 00:00:00.000000
/* Rest of code executes normally but it returns the UTC Date.
----------------------
All great - but this code runs 2 times. On the second run, we are fed in 2021-09-23 00:00:00 so after "setTimeZone()" the date returned is "2021-09-22 18:00:00". 6 hours earlier.
So - the date field jumps back 1 day.
-> It looks like the tzcorrection is being applied 2 times inappropriately.
-----------------------
I'm looking into this - but this is a bit deeper than I can handle. So I wanted to document it. Maybe somebody else wants to tackle it.....
-Bob