Skip Navigation

[Resuelto] Universal time for Toolset date field in WordPress admin

This support ticket is created hace 1 año, 3 meses. There's a good chance that you are reading advice that it now obsolete.

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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 24 respuestas, tiene 3 mensajes.

Última actualización por Nigel hace 1 año, 2 meses.

Asistido por: Nigel.

Autor
Mensajes
#2635683

Pat

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

#2635759

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: 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.

#2635787

Pat

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

#2635949

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

#2636055

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Thank you for sharing the information. You should also share the shortcode code you are using so that it might help other users.

#2636681

Pat

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

#2636697

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2636757

Pat

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

#2636961

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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?

#2636975

Pat

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

#2637061

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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.

#2637147

Pat

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

#2637527

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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?

#2637545

Pat

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

#2637555

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

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?