Reply
 
Thread Tools
Old 01-05-2004, 02:21 PM   #1   [permalink]
Usagi^.^
Ex Moderator V.I.P.
 
Usagi^.^'s Avatar
 
Join Date: 4 Feb 2001
Location: Québec
Posts: 2,226
PHP: Darn daylight savings..!

Ok, I've been searching around for a script for a forum: to adjust the time to the user time. You know, just like it does here; in the options they ask your time zone (-5 Eastern time for me).

That's all easy to save the post time under the GMT time, and then showing that time on the page with that time zone option added. In GMT right now it 6pm, and it's 2pm for me.

That's the problem! I'm in the -5 time zone, but right now I'm at a 4hours differences, becaaaaause: THE DARN DAYLIGHT SAVINGS!

Anyone has a clue how I could detect whether it's the advanced time or not? I saw a script that couldn't apply for me, but it would calculate which day of the year we were and would calculate when the daylight saving applied, and it'd be different for NTS (or whatever abbreviation) and UTC.

Anyway... Help?
__________________
(\__/)
(='.'=)
(")_(")
Usagi^.^ is offline   Reply With Quote
Old 02-05-2004, 02:35 AM   #2   [permalink]
GuGuEaTeR
Forum Master
 
GuGuEaTeR's Avatar
 
Join Date: 29 Dec 2001
Location: Stratosphere
Posts: 2,271
Send a message via AIM to GuGuEaTeR Send a message via MSN to GuGuEaTeR
Make an option that also allows them to check if they have day-light saving or not. Let the clients do the work, not the server.

Then use that to calculate, along with server's time zone, to get the proper time for the client.

Can't give you the exact code because of laziness and necessity for much thinking and calculation, but it won't be too hard to make an algorithm up. Well, can't be as hard as coding a whole forum up from nothing.
__________________
mplayer > * media players, period.
GuGuEaTeR is offline   Reply With Quote
Old 03-05-2004, 09:49 AM   #3   [permalink]
Usagi^.^
Ex Moderator V.I.P.
 
Usagi^.^'s Avatar
 
Join Date: 4 Feb 2001
Location: Québec
Posts: 2,226
True. ^^;

Hmm, you're right, I could just ask the user, 'cause some places like where Eva2k lives there's no daylight savings huh?

But the person still has to go into the panel at least twice a year to switch on or off that option... ><; It's the same as what I'm doing, just simpler to understand for the user. *sigh* I guess I'll do that, it's only twice a year right..? ;_;
__________________
(\__/)
(='.'=)
(")_(")
Usagi^.^ is offline   Reply With Quote
Old 03-05-2004, 10:22 AM   #4   [permalink]
GuGuEaTeR
Forum Master
 
GuGuEaTeR's Avatar
 
Join Date: 29 Dec 2001
Location: Stratosphere
Posts: 2,271
Send a message via AIM to GuGuEaTeR Send a message via MSN to GuGuEaTeR
It's all a matter of feasability. How many times do you think people look at the post time anyway? Don't they usually care only that whoever posted first?

It would still require quite some number of programming. I mean, you have to figure out the exact location of the client's computer, if they only have one that is. Then you have to take that, figure out its time-zone (from a DB most likely), and blah blah blah. Just way too much work in my opinion.

Feasability. The sole reason why small stores don't have massive computer facilities; they don't need it. And you probably don't need to have the world's most accurate server-client time relationship anyway

[edit] On a second thought, and retyping since AB was too busy, it won't be so hard implementing it. All the users can set their timezones themselves, and the program can just have lots of IF statements in it.
__________________
mplayer > * media players, period.

Last edited by GuGuEaTeR; 03-05-2004 at 10:38 AM.
GuGuEaTeR is offline   Reply With Quote
Old 03-05-2004, 12:28 PM   #5   [permalink]
Usagi^.^
Ex Moderator V.I.P.
 
Usagi^.^'s Avatar
 
Join Date: 4 Feb 2001
Location: Québec
Posts: 2,226
Yeah, that's what I did, a drop-down thing asking for the timezone, which I stole from vB.

And it is the whole bunch of IFs that scare me. ^^; If I don't put a lil' checkbox "Do you have daylight savings right now?" like you suggested, I would need a bunch of IFs to:
- figure out whether the person is in NTS or UTC ('cause I saw somewhere they have different dates for daylight savings. -_-; )
- then IFs to know which day of the year we are and see if it's daylight savings, and then I could remove 1 or not... -_-; I'm not even sure of the dates, I can't find a single website explaining what daylight savings are and infos... ><;

Blah, I'll put the checkbox. ^^; Or I could always try to steal vB's script... *evilgrin* AB doesn't use the daylight savings 'cause of Eva2k, but I think the application I want is implemented in this forum.

And I'd really like to have that application, but the checkbox could be fine. But it's gonna be for a forum which ppl _pay for_ to be members, so you can understand I want to make it the best I can. *.*
__________________
(\__/)
(='.'=)
(")_(")
Usagi^.^ is offline   Reply With Quote
Old 07-05-2004, 10:09 AM   #6   [permalink]
GuGuEaTeR
Forum Master
 
GuGuEaTeR's Avatar
 
Join Date: 29 Dec 2001
Location: Stratosphere
Posts: 2,271
Send a message via AIM to GuGuEaTeR Send a message via MSN to GuGuEaTeR
Even if people pay the feasability of this feature is so minimal that it's just not worth it. It'd be easier to just make the server go 24 hours all year, on spot of Greenwich Median time whatever, and people have to follow that server's time, regardless of where they live.

Lots of IFs aren't much of a problem in coding, it's just laying them out which takes some time. If you know how it feels to write a code that's around 10,000 lines long, then you'd know that lots of IF statements are common.

Good luck anyway :thumb:
__________________
mplayer > * media players, period.
GuGuEaTeR is offline   Reply With Quote
Old 10-05-2004, 11:53 PM   #7   [permalink]
Keiichi
Executive Member
 
Keiichi's Avatar
 
Join Date: 19 Jul 2000
Location: At home...
Posts: 402
This should be simple. There's no need for big IF statements. Here's one I just made:
PHP Code:
function makeDate($time$zone$daylights$format) {
  
$greenwich $time - (date("O") * 3600 100); // $time in greenwich time
  
$userTime $greenwich + ($zone 3600); // user's time with timezone
  
if ($daylights == && date("I"$userTime) == 1// check daylights
    
$userTime -= 3600// subtract an hour if daylight savings
  
return date($format$userTime);
}

$time makeDate(time(), -100"M, d Y g:ia");
echo 
$time
I hope it's right. I don't have daylight savings here to test that. Basically the function asks for the time (current time, a posted time, etc), the person's timezone difference (from greenwich), whether the user selects to have daylight savings (1) or not (0), and finally the format of the date/time to show.
The date() function should be useful: http://www.php.net/manual/en/function.date.php
__________________
K1
"Belldandy's drunk? But why now?!...No way...because of COLA?" :goof:

Last edited by Keiichi; 10-05-2004 at 11:55 PM.
Keiichi is offline   Reply With Quote
Old 11-05-2004, 09:50 AM   #8   [permalink]
Usagi^.^
Ex Moderator V.I.P.
 
Usagi^.^'s Avatar
 
Join Date: 4 Feb 2001
Location: Québec
Posts: 2,226
Darn it all, how come I missed the "I" in the date() function? Well, I didn't know you could give a second statement to date() anyway, didn't check enough I guess.

PHP Code:
if ($daylights == && date("I"$userTime) == 1// check daylights 
But how does it work? It checks the date and time for a daylight saving, sure, but does it take in account the UTC and US difference? I found this link that says there's a difference: http://webexhibits.org/daylightsaving/b.html

It's 'cause half of my visitors will be from France, you see, so I wanna make sure...

And for getting the greenwich time, you can use gmdate(); too right? 'Cause that's what I'm using everywhere, please don't tell me I have to change it. >< For what I read, it gives the GMT date _and_ time, so should be just as good right?

And, and... Hehehe, no more questions. ; ) I didn't think it was that easy, should've found the "I" thing earlier! Thanks Keichii!

Hey, BTW, long time no see. o.o; Mikomi's board died? ;_;
__________________
(\__/)
(='.'=)
(")_(")
Usagi^.^ is offline   Reply With Quote
Old 11-05-2004, 09:56 PM   #9   [permalink]
Keiichi
Executive Member
 
Keiichi's Avatar
 
Join Date: 19 Jul 2000
Location: At home...
Posts: 402
I guess I'll fix up that function when I havea time. I plan to use it too some time in the future. I guess I haven't thought about that UTC stuff. I've only learned about this just recently, but totally had forgotten about it when making this. Thanks for reminding me, and the gmdate(). I've never used it before. *lol*

Yeah, Mikomi closed her board like two months ago... :\
__________________
K1
"Belldandy's drunk? But why now?!...No way...because of COLA?" :goof:
Keiichi is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need someone with skills on PHP and other web things. Kensuke::Ninja of Light Promotion: exchanging links / staff recruiting 2 13-04-2004 10:40 PM
Help with some PHP <---------- EVA 2000 that means you! :p StramiT HTML, PHP, MySQL, Graphics, Coding 8 05-07-2001 03:15 PM
Daylight Savings time isamudyson Contact Admin Archive 3 03-04-2001 03:20 PM


New To Site? Need Help?

All times are GMT -4. The time now is 01:54 PM.


Powered by vBulletin® Version 3.8.10
Copyright ©2000 - 2018, vBulletin Solutions, Inc.