in reply to Re: Convert dates with Time::Local
in thread Convert dates with Time::Local

Thnx, Do you know how to use timegm when you have a julian day and not a month and day ?

Luca

Replies are listed 'Best First'.
Re^3: Convert dates with Time::Local
by duff (Parson) on Feb 13, 2006 at 16:44 UTC

    Like so:

    use Time::Local qw/timegm_nocheck/; my $date_string = "2005301"; # The 301st day of 2005 my ($year,$julian_day) = $date_string =~ /^(\d\d\d\d)(\d\d\d)$/; my $gmt = timegm_nocheck 0,0,0,$julian_day,0,$year; # ... do something with the gmt value

    Way back in the days of perl4, timelocal.pl (from whence Time::Local is derived) did no validation of the numbers since it is a straight numeric calculation that does not depend on how many days there are in a given month or how many hours in a day, etc. timegm_nocheck and timelocal_nocheck implement the modern-day equivalents of this idea.

    But, you'd know this if you'd read the documentation

Re^3: Convert dates with Time::Local
by davorg (Chancellor) on Feb 13, 2006 at 15:47 UTC

    I don't think I'd use timegm with a Julian date.

    Jan 1st 1970 has a Julian date of 2440587. Surely you can just subtract that from the Julian date you have and then multiply by the number of seconds in a day to get the number of seconds since the epoch. This, of course, assumes that your computer uses 1970-01-01 00:00:00 as its epoch.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Julian dates and julian days are different things. The latter is just the number of days since the start of the year. Jan 1 is julian day 1, Feb 1 is julian day 32, Feb 2, day 33, and so on.

        Julian days and Julian dates are subtley different things as the Wikipedia article indicates. But Julian day doesn't mean what you think it means. Granted, it's quite a common error. But it's still an error :)

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg