Support

Account

Home Forums General Issues Zulu time in Date picker

Solved

Zulu time in Date picker

  • I have a custom User meta field called vino_article_date.
    For each user, it is created via background PHP/plugin processes.
    It saves a date and time to the meta in the Zulu format.
    Example: 2017-12-06T00:17:50Z

    Now, I want to make this field also editable in the User edit screen.
    I already have a field group on this screen.
    Now I have added a field with the corresponding name, vino_article_date.
    I make this using the Date Time Picker.
    And I want to be able to change the date-time and re-save from there.

    But I need to be certain the date-time formats are going to line up.
    There is no preset option resembling the above Zulu format for me to select.
    Do I need to use “Custom” to force it?
    Eg. Y-m-d\TH:i:s\Z , which mirrors the earlier process in my code which created the date…

    $params['published_at_start'] = $lastFetchedAt->format('Y-m-d\TH:i:s\Z');

    … ?

    When I do that and load a User profile, the text input box comes up with the correct original date, in that original format. But, when I click in it, the Date-Time picker opens on the current date, with time 00:00:00 Z – it doesn’t inherit the actual value. See grab…

    Grab

    Is this the actual behaviour of the Date Time Picker, or is something wrong?

    And is there anything else I should know about?

    Thanks.

  • This is just a guess, I can’t give you an example, only where to start looking.

    I’m pretty sure that this the actual behavior of the Date Time Picker, like you said.

    I think that in order to do this you will need to alter the time zone somehow in the date/time picker, or the time picker as the case may be. Take a look at these hooks on the custom JS page https://www.advancedcustomfields.com/resources/adding-custom-javascript-fields/

    Past this, it should be possible to alter the time used for the specific field, I think. You may need to “Localize” https://codex.wordpress.org/Function_Reference/wp_localize_script your custom JS file with information to use when initializing the field.

  • If it’s the intended behaviour of the picker to ignore the stored and shown date by instead showing the current date upon pending, I think that’s unnecessarily complex on ACF’s part.

    If it’s a Zulu time format issue, then okay.
    But I don’t think I have the wherewithal to make all these changes, I may just set it as a text field and will enter the time in the correct format manually myself.

    Thanks for your ideas, as ever.

  • It’s an issue with changing from using local time to using Z time. The date time picker and the time picker both depend on the jquery date picker. This script picks up the local time on the computer where the browser is being run and has nothing to do with the date as set on the server, or in WP settings.

    I just tested the above, I created one each of the 3 field types (date, time and date/time). I went to edit a page and today/now were my local time. I then changed my computer clock settings, both date and a different hour. When I reloaded the page all fields picked up this new date and time as the current date and time.

    All of which are completely independent of the server, the server where my test site is located is in a completely different time zone than I’m in. And this time is also independent of the time zone set in WP settings which is set to yet another time zone that is not the same as either myself of where the server is located.

    I know it sounds like a lot, but in order to alter the way the picker works you need to do so on the JS side.

    Even then you can never be sure. It would be a simple thing for anyone to set their time zone to whatever they wanted and then change their clock to a day and time that does not correspond to any real world date/time in any time zone, thus making any calculation to get the Z date/time irrelevant.

    I did just find this, and it is possible to use the servers date/time as the default https://stackoverflow.com/questions/5011644/supplying-local-time-generated-from-server-to-jquery-datepicker so it is possible, but then we’re back to my first reply, and I don’t have any code that will help you with this. I did find a couple of other people looking for the same answer but I did not find any answers https://www.google.com/search?q=acf+use+server+date+for+date+picker.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.