Page Index Toggle Pages: [1] 2  Send TopicPrint
Very Hot Topic (More than 25 Replies) $get_date question (Read 4926 times)
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
$get_date question
Jan 25th, 2004 at 8:08pm
Print Post  
How can I get something to run at an exact time? That is with time zones? I want this thing I am making to run once, at say 9pm pacific time. I am worried about members in other time zones getting it to run earlier/later.

THis is what I have now:
Code
Select All
if ($mon_num == 1 && $mday == 31 && $hour == 9 || $mon_num == 1 && $mday > 31 || $mon_num > 1) {DO SOMETHING} 



TIA
  
Back to top
WWW  
IP Logged
 
Ikari-Kun
God Member
*****
Offline



Posts: 501
Joined: Apr 25th, 2002
Gender: Male
Re: $get_date question
Reply #1 - Jan 26th, 2004 at 7:45am
Print Post  
A server side language always uses the server time and not the user time. So that it'll only run when it's 9pm on your server.
  

perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
Back to top
ICQ  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #2 - Jan 26th, 2004 at 7:48am
Print Post  
Really? Someone has thought of this?  Grin
So I don't have to worry? My code will run off my time with get_date stuff? That's cool! THanks..



  
Back to top
WWW  
IP Logged
 
Ronnie
Senior Member
****
Offline


And on that bombshell

Posts: 336
Location: Manchester
Joined: Dec 15th, 2001
Gender: Male
Re: $get_date question
Reply #3 - Jan 26th, 2004 at 4:12pm
Print Post  
getdate returns the localtime, all the time offsetting is done when the date is formatted through timeformat. So you should be okay just getting the date and avoid using timeformat.
  
Back to top
WWWICQ  
IP Logged
 
ironwing
God Member
*****
Offline


I love YaBB 1 Gold!

Posts: 2330
Location: Sonoran Desert
Joined: Nov 20th, 2001
Re: $get_date question
Reply #4 - Jan 26th, 2004 at 5:00pm
Print Post  
You're still not going to get it to run at the exact time unless there is a user around at the exact time to trigger the script.  Otherwise the script will run later, when a user finally comes along to trigger it.

Dan
  

Please include your forum address in all requests for assistance.  It greatly speeds things along.
Back to top
WWW  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #5 - Jan 26th, 2004 at 5:15pm
Print Post  
I actually using it as prevention. I don't want them to see what it does until that time. So per Ronnie, inherit in get_date is some formatting for time zones? I'm still confused on this! Should I just use straight up perl for time instead?
  
Back to top
WWW  
IP Logged
 
Ronnie
Senior Member
****
Offline


And on that bombshell

Posts: 336
Location: Manchester
Joined: Dec 15th, 2001
Gender: Male
Re: $get_date question
Reply #6 - Jan 27th, 2004 at 1:58am
Print Post  
You use sub get_date to return a time/date string in the format "12/29/01 at 17:52:34". This is the localtime at the server.

This is usually then passed to sub timeformat. This modifies the string to apply the time offset for that user and apply the time format.

Based on what you said I think you've no need for the time offsets/formats so just use get_date to get the current date and time at your server, in the format I mentioned above. You can then split it up to get the day/month etc., there is code in sub timeformat you can copy to do this quickly.
  
Back to top
WWWICQ  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #7 - Jan 27th, 2004 at 3:44am
Print Post  
Thanks for you help Ronnie... that's great to know.
The one kink in my chain is the timer I am running on this related page, it's in JavaScript so it's user-side. Maybe I can convert that to perl. I didn't see many cool perl countdown scripts out there that work in real time though. hmmm...
  
Back to top
WWW  
IP Logged
 
Ikari-Kun
God Member
*****
Offline



Posts: 501
Joined: Apr 25th, 2002
Gender: Male
Re: $get_date question
Reply #8 - Jan 27th, 2004 at 5:40am
Print Post  
You could use perl to get the actual time and use javascript for the countdown then.
  

perl -e 'print $i=pack(c5,(41*2),sqrt(7056),(unpack(c,H)-2),oct(115),10);'
Back to top
ICQ  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #9 - Jan 27th, 2004 at 6:48am
Print Post  
You know I thought of that, but I haven't followed through on figuring it out. Perl doesn't get much easier than time either.  Roll Eyes I would think I can leave most of it and just swap out some variables like you said. Good to talk about this anyway and get a plan. That sounds like it. Check this out..

Here's the guts of the JavaScript that need changing:
Code
Select All
function setup(day,box)
{
today = (new Date()).getTime();
the_day = (new Date(day)).getTime();
time = (the_day - today);
document.forms[box].time2.value=time;
} 

  
Back to top
WWW  
IP Logged
 
Ronnie
Senior Member
****
Offline


And on that bombshell

Posts: 336
Location: Manchester
Joined: Dec 15th, 2001
Gender: Male
Re: $get_date question
Reply #10 - Jan 27th, 2004 at 3:07pm
Print Post  
I don't know the exactly how Javascript works but I would have thought instead of getting the user's local time with

Code
Select All
today = (new Date()).getTime(); 



you could maybe do something like

Code
Select All
$thetime = localtime; <-- in Perl

today = (new Date($thetime)); <-- then in Javascript 



ie. you're getting the server localtime in Perl, and then when you print the Javascript you pass that time to Date instead of using the client-side getTime.
  
Back to top
WWWICQ  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #11 - Jan 27th, 2004 at 4:46pm
Print Post  
I think you guys are right, that's the start of it.. thanks!

I am worried, not sure if I need to be, about some symantics that may need to converted one way or the other as the following line of code is used in JavaScript to determine the end time:

Code
Select All
<input type="hidden" name="time2" size="0" value="Jan 31, 2004 11:05:00"> 

  
Back to top
WWW  
IP Logged
 
Ronnie
Senior Member
****
Offline


And on that bombshell

Posts: 336
Location: Manchester
Joined: Dec 15th, 2001
Gender: Male
Re: $get_date question
Reply #12 - Jan 28th, 2004 at 11:20am
Print Post  
Converting the YaBB date into a format javascript accepts would be easy, you'd just need to split up "12/29/01 at 17:52:34" to get the individual parts and then create a new string in the format you want i.e. "Jan 31, 2004 11:05:00". As you can see the time part doesn't need any alterations anyway.
  
Back to top
WWWICQ  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #13 - Jan 28th, 2004 at 5:02pm
Print Post  
Wow. Thanks guys. I have to figure this out tonight, so I'll let you know how it goes.
  
Back to top
WWW  
IP Logged
 
caliman
God Member
*****
Offline


Swanky

Posts: 1220
Location: Pt. Richmond
Joined: Mar 20th, 2002
Gender: Male
Re: $get_date question
Reply #14 - Jan 29th, 2004 at 7:32am
Print Post  
i think i got a sweet perl time thing going on, but i can't seem to mix it with the javascript... i need fresh eyes on this...

sweet perl time thing:
Code
Select All
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);

$year += 1900;
$hour=$hour+$offset;
if ($hour >= 24) {
$hour = $hour - 24;
$mday = $mday + 1;
}
if ($hour >= 12) {
    if ($hour > 12){
          $hour = $hour - 12;
       }
    $ampm = "pm";
}
else { $ampm = "am"; }

if ($sec < 10) { $sec = "0$sec"; }
if ($min < 10) { $min = "0$min"; }
if ($mon < 10) { $mon = "0$mon"; }
if ($mday < 10) { $mday = "0$mday"; }
$month = ($mon + 1);
@months = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
my $date = "$months[$mon] $mday $year";
chop($date) if ($date =~ /\n$/);

my $datetime = "$date $hour:$min:$sec"; 




javascript :
Code
Select All
function setup(day,box)
{
today = (new Date()).getTime();
the_day = (new Date(day)).getTime();
time = (the_day - today);
document.forms[box].time2.value=time;
}


 




I can't seem to force-feed perl (first code block) into the Javascript without busting the timer. UGH.

I tried : "today = $datetime" and some variations..

Hitting a wall!




« Last Edit: Jan 30th, 2004 at 7:35am by caliman »  
Back to top
WWW  
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint