Startseite › Toolset Professional Support › [Gelöst] Universal time for Toolset date field in WordPress admin
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Dieses Thema enthält 24 Antworten, hat 3 Stimmen.
Zuletzt aktualisiert von Nigel vor 1 Jahr, 2 Monaten.
Assistiert von: Nigel.
Hello,
I have created a date field thanks to Toolset (and have checked the date / time option). This field is used by a Toolset postype.
When I'm in the wordpress admin and create a new post of this postype, I can define values for date and time for the field . Fine. But if I'm checking what is really recorded in the database, then, I have a 2 hours delta (meaning the date / time recorded is the universal time and not the local time (which in France is 2 hours difference). I have also checked that the WordPress settings are OK for the date and that the local time is well defined by Paris. The issue is that when I'm using the date to make a conditional output, I have the 2 hours delta compare to what I'm trying to have !
Is there any way to have the right record in the database from the beginning?
For info, I have tried the same on another site and found the same issue !!!
Regards
Pat
Sprachen: Englisch (English ) Spanisch (Español )
Zeitzone: Europe/London (GMT+00:00)
Hi Pat
This is a long-standing problem that we are not really able to fix because of backwards compatibility issues that would affect existing sites.
Types has done this incorrectly since day one, and we are kind of stuck with it.
When Types converts a date/time entered in a human-readable format in a date field to a timestamp to store in the database, it should first convert the date/time to UTC (timestamps by definition are UTC-based), and then when displaying the field value it should convert from UTC to local time and then output the formatted time.
But it doesn't. It just takes the local time and generates a "timestamp" from it, without first converting it to UTC.
One solution would be for you to intervene when saving date/time fields to the database and correcting the timestamp and again intervening when displaying fields to output the adjusted local time.
Hi Nigel,
I understand your point. My issue is that the field is not filled thanks to a Forms but in the WordPress admin.
So, best way should be to add something in the conditional output in order to manage the local time if possible.
Regards
Pat
Hi Nigel,
Just for info, here is the code I'm using for the conditional output :
[wpv-conditional if="( date_debut_ins() lte [post-today] ) AND ( date_fin_ins() gt [post-today] )" evaluate="true"]
With this code I'm verifying that we are inside the right period : date_debut_ins (starting date) to date_fin_ins (end date) in order to display the buy button. If outside this period, the button is not displayed.
Currently, the button is available on the site 2 hours after what have been defined in the field.
So, as I understand this would be very complicated to modify the Toolset behavior on this topic, perhaps the best would be to adapt the code of the conditional output to work in the local timing (but we have also to take into account the summer / winter changes that could happen ?).
Let me know
Regards
Pat
Thank you for sharing the information. You should also share the shortcode code you are using so that it might help other users.
Hi Minesh
Sorry I cannot share access info as the site is in production.
You can find the shortcode used in my first message of this topic
Hope this helps
Regard
Pat
I asked for benefits of other users - its on you, if you want to share the code you used for shortcode then it will help other users otherwise its ok. You are welcome to mark resolve this ticket.
Hi Minesh
Dont know if I missed something but i have not got à.y answer on how to modify the conditional shortcode in ordre to integrate the local time.
Can you check please
Regards
Pat
Sorry but with the following reply you shared the conditional code:
=> https://toolset.com/forums/topic/universal-time-for-toolset-date-field-in-wordpress-admin/#post-2635949
Can you please tell me where exactly you need help?
Hi Minesh
I need to make sure my code works well with the local time. As I understand from Nigel, Toolset has not managed correctly this from the beginning and now, the only way is to modify the conditional output. I need to have this updated code to be sure the conditional output will give the correct local time, which is not the case tokay (2 hours delta between France and universal time).
Regards
Pat
Can you please share details about what timezone time you want to compare with and share admin access details and problem URL and what is your expected output.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Hi Minesh
Sorry but the site is in production and I cannot give you access.
This site is working only for french user in France. So I Just need to manage the 2 hours difference with UTC time when usine the conditional shortcode given in my first message of this topic
Regards
Pat
You shared the following conditional code:
[wpv-conditional if="( date_debut_ins() lte [post-today] ) AND ( date_fin_ins() gt [post-today] )" evaluate="true"]
But I'm not sure what code is used that build the function date_debut_ins() and date_fin_ins(), also, what would be the code used for the shortcode [post-today].
Can you please share the source code of those functions and shortcode and also tell me you want to add 2 hours or deduct two hours from the time. It seems you want to deduct the two hours from the values return by functions and shortcodes - correct?
Hi Minesh :
Here is function date_debut_ins :
function date_debut_ins( ) { $id_va = 18207; $datedebut = get_post_meta($id_va, 'wpcf-date-debut-inscription-site', true ); return $datedebut; } add_shortcode( 'date-debut-ins', 'date_debut_ins' );
Here is function date_debut_ins :
function date_fin_ins( ) { $id_va = 18207; $datefin = get_post_meta($id_va, 'wpcf-date-fin-inscription-site', true ); return $datefin; } add_shortcode( 'date-fin-ins', 'date_fin_ins' );
Here is shortcode [post-today'] :
add_shortcode('post-today', 'today_shortcode'); function today_shortcode() { date_default_timezone_set('Europe/Paris'); $timestamp = time(); return $timestamp; }
For info, post ID 18207 is a specific post used to define some global variables. For that, I have created some date fiields (wpcf-date-debut-inscription-site and wpcf-date-fin-inscription-site.
Hope this helps
Regards
Pat
It seems you forget to answer the following:
Can you please share the source code of those functions and shortcode and also tell me you want to add 2 hours or deduct two hours from the time. It seems you want to deduct the two hours from the values return by functions and shortcodes - correct?