<xf:date> displays day in browser timezone not forum/account timezone

K a M a L

Well-known member
Affected version
2.2.latest
Currently Xenforo <xf:date> displays day from browser timezone not account timezone when they mismatch
assume you have
<xf:date time="1668142595" />
your browser time zone is UTC
your forum account time zone is (UTC-06:00) Central Time (US & Canada)

when page is rendered it has the correct PHP time and day
HTML:
<time  class="u-dt" dir="auto" datetime="2022-11-10T22:56:35-0600" data-time="1668142595" data-date-string="Nov 10, 2022" data-time-string="10:56 PM" title="Nov 10, 2022 at 10:56 PM">Thursday at 10:56 PM</time>

but as soon as Javascript time refreshes it becomes
HTML:
<time class="u-dt" dir="auto" datetime="2022-11-10T22:56:35-0600" data-time="1668142595" data-date-string="Nov 10, 2022" data-time-string="10:56 PM" title="Nov 10, 2022 at 10:56 PM">Friday at 10:56 PM</time>

Because Xenforo Javascript code doesn't consider account time zone when calculting day
JavaScript:
$el.text(XF.phrase('day_x_at_time_y', {
   '{day}': XF.phrase('day' + new Date(thisTime * 1000).getDay()),
   '{time}': $el.attr('data-time-string') // must use attr for string value
}))
 
Last edited:
Top Bottom