RE: Backing up two days from localtime

2002-04-26 Thread Timothy Johnson

 
Actually this is a really common question.  The thing you need to remember
is that when you use localtime(), what you are really saying is
localtime(time).  Local time takes the number of seconds since the year 1970
and translates it into the array you are using UNLESS YOU SPECIFY ANOTHER
DATE IN THE SAME FORMAT.  Therefore you can do this:

localtime(time - (60 * 60 * 24)); #60 sec, 60 min, 24 hrs.

which translates to 

localtime(time - 86400); # the number of seconds in one day, 
 # which is yesterday.

So taking this info, it is easy to extrapolate that

localtime(time - 86400 * 2);

is the date two days ago. 

Note:  the * operator is calculated before the - operator, otherwise you
would have to use parenthesis to force the operation first.

-Original Message-
From: Tara Calishain
To: [EMAIL PROTECTED]
Sent: 4/25/02 10:57 PM
Subject: Backing up two days from localtime

Howdy,

I need to back up two days from localtime and I can't figure out how to
do
it. Currently I'm doing this just so I can work out the rest of the
program:

($day, $month, $year) = (localtime) [3,4,5]; #getting your local time 
information
$realday = $day-2;
if ($realday1) {$realday = 30} else {$realday = $day-2};

. but that's a very cheesy and occasionally wrong workaround.

This is probably a stupid question hopefully not the stupidest question 
you've ever
seen. I hope.

Thanks,

Tara


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-26 Thread Jonathan E. Paton

 I need to back up two days from localtime and I can't
 figure out how to do it. Currently I'm doing this just
 so I can work out the rest of the program:

[Ignore me if you aren't on a Unix like platform]

Hi,

You should seriously consider installing the 'at' job
manager for run-once tasks, or 'cron' to schedule tasks
regularly.  Try to avoid spreading time-scheduling
around, especially into memory hungry Perl processes
that just sit around doing nothing.

man at
man cron

However, you may have to contact your administrator
for these.  Easy though if you own the machine.

Jonathan Paton

__
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-26 Thread Michael Lamertz

On Fri, Apr 26, 2002 at 09:32:04AM +0100, Jonathan E. Paton wrote:
  I need to back up two days from localtime and I can't
  figure out how to do it. Currently I'm doing this just
  so I can work out the rest of the program:
 
 [Ignore me if you aren't on a Unix like platform]
 
 Hi,
 
 You should seriously consider installing the 'at' job
 manager for run-once tasks, or 'cron' to schedule tasks
 regularly.  Try to avoid spreading time-scheduling
 around, especially into memory hungry Perl processes
 that just sit around doing nothing.
 
 man at
 man cron

I think you're missing the point here.  It's quite a common task to work
on logfiles that are a day or two old and have a timestamp in their
filename.  Sometimes these files are just required to be kept where they
are for some days, and then one has exactly the problem the original
post described.

He'll still use cron to schedule his script, but the script will need to
'calculate' the filename of the n-days old logfile.

-- 
   If we fail, we will lose the war.

Michael Lamertz|  +49 221 445420 / +49 171 6900 310
Nordstr. 49|   [EMAIL PROTECTED]
50733 Cologne  | http://www.lamertz.net
Germany|   http://www.perl-ronin.de 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-26 Thread Tara Calishain

At 02:05 AM 4/26/2002, Jeff 'japhy' Pinyan wrote:
 I need to back up two days from localtime and I can't figure out how to do
 it. Currently I'm doing this just so I can work out the rest of the program:
 
 ($day, $month, $year) = (localtime) [3,4,5]; #getting your local time

The generic (read: potentially unsafe) way is to fix the problem right
there:

   ($day, $month, $year) = (localtime(time - 86400*2))[3,4,5];

The only place to worry about this is during the switch to/from Daylight
Savings Time, at 2:00 am, twice a year.

Thanks Jeff and Timothy. (And thanks to Jonathan too, but I'm on Windows.)

Actually, are there any books/docs that talk specifically about dealing 
with time?
I'm anticipating coming across this same problem with user input dates, and
I don't expect the seconds trick will work for that one.

For example, say a user specified $day-$month-$year and ten days, and I
wanted to generate a date string for every day going back ten days.

I begin to see the appeal of Julian days. At least with those all you have
to do is subtract one.

Apparently I've learned some kind of critical mass of perl because I'm writing
scripts all over the place. Well, the Google API also had something to do 
with it,
I suspect.

Thank you again for your help!

Tara
  


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-26 Thread Felix Geerinckx

on Fri, 26 Apr 2002 12:32:21 GMT, [EMAIL PROTECTED] (Tara
Calishain) wrote: 

 Actually, are there any books/docs that talk specifically about
 dealing with time?
 I'm anticipating coming across this same problem with user input
 dates, and I don't expect the seconds trick will work for that
 one. 
 
 For example, say a user specified $day-$month-$year and ten days,
 and I wanted to generate a date string for every day going back
 ten days. 

You might want to look into the Date::Calc module at

http://search.cpan.org/search?dist=Date-Calc

It will cover most calculations with dates.

With ActivePerl on Windows, it's easily installed with

ppm install Date::Calc

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-26 Thread Michael Lamertz

On Fri, Apr 26, 2002 at 08:32:21AM -0400, Tara Calishain wrote:

 I'm anticipating coming across this same problem with user input dates, and
 I don't expect the seconds trick will work for that one.
 
 For example, say a user specified $day-$month-$year and ten days, and I
 wanted to generate a date string for every day going back ten days.

Although Randal L. Schwartz posted a hillarious comment on Date::Manip

(http://archive.develooper.com/beginners%40perl.org/msg22416.html)

you should take a look at that module.  I have used it quite a lot to
let people pass more or less generic time/date specifications to my
scripts.  It does for example things like that:

-- snip --
nijushiho:~# perl -MDate::Manip -le 'print UnixDate(44 days ago, %Y%m%d)'
20020313
nijushiho:~# 
-- snip --

It comes at a price though, so I wouldn't use it to process some 20 million
lines of webserver logs in a nightly run :-)

-- 
   If we fail, we will lose the war.

Michael Lamertz|  +49 221 445420 / +49 171 6900 310
Nordstr. 49|   [EMAIL PROTECTED]
50733 Cologne  | http://www.lamertz.net
Germany|   http://www.perl-ronin.de 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Backing up two days from localtime

2002-04-26 Thread Timothy Johnson

 
You can convert the date/time to seconds format using the Time::Local
module.  It attempts to do a reverse localtime().

-Original Message-
From: Felix Geerinckx
To: [EMAIL PROTECTED]
Sent: 4/26/02 5:40 AM
Subject: Re: Backing up two days from localtime

on Fri, 26 Apr 2002 12:32:21 GMT, [EMAIL PROTECTED] (Tara
Calishain) wrote: 

 Actually, are there any books/docs that talk specifically about
 dealing with time?
 I'm anticipating coming across this same problem with user input
 dates, and I don't expect the seconds trick will work for that
 one. 
 
 For example, say a user specified $day-$month-$year and ten days,
 and I wanted to generate a date string for every day going back
 ten days. 

You might want to look into the Date::Calc module at

http://search.cpan.org/search?dist=Date-Calc

It will cover most calculations with dates.

With ActivePerl on Windows, it's easily installed with

ppm install Date::Calc

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Backing up two days from localtime

2002-04-25 Thread Tara Calishain

Howdy,

I need to back up two days from localtime and I can't figure out how to do
it. Currently I'm doing this just so I can work out the rest of the program:

($day, $month, $year) = (localtime) [3,4,5]; #getting your local time 
information
$realday = $day-2;
if ($realday1) {$realday = 30} else {$realday = $day-2};

 but that's a very cheesy and occasionally wrong workaround.

This is probably a stupid question hopefully not the stupidest question 
you've ever
seen. I hope.

Thanks,

Tara


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: Backing up two days from localtime

2002-04-25 Thread Jeff 'japhy' Pinyan

On Apr 26, Tara Calishain said:

I need to back up two days from localtime and I can't figure out how to do
it. Currently I'm doing this just so I can work out the rest of the program:

($day, $month, $year) = (localtime) [3,4,5]; #getting your local time 

The generic (read: potentially unsafe) way is to fix the problem right
there:

  ($day, $month, $year) = (localtime(time - 86400*2))[3,4,5];

The only place to worry about this is during the switch to/from Daylight
Savings Time, at 2:00 am, twice a year.

-- 
Jeff japhy Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for Regular Expressions in Perl published by Manning, in 2002 **
stu what does y/// stand for?  tenderpuss why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]