Time::Local let me faint



  • 1. User define switch
    Dear all, Is there any simple way to add user defined switches in Perl. I want someting like that: perl --filein MyInputFileName --fileout MyOutputFileName ##in command line With --filein switch I want to define file, which will be read as the input and with the --fileout the output file. Thanks in advance for any suggestion, Andrej
  • 2. PERL BOOKS for EDA??
    hi iam karthy, which is the best e-book to learn perl, iam working in verilog, is there any PERL book specifically written for EDA ..( PERL for EDA ) kindly reply me have a nice day bye
  • 3. How to concatenate 'like' files in a dir?
    Hi All, I have a directory of .txt files and need to concatenate all files belonging to each user (oldest first, no set number per user). The username (M08x) is embedded in the filename, along with other info. I would like to delete the smaller individual logs/files once they have been concatenated. Any advice is greatly appreciated! Here is a sample of the filenames... -rw-r--r-- 1 christine christine 28046 Oct 11 21:40 KCD-M087326-NA-server.name-2005Oct11-20:42:14.txt KCD-M087326-NA-server.name-2005Oct16-23:55:26.txt KCD-M087326-NA-server.name-2005Oct17-22:44:00.txt KCD-M087326-NA-server.name-2005Oct19-21:35:06.txt KCD-M087350-NA-server.name-2005Oct03-19:20:56.txt KCD-M087350-NA-server.name-2005Oct05-21:13:19.txt KCD-M087350-NA-server.name-2005Sep27-19:26:09.txt ...... Thank you, Christine
  • 4. Radius CPAN Modules
    Hi, Is there any modules that supports Radius Disconnect type messages (RFC3576). Spend some extensive time going through what's available on CPAN, but I haven't found anything that supports Disconnect Messages.... Did I miss anything, or is radclient my only option?? :( Thanks, Chris

Time::Local let me faint

Postby practicalperl » Thu, 31 Aug 2006 01:48:26 GMT


Please see these two lines' output:

[$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,8,2006)'
Day '31' out of range 1..30 at -e line 1

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,7,2006)'

I translate the time of '2006-7-31 00:00:00' to unix timestamp,it's
But when I translate the time of '2006-8-31 00:00:00' to unix timestamp,it
said '31 out of range'.
I'm so faint that August doesn't have 31th day?Please tell me why this
happen and how to resolve it.
Thank you very much.

Re: Time::Local let me faint

Postby lawrence » Thu, 31 Aug 2006 01:54:19 GMT

Because SEPTEMBER only has thirty days.

0 - January;  1 - February; 2 - March; ... 


Re: Time::Local let me faint

Postby a.r.ferreira » Thu, 31 Aug 2006 01:55:14 GMT

from "perldoc Time::Local"

       It is worth drawing particular attention to the expected ranges for the
       values provided.  The value for the day of the month is the actual day
       (ie 1..31), while the month is the number of months since January
       (0..11).  This is consistent with the values returned from localtime()
       and gmtime().

That means

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,8,2006)'
Day '31' out of range 1..30 at -e line 1

         is trying to get "31/Sep/2006" which does not exist

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,7,2006)'

         is getting "31/Aug/2006" which is alright.

Adriano Ferreira.

Re: Time::Local let me faint

Postby practicalperl » Thu, 31 Aug 2006 01:58:34 GMT

Thank you,:-)
For the intuition I treated '8' as August in Time::Local's method...A
low-level mistake.

2006/8/30, Lawrence Statton XE1/N1GAK < XXXX@XXXXX.COM >:

Re: Time::Local let me faint

Postby dsl58893 » Thu, 31 Aug 2006 01:58:37 GMT

I believe it is because the months are 0-indexed (0-11), so 
timelocal(0,0,0,31,8,2006) is 2006-7-31 *not* 2006-8-31.

It also say so in the documentation.
perldoc Time::Local

Hope it helps.

Flemming Greve Skovengaard            The killer's breed or the Demon's seed,
a.k.a Greven, TuxPower                The glamour, the fortune, the pain,
< XXXX@XXXXX.COM >           Go to war again, {*filter*} is freedom's stain,
4011.74 BogoMIPS                      Don't you pray for my soul anymore.

Re: Time::Local let me faint

Postby krahnj » Thu, 31 Aug 2006 02:07:21 GMT


   localtime EXPR
           Converts a time as returned by the time function to a 9-element
           list with the time analyzed for the local time zone.  Typically
           used as follows:

               #  0    1    2     3     4    5     6     7     8
               ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =

           All list elements are numeric, and come straight out of the C
           truct tm  $sec, $min, and $hour are the seconds, minutes, and
           hours of the specified time.  $mday is the day of the month, and
           $mon is the month itself, in the range 0..11 with 0 indicating
           January and 11 indicating December.  $year is the number of years
           since 1900.  That is, $year is 123 in year 2023.  $wday is the day
           of the week, with 0 indicating Sunday and 3 indicating Wednesday.
           $yday is the day of the year, in the range 0..364 (or 0..365 in
           leap years.)  $isdst is true if the specified time occurs during
           daylight savings time, false otherwise.

So if you want to translate 31 August 2006 you have to subtract one from the
month and 1900 from the year:

$ perl -Mstrict -MTime::Local -le 'print timelocal(0,0,0,31,7,106)'

use Perl;

Re: Time::Local let me faint

Postby krahnj » Thu, 31 Aug 2006 12:48:34 GMT

The reason that '2006' works is because Time::Local makes a guess that '2006'
actually means '106'.

use Perl;

Re: Time::Local let me faint

Postby Paul Lalli » Thu, 31 Aug 2006 21:30:46 GMT

There is no "guesswork" involved.  Time::Local has a very well
documented specific set of rules:

     o   Years greater than 999 are interpreted as being the
         actual year, rather than the offset from 1900.  Thus,
         1963 would indicate the year Martin Luther King won the
         Nobel prize, not the year 2863.

     o   Years in the range 100..999 are interpreted as offset
         from 1900, so that 112 indicates 2012.  This rule also
         applies to years less than zero (but see note below
         regarding date range).

     o   Years in the range 0..99 are interpreted as shorthand
         for years in the rolling "current century," defined as
         50 years on either side of the current year.  Thus,
         today, in 1999, 0 would refer to 2000, and 45 to 2045,
         but 55 would refer to 1955.  Twenty years from now, 55
         would instead refer to 2055.  This is messy, but matches
         the way people currently think about two digit dates.
         Whenever possible, use an absolute four digit year

Paul Lalli

Similar Threads:

1.Invalid local time for date in time zone: America/New_York

Hi all, I am facing a weird error.

I have a program that has the following line as part of it's co

my $dt =

The funny part is that when i run this program on my computer, which is
in the US, EST, it works fine. When a friend of mine runs it in his
computer in the EU, it gives him

Invalid local time for date in time zone: America/New_York

According to documentation, this can happen only if a specified local
time never existed due to DST changes - which doesn't seem to be the
case here.

any help ?

2.Curious about Time::Local

What is $dow in the line from Alpaca, p77:

my ($sec, $min, $hour, $day, $month, $year, $dow) = localtime;

Curious, I wrote

#!/usr/bin/perl -w

use strict;
use Time::Local;
use File::Find;

my ($sec, $min, $hour, $day, $month, $year, $dow) = localtime;
print "Day $day Month ", $month + 1, " Year ", $year + 1900, "\n";
print "Dow $dow\n";
print localtime, "\n\n";
my @numbers = grep (//,localtime);
for (@numbers) {
	print $_, "\n";
and found there are actually three numbers following the number for the
year.   The man page for Time::Local makes no mention of these.  

Tom George

3.utc to local time


5.Local and global at the same time?

Hi all,

If I declare a variable x1 outside of the sub that makes it global, right?
Now the question is can I have the same variable x1 as a local variable of a
sub, i.e. will the following work?

$x1 = "cat";

sub sample()
   my $x1="dog";

Just trying to work out some guidelines on using variables, i.e. using
local, my or global and some naming converntion stuff ...

Is there some good links on such guidelines?

6. Time::Local - month problem

7. Time::Local V 1.10 and users thereof, eg Archive::Zip V 1.14

8. Converting between Local and Unix time problems

Return to PERL


Who is online

Users browsing this forum: No registered users and 12 guest