Tuesday, June 18, 2002, 9:30:40 PM, Todd Wade wrote: > # this sub was written by Larry Rosler > # modified by me to get rid of the 'argument isnt numeric' warnings by -w > # i found it on deja
it's probably better to use timelocal() from the core Time::Local module, if only for the reason that it's got a whole lot more documentation than this subroutine. > # it takes 6 arguments > # and returns the time in epoch seconds > # or undef if the date is not valid > sub UTC_to_Epoch { > my($year, $mon, $day, $hour, $min, $sec) = @_; > (($year =~ m/^\d{4}$/) && ($mon =~ m/^\d{1,2}$/) && ($day =~ > m/^\d{1,2}$/)) or return; > ($year <= 2037) or return; > my @m_day = (0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); > $m_day[2] = 29 unless $year % 4; # OK from 1901 through 2099. > 1970 <= $year && $year <= 2099 > && 1 <= $mon && $mon <= 12 > && 1 <= $day && $day <= $m_day[$mon] > && 0 <= ($hour ||= 0) && $hour <= 23 > && 0 <= ($min ||= 0) && $min <= 59 > && 0 <= ($sec ||= 0) && $sec <= 59 > or return; > # Adapted from Astronomical Computing, Sky & Telescope, May, 1984. > 24 * 60 * 60 * (367 * $year - 678972 - 40587 + int(275 * $mon / 9) + $day > - int((int(int($year + ($mon < 9 ? -1 : 1) * int(abs($mon - 9) / 7)) / 100) > + 1) * 3 / 4) - int(7 * (int(($mon + 9) / 12) + $year) / 4)) + 60 * 60 * > $hour + 60 * $min + $sec > } > Todd W -- Best Regards, Daniel [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]