#!/usr/local/bin/perl
# [ Perl_timegm_Test2.cgi ] Test of timegm/timelocal to appoint "4-digit years".
# You appoint the argument "year" in the application side by "4-digit years" (1960, 1990, 2010, 2040 etc.)
# When you obtain an epoch by timegm/timelocal, you appoint the value that converted "4-digit years"
# in the following rule.
# (1) 4-digit years >= 1900 : You just appoint "4-digit years".
# (2) 4-digit years < 1900 : You appoint ["4-digit years" - 1900]. (A negative offset value from 1900.)
use Time::Local;
sub debugtimegm {
my ($year,$month,$day,$hour,$min,$sec) = @_;
my $adjust_year = $year;
$adjust_year -= 1900 if ($adjust_year < 1900);
my $epoch = timegm( $sec,$min,$hour,$day,$month-1,$adjust_year);
print "$year/$month/$day $hour:$min:$sec -> epoch( $epoch ) -> DateTime( " . gmtime($epoch) . " )
\n";
if (($year != ((gmtime($epoch))[5] +1900))) {
print " [ " . $epoch . " - 3155760000 ] = epoch( " . ($epoch-3155760000) . " ) -> DateTime( " . gmtime($epoch-3155760000) . " )
\n";
}
}
sub debugtimelocal {
my ($year,$month,$day,$hour,$min,$sec) = @_;
my $adjust_year = $year;
$adjust_year -= 1900 if ($adjust_year < 1900);
my $epoch = timelocal( $sec,$min,$hour,$day,$month-1,$adjust_year);
print "$year/$month/$day $hour:$min:$sec -> epoch( $epoch ) -> DateTime( " . localtime($epoch) . " )
\n";
}
print "Content-type: text/html\n\n";
print "
\n";
print " Test of timegm/timelocal to appoint 4-digit years.
\n";
print "[ diff-value:3155760000 / 86400 = (100 * 365.25) equal 100 years. ]
\n";
print "Perl ver " . $] . " , Now = [ " . gmtime(time()) . " (GMT) ]
\n";
&debugtimegm(2039,1,1,0,0,0);
&debugtimegm(2038,1,19,3,14,8);
print "
\n";
&debugtimegm(2038,1,19,3,14,7);
&debugtimegm(2038,1,19,3,14,6);
&debugtimegm(2038,1,19,0,0,0);
print "
\n";
&debugtimegm(1970,1,1,0,0,0);
&debugtimegm(1969,1,1,0,0,0);
&debugtimegm(1968,1,1,0,0,0);
&debugtimegm(1967,1,1,0,0,0);
&debugtimegm(1966,1,1,0,0,0);
&debugtimegm(1965,1,1,0,0,0);
&debugtimegm(1964,1,1,0,0,0);
&debugtimegm(1963,1,1,0,0,0);
&debugtimegm(1962,1,1,0,0,0);
print "
\n";
&debugtimegm(1961,12,31,23,59,59);
&debugtimegm(1961,1,1,0,0,0);
&debugtimegm(1960,1,1,0,0,0);
&debugtimegm(1959,1,1,0,0,0);
print "
\n";
&debugtimegm(1901,1,1,0,0,0);
&debugtimegm(1900,3,1,0,0,0);
&debugtimegm(1900,2,28,0,0,0);
&debugtimegm(1900,1,1,0,0,0);
print "
\n";
&debugtimegm(1899,12,31,23,59,59);
&debugtimegm(1899,1,1,0,0,0);
&debugtimegm(1898,1,1,0,0,0);
&debugtimegm(1897,1,1,0,0,0);
print "
\n";
&debugtimegm(100,1,1,0,0,0);
&debugtimegm(1,1,1,0,0,0);
print "
\n";
print "=== [ timelocal ] (GMT=JST-9:00) ===
\n";
&debugtimelocal(1962,1,1,9,0,1);
&debugtimelocal(1962,1,1,9,0,0);
&debugtimelocal(1962,1,1,8,59,59);
&debugtimelocal(1962,1,1,0,0,0);
&debugtimelocal(1961,12,31,23,59,59);
&debugtimelocal(1961,1,1,0,0,0);
&debugtimelocal(1960,1,1,0,0,0);
&debugtimelocal(1900,1,1,9,0,1);
&debugtimelocal(1900,1,1,9,0,0);
&debugtimelocal(1900,1,1,8,59,59);
&debugtimelocal(1900,1,1,0,0,0);
&debugtimelocal(1899,12,31,23,59,59);
&debugtimelocal(1899,1,1,0,0,0);
print "\n";
exit;
#-------------------------------------------------
# Result of Perl_timegm_Test2.cgi
#-------------------------------------------------
#
# Test of timegm/timelocal to appoint 4-digit years.
# [ diff-value:3155760000 / 86400 = (100 * 365.25) equal 100 years. ]
#
# Perl ver 5.012003 , Now = [ Tue Mar 15 04:31:49 2011 (GMT) ]
#
# 2039/1/1 0:0:0 -> epoch( 2177452800 ) -> DateTime( Sat Jan 1 00:00:00 2039 )
# 2038/1/19 3:14:8 -> epoch( 2147483648 ) -> DateTime( Tue Jan 19 03:14:08 2038 )
#
# 2038/1/19 3:14:7 -> epoch( 2147483647 ) -> DateTime( Tue Jan 19 03:14:07 2038 )
# 2038/1/19 3:14:6 -> epoch( 2147483646 ) -> DateTime( Tue Jan 19 03:14:06 2038 )
# 2038/1/19 0:0:0 -> epoch( 2147472000 ) -> DateTime( Tue Jan 19 00:00:00 2038 )
#
# 1970/1/1 0:0:0 -> epoch( 0 ) -> DateTime( Thu Jan 1 00:00:00 1970 )
# 1969/1/1 0:0:0 -> epoch( -31536000 ) -> DateTime( Wed Jan 1 00:00:00 1969 )
# 1968/1/1 0:0:0 -> epoch( -63158400 ) -> DateTime( Mon Jan 1 00:00:00 1968 )
# 1967/1/1 0:0:0 -> epoch( -94694400 ) -> DateTime( Sun Jan 1 00:00:00 1967 )
# 1966/1/1 0:0:0 -> epoch( -126230400 ) -> DateTime( Sat Jan 1 00:00:00 1966 )
# 1965/1/1 0:0:0 -> epoch( -157766400 ) -> DateTime( Fri Jan 1 00:00:00 1965 )
# 1964/1/1 0:0:0 -> epoch( -189388800 ) -> DateTime( Wed Jan 1 00:00:00 1964 )
# 1963/1/1 0:0:0 -> epoch( -220924800 ) -> DateTime( Tue Jan 1 00:00:00 1963 )
# 1962/1/1 0:0:0 -> epoch( -252460800 ) -> DateTime( Mon Jan 1 00:00:00 1962 )
#
# 1961/12/31 23:59:59 -> epoch( -252460801 ) -> DateTime( Sun Dec 31 23:59:59 1961 )
# 1961/1/1 0:0:0 -> epoch( -283996800 ) -> DateTime( Sun Jan 1 00:00:00 1961 )
# 1960/1/1 0:0:0 -> epoch( -315619200 ) -> DateTime( Fri Jan 1 00:00:00 1960 )
# 1959/1/1 0:0:0 -> epoch( -347155200 ) -> DateTime( Thu Jan 1 00:00:00 1959 )
#
# 1901/1/1 0:0:0 -> epoch( -2177452800 ) -> DateTime( Tue Jan 1 00:00:00 1901 )
# 1900/3/1 0:0:0 -> epoch( -2203891200 ) -> DateTime( Thu Mar 1 00:00:00 1900 )
# 1900/2/28 0:0:0 -> epoch( -2203977600 ) -> DateTime( Wed Feb 28 00:00:00 1900 )
# 1900/1/1 0:0:0 -> epoch( -2208988800 ) -> DateTime( Mon Jan 1 00:00:00 1900 )
#
# 1899/12/31 23:59:59 -> epoch( -2208988801 ) -> DateTime( Sun Dec 31 23:59:59 1899 )
# 1899/1/1 0:0:0 -> epoch( -2240524800 ) -> DateTime( Sun Jan 1 00:00:00 1899 )
# 1898/1/1 0:0:0 -> epoch( -2272060800 ) -> DateTime( Sat Jan 1 00:00:00 1898 )
# 1897/1/1 0:0:0 -> epoch( -2303596800 ) -> DateTime( Fri Jan 1 00:00:00 1897 )
#
# 100/1/1 0:0:0 -> epoch( -59011459200 ) -> DateTime( Fri Jan 1 00:00:00 100 )
# 1/1/1 0:0:0 -> epoch( -62135596800 ) -> DateTime( Mon Jan 1 00:00:00 1 )
#
#
# === [ timelocal ] (GMT=JST-9:00) ===
# 1962/1/1 9:0:1 -> epoch( -252460799 ) -> DateTime( Mon Jan 1 09:00:01 1962 )
# 1962/1/1 9:0:0 -> epoch( -252460800 ) -> DateTime( Mon Jan 1 09:00:00 1962 )
# 1962/1/1 8:59:59 -> epoch( -252460801 ) -> DateTime( Mon Jan 1 08:59:59 1962 )
# 1962/1/1 0:0:0 -> epoch( -252493200 ) -> DateTime( Mon Jan 1 00:00:00 1962 )
# 1961/12/31 23:59:59 -> epoch( -252493201 ) -> DateTime( Sun Dec 31 23:59:59 1961 )
# 1961/1/1 0:0:0 -> epoch( -284029200 ) -> DateTime( Sun Jan 1 00:00:00 1961 )
# 1960/1/1 0:0:0 -> epoch( -315651600 ) -> DateTime( Fri Jan 1 00:00:00 1960 )
# 1900/1/1 9:0:1 -> epoch( -2208988799 ) -> DateTime( Mon Jan 1 09:00:01 1900 )
# 1900/1/1 9:0:0 -> epoch( -2208988800 ) -> DateTime( Mon Jan 1 09:00:00 1900 )
# 1900/1/1 8:59:59 -> epoch( -2208988801 ) -> DateTime( Mon Jan 1 08:59:59 1900 )
# 1900/1/1 0:0:0 -> epoch( -2209021200 ) -> DateTime( Mon Jan 1 00:00:00 1900 )
# 1899/12/31 23:59:59 -> epoch( -2209021201 ) -> DateTime( Sun Dec 31 23:59:59 1899 )
# 1899/1/1 0:0:0 -> epoch( -2240557200 ) -> DateTime( Sun Jan 1 00:00:00 1899 )