Our component manages Television programming, so dates & times are critical - here's the scenario:
- Our server and most producers are all on local, Pacific Time (America/Los_Angeles, UTC+8)
- Joomla is configured with the timezone being "America/Los_Angeles" (
public $offset = 'America/Los_Angeles';) because that IS the timezone we're in.
- The database has a
datefield specifying when the episode is scheduled to be aired - the actual time is unknown.
- It also has a
datetimefield specifying when the episode was actually aired, including the time it was aired.
The episode in question has a scheduled date of "2015-01-02" (time is unknown). Using a Calendar field type, it always displays 2015-01-01, presumably because it's defaulting to 00:00:00 as the time and subtracting 8 hours due to the offset.
So, the question comes down this is:
- Does the calendar field type have a bug because it's a Calendar, not a clock, so should not be considering the time,
- or should we have Joomla configured to use the UTC time zone?
- or am I missing something fundamental here?
And finally, if the displayed date is going to "fluctuate", is there a best-practices method to advise the user which time zone is in play? i.e. The episode is going to air Jan 2nd local time, yet the calendar is displaying Jan 1st.
I apologize for the general confusion of the question - I've been chasing this for a bit, and am not sure of what the Timezone premises are that Joomla runs on, so what the expected output should be.
I'm not using
JHtml::calendar directly, but via my form:
<field name="first_aired" type="calendar" label="COM_PASS_EPISODES_EPISODES_FIRST_AIRED_PLANNED_LABEL" description="COM_PASS_EPISODES_EPISODES_FIRST_AIRED_DESC" class="required span2 validate-airdate" default="NOW" format="%Y-%m-%d" />
The code in
libraries\joomla\form\fields\calendar.php does it's thing, then simply uses
return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
The Calendar Field docs say that only SERVER_UTC or USER_UTC are allowed for the optional
filter element, and omitting it or specifying "" defaults to USER_UTC, but specifying anything invalid skips the code that adds the offset, so show the actual date regardless of having a time or not.