EntropySink

Technical & Scientific => Programming => Topic started by: ober on November 01, 2016, 10:26:47 AM

Title: Handling timezone conversion
Post by: ober on November 01, 2016, 10:26:47 AM
So I'm freelancing an app and this is the first time I'm trying to handle timezone conversion.  Everything is stored in the DB as UTC and I've got the profile setup correctly with the timezone.  According to StackOverflow, I'm doing it correctly, but the load time for my overview screen increased dramatically.  Like I'm doing local development with a vagrant box and prior to the change, loading ~25 records was almost instant.  Now it's taking almost 3 seconds.

I do the following:
Code: [Select]
$usersTimezone = new \DateTimeZone($_SESSION['tz']);  // this is outside the loop
foreach($row as $key) {
  // get other fields
  $updated = new \DateTime($key->updated);
  $updated->setTimeZone($usersTimezone);
  $outrow['updatedate'] = $updated != '' ? $updated->format("n/j/Y") : "Never";
}
[code]

I wonder if I could create the DateTime object once and reuse it?

Title: Re: Handling timezone conversion
Post by: ober on November 01, 2016, 11:41:52 AM
I guess I have a different question.  I'm setting the PHP (application) timezone to be UTC (date_default_timezone_set('UTC');).  If I change that timezone setting in PHP for each user, will the DB store a central value that will convert for other users? 

Ugh, I need to do some testing.
Title: Re: Handling timezone conversion
Post by: ober on November 03, 2016, 11:09:21 PM
So... finally got back to this.  I'm a fucking idiot and I was passing the wrong variable to the date functions.  The added time was the app dumping a ton of errors to the error log.  Ooops! 
Title: Re: Handling timezone conversion
Post by: KnuckleBuckett on November 04, 2016, 05:59:51 AM
Prolly all that hair over your eyes. 

Check this shit out.

https://www.amazon.com/Unisex-Spring-Accessory-Beauty-hair/dp/B00IP5Y4CM/ref=sr_1_1_s_it?s=beauty&ie=UTF8&qid=1478253538&sr=1-1&keywords=hair+holder

YW
Title: Re: Handling timezone conversion
Post by: ober on November 04, 2016, 09:08:14 AM
Perfect!  I've been looking for one just like that!
Title: Re: Handling timezone conversion
Post by: KnuckleBuckett on November 05, 2016, 12:23:50 AM
Perfect!  I've been looking for one just like that!