Author Topic: Handling timezone conversion  (Read 899 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14217
  • Karma: +72/-788
  • mini-ober is taking over
    • Windy Hill Web Solutions
Handling timezone conversion
« 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?


ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14217
  • Karma: +72/-788
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Handling timezone conversion
« Reply #1 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.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14217
  • Karma: +72/-788
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Handling timezone conversion
« Reply #2 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! 

KnuckleBuckett

  • Jackass In Charge
  • Posts: 9588
  • Karma: +26/-259
  • [url=http://google.com]I search a lot[/url]

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14217
  • Karma: +72/-788
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: Handling timezone conversion
« Reply #4 on: November 04, 2016, 09:08:14 AM »
Perfect!  I've been looking for one just like that!

KnuckleBuckett

  • Jackass In Charge
  • Posts: 9588
  • Karma: +26/-259
  • [url=http://google.com]I search a lot[/url]
Re: Handling timezone conversion
« Reply #5 on: November 05, 2016, 12:23:50 AM »
Perfect!  I've been looking for one just like that!