7

I am using the Calendar form field type and am experiencing an odd result. I am passing in a date of 03/23/2016 as a string and it is instead showing 03/22/2016. This is true for all dates I have tested. They are always displayed 1 day earlier than the input I provided (e.g. 05/31/2016 will render as 05/30/2016). Here is how I am rendering the field:

<?php 
    $myDate = '03/23/2016';
    echo $this->form->getInput('date', null, $myDate);
?>

And here is the XML for that field:

<field
  description="COM_MYCOMPONENT_FORM_WEBINAR_DATE_DESC"
  format="%m/%d/%Y"
  label="COM_MYCOMPONENT_FORM_WEBINAR_DATE_LBL"
  name="date"
  type="calendar" />

If I print the date to the screen, it is the correct date. It is only when I put it into the calendar field that it reverts back one day. Any idea why this might be occurring and how I can fix it?

  • 1
    Have you checked the timezones set in both the global configuration and your php.ini to see if there is a conflict? – YellowWebMonkey Jun 25 '16 at 2:48
  • 1
    Have you checked if the wrong day is produced right after passing in that date, or later just for the rendering? What happens with the dates 03/01/2016 and 03/00/2016? – lars k. Jun 29 '16 at 7:47
  • @YellowWebMonkey - The server and Joomla! timezone are both set to PST. That doesn't appear to be the issue. – Zachary Draper Jul 6 '16 at 1:34
  • @larsk. - When printed to the screen right before the calendar field is rendered, the date is correct. It is only wrong in the calendar. I tested 06/01/2016 and it sets it to 05/31/2016. Interesting question! – Zachary Draper Jul 6 '16 at 1:36
3

When no filter is specified for a calendar field, the system will automatically apply the 'user_utc' filter. According to Joomla!'s documentation, this filter, "calculates the specified value to the time of Greenwich, according to the user time zone settings."

In this case, no timezone adjustment was necessary as the date was already in the appropriate timezone. As such, the 'user_utc' filter is not needed. In order to prevent Joomla! from using that filter, simply add a filter to the form field that doesn't exist. In this case, I used none:

<field
  description="COM_MYCOMPONENT_FORM_WEBINAR_DATE_DESC"
  filter="none"
  format="%m/%d/%Y"
  label="COM_MYCOMPONENT_FORM_WEBINAR_DATE_LBL"
  name="date"
  type="calendar" />

This prevents Joomla! from automatically making timezone adjustments to the date specified.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.