jdate plugin - when using Local Time

thellie

Member
Hi,
I'm not sure if this is a bug or not. If I set it to UTC the dbase will show the UTC datetime and the front end will show the timezone adjusted datetime. I'm based in Thailand btw...

However, what I'm getting is, when saving a datetime jdate (Server timezone: Bangkok / jdate: Local time):
  • it saves the local time to the dbase (correctly)
  • but when reopening the record it shows the local time + the time difference (7 hrs)
Does that make sense?

Example A
Bangkok / UTC
set jdate to 09:55
MySQL = 02:55
Front end = 09:55

which is correct...

Example B
Bangkok/Local time
set jdate to 09:55
MySQL = 09:55
Front end = 16:55

which is incorrect. The front end should still be showing 09:55, not adding the time difference.

I realise I could just keep the jdate element as UTC, but I prefer to use local time when creating jdate elements because if I have to refer to data in the MySQl dbase the datetime will be the same as in the front end.

Or is my thinking squiffy..?
 
In most cases it is a good idea to use UTC time and do the timezone/DST calculations in your PHP code. But if your users are 100% from Thailand and as I know, Thailand has no daylight saving times, "Local" time should work fine and you don't need to do any timezone calculations in your code.

Anyway, I see your point above and I agree this should be the way the jdate behaves.

I made some tests and I get also weird results.

1) UTC
- UTC time during the adding of new record is 10:00
- After record added, time in database is 11:00, so 1 hour more than the UTC time

2) Local time
- Works fine for me. If I add record at 10:00 local time, then 10:00 is recorded in database

Hope some of the core developers can confirm this.
 
Nevermind, I had UTC as the timezone at my test site for some unknown reason. I should quit the computer jobs for today and get some fresh air :).

But anyway, I now seem to be able to replicate the Example B in the OP's post. With "Local time" setting, same time is added in the database as selected in the jdate field. But when the date is displayed e.g. in list, timezone hours are still added.
 
Last edited:
Can you change line 448 of plugins/fabrik_element/jdate/jdate.php to return false instead of true. I believe this is where the problem arises. I tried an element in both UTC and Local and it seems to work for me but could probably use a little more testing.
 
Has anything been amended in the Zeta version of this plugin?

I'm getting a similar issue to the original problem, but for the front end:

Example A
Bangkok / UTC
set jdate to 1 Jan 2024 09:40
MySQL = 1 Jan 2024 02:40
Front end = 2 Jan 2024 16:09

which is correct...

Example B
Bangkok/Local time
set jdate to 1 Jan 2024 09:40
MySQL = 1 Jan 2024 09:40
Front end = 2 Jan 2024 16:09

The jdate format for list and form is: j M Y (H:i)
But it looks like minutes are replacing the hour and hours are replacing the minutes, so the actual format is j M Y (i:s)

Example C
Bangkok/UTC

In the Formatting & Time tab, Show time selector is enabled, but the format is left blank
In the Date formats tab, if I set the format to: j M Y (H:i:s)
The front end shows: 1 Jan 2024 (00:09:40) 00:09

Can anyone replicate this?
 
That hasn't made a difference - see screenshots below
I'm inputting 1 January 2024 09:40, using Bangkok/UTC 24 hour settings.

If I turn off the 'Show time selector', the date appears correctly: 1 Jan 2024. If I turn it on, I now get 25 Mar 2024 08:09
The list shows the date & time correctly.

Screen Shot 2566-12-14 at 09.10.37.png Screen Shot 2566-12-14 at 09.11.43.png Screen Shot 2566-12-14 at 09.13.01.png Screen Shot 2566-12-14 at 09.16.55.png Screen Shot 2566-12-14 at 09.25.02.png
 
Last edited:
I have another element below the Flight date & time element, called Pickup location - this is a calc to summarise where/when to pick up the volunteer.

In the code, I have a variable to show the flight arrival time. If it's ..._raw, the time is correct, ie same as the MySQL field: 02:40. If it's not ..._raw, then the time shows as 7:40 PM, which is 10 hours off.

I'm using PHP 8.1, and I'm hosted by Hostinger. I can't revert to 8.0, and 8.2 gives me the same results.

Code:
$pickup_startdate = date('d-m-Y', strtotime('{vol_appform___startdate_raw}'));
$pickup = '{vol_pickup___pickup_raw}';
$pickup_flight_number = '{vol_pickup___flight_number_raw}';
$pickup_flight_date = date('d-m-Y', strtotime('{vol_pickup___arrival_time_raw}'));

--------->>>> $pickup_flight_time = date('g:i A', strtotime('{vol_pickup___arrival_time_raw}'));

if($pickup === 'airport' && ($pickup_startdate === $pickup_flight_date))
{ return 'Chiang Rai airport: ' . $pickup_flight_date . ' ('. $pickup_flight_time . ')';}
elseif($pickup === 'airport' && ($pickup_startdate != $pickup_flight_date))
{ return 'Baan Pordeedin at 11:00 on ' . $pickup_startdate;}
elseif($pickup === 'pordeedin')
{ return 'Baan Pordeedin at 11:00 on ' . $pickup_startdate;;}
elseif($pickup === 'other')
{ return '{vol_pickup___if_other}';}
else
{ return ' - Unknown - please advise us before your form cut off date';}
 
I now get 25 Mar 2024 08:09
This is replicatable.
It's only if you use "j" as date's day format and the given day is single digit (took me a while to get it reproduced:rolleyes:).
So as a quick work around set "d M Y" as form format
 
There are several conversions from and to php date and strftime formats + formatting done by JS.

You can change plugins\fabrik_element\jdate\jdate.php line 2996
from
'j' => '%e',
to
'j' => '%d',

I added this fix for the next release.
This will force form view to two digit day but keeps the one digit day in details view (don't ask why:confused:)
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top