1use Test; 2BEGIN { plan tests => 12 } 3# Test the calculation of (modified) Julian date 4use Time::Piece; 5 6# First a lookup table of epoch and MJD 7# Use 3 sig fig in MJD (hence the use of strings) 8# This will not work on systems that use a different reference 9# epoch to unix time. To be more general we should use strptime 10# to parse the reference date. 11my %mjd = ( 12 951827696 => '51603.524', # 2000-02-29T12:34:56UT 13 1000011 => '40598.574', # 1970-01-12T13:46:51UT 14 1021605703 => '52411.140', # 2002-05-17T03:21:43UT 15 1121605703 => '53568.547', # 2005-07-17T13:08:23UT 16 1011590000 => '52295.218', # 2002-01-21T05:13:20UT 17 1011605703 => '52295.399', # 2002-01-21T09:35:03 18 ); 19 20# Now loop over each MJD 21for my $time (keys %mjd) { 22 23 # First check using GMT 24 my $tp = gmtime( $time ); 25 ok(sprintf("%.3f",$tp->mjd),$mjd{$time}); 26 27 # Now localtime should give the same answer for MJD 28 # since MJD is always referred to as UT 29 $tp = localtime( $time ); 30 ok(sprintf("%.3f",$tp->mjd),$mjd{$time}); 31 32} 33 34