XF 2.2 Sanity Check on setting date and time

Dannymh

Active member
Hi,

I am having some trouble with setting a timestamp. it seems to be setting the timestamp ahead of where it should be. As in I set it with the users timezone, but then read with my timezone it is taking that as a GMT time stamp and setting that.

The Code I am using is

PHP:
$tz = new \DateTimeZone(\XF::visitor()->timezone);
            $theDate = $this->custom_fields->endDate." ".$this->custom_fields->end_time.":00";
            $dateTime = new \DateTime($theDate, $tz);
            $this->custom_fields->endTimeStamp = $dateTime->getTimestamp();

This is inside an extended thread entity as an example if this ran with

PHP:
$tz = new \DateTimeZone('sydney/Australia');
$theDate = "2023-09-26 15:00";

it would return a timestamp of 1695368508

Which when evaluated returns Wednesday, 27 September 2023 12:00:00 AM GMT+10:00 for that same timezone

I know that a lot of time parsing in xenforo tries to be as automated as possible, however I want to be able to set a specific time of day that is relevant to the poster and the readers should be working off of that.

Should I just be setting that without the timezone and evaluating on read?[/code]
 
My code was correct, but old stupid me didnt realise the new test user was pointing at GMT hahaha
 
Back
Top Bottom