tags:

views:

73

answers:

1

Hi all,

This might be a too bigger ask, but before I outsource it, I would like to try to understand it first, and do it for myself.

I am working on a project that involves an existing database. I am building the site around the existing data, but have run into issues with timestamps. Basically, I am hoping someone can give me a snippet example of what I would need(function, or class) to achieve this:

  1. Each user in the database has tables of data which includes content like blogs, articles, and other input containing timestamps for dates.
  2. Each user also has a timezone code(i.e: 10+, 12-, 1+, and so on and so forth) which they manually selected upon signup, to make any timestamps applicable to their timezone.
  3. I need to create a function(or class) that enables me to collect the users timezone, and convert any timestamps to be applicable to the users timezone code.

Example:

$timestamp = $rows[blogentry_date]; //Just an example of a query result
$users_timeszone_code = TheFunctionI_NeedHelpCreating() // Hopefully collects users 
// timezone code, and converts it to a supported 
// timezone using date_default_timezone_set()??(just a guess)
CreateDate($users_timeszone_code, $timestamp);

Example Output:

12, Monday 2007. 5:00am // Just as an example

Does this make sense? I hope my examples haven't made things worst, but i find it easier explaining what im thinking in little code snippets than with words..lol. Any help will be greatly appreciated.

Cheers, and thanks.

+1  A: 

Using a time zone code isn't a good idea. Different time zones change daylight savings times on different dates. Ideally (IMO) you should use Olsen codes such as "Europe/London" if the relevant platforms you're using can cope with them. Those should allow you to predict when any particular instant occurs for the user's time zone.

I'm sorry this in't actually helping with the function you need to write, but it should help you to avoid going in the wrong direction.

(I speak from bitter experience - time zones are a pain in the neck.)

Jon Skeet
Hi there,Thanks for your answer. I agree with you completely(but with great frustration..lol). I guess my only option is to update the database with olsen codes in place of the timezone codes. This way, I will be able to write the function myself..so thanks for the tip..this has driven me nuts..lol
Lea
I'm glad it helped, even without any idea about PHP or MySql. I wasn't expecting it to be more than just a hint, but if it's proved useful that's great :) Now I've got to go back to my own time zone issues :(
Jon Skeet