#!/usr/local/bin/perl -w use strict; # About: # ----- # Author: Parv, parv underscore at yahoo dot com # Modified: dec 20 2000 # # Currently this program does the below stated conversion, but can be # (easily) extended to do other conversions. # # Unix date/time in seconds is converted to year, month, day, hour, # minute, second. # # Credits: # ------- # This program's date conversion algorithm is based on an # article about inter-date conversions (shown via JavaScript); # author of the article is John Walker, founder of AutoCad. # Article copies are available at many places, two of which 're... # # http://www.fourmilab.ch/documents/calendar/ # http://www.michaelmccafferty.com/mmmdate.htm # # ...The article recommends/referrers to... # # 1. Astronomical algorithms, # Mjean Meeus; 1991; ISBN: 0-943396-35-2 # # 2. Explanatory supplement to the astronomical almanac, # p. Kenneth Seidelmann (ed.); 1992; ISBN: 0-935702-68-7 # # adjust unix epoch in julian day by 0.5 so that day starts on # midnight instead of noon # use constant Unix_Epoc_Julian => 2440587.5 +0.5; # other constants use constant Avg_JulianCal_Yr => 365.25; use constant Avg_GregorianCal_Yr => 365.2425; convert_show_datetime(@ARGV); sub convert_show_datetime { for (@ARGV) { # check if an argument is a digit(s) # unless (m#\d+#) { print "\n# $_ is not a number, skipping...\n"; next; } # convert given seconds into (fractional) julian days # my $t = unixSec2julianDay($_); my $t_2 = int($t); my $diff = $t - $t_2; # get date & time... my ($year, $month, $day) = julianDay2date($t_2, $diff); my ($hour, $min, $sec) = julianDay2time($diff); print < 2) ? ($y -4716) : ($y -4715); # zero-pad year, month, day before returning # return ( sprintf("%04s", $y), sprintf("%02s", $m), sprintf("%02s", $d) ); } sub not_digit { my ($d) = @_; return 1 if !((defined $d) || ($d =~ m/\d+/)); return 0; }