6

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?

4
  • 1
    Have you checked the timezones set in both the global configuration and your php.ini to see if there is a conflict? Jun 25, 2016 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, 2016 at 7:47
  • @YellowWebMonkey - The server and Joomla! timezone are both set to PST. That doesn't appear to be the issue. Jul 6, 2016 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! Jul 6, 2016 at 1:36

1 Answer 1

7

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 agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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