replaced Date::Calc with Date::Manip

This commit is contained in:
JT Smith 2004-08-30 23:05:03 +00:00
parent 13002676db
commit a7e9ffb440
9 changed files with 10190 additions and 65 deletions

View file

@ -78,6 +78,9 @@
the shortcut. the shortcut.
- bugfix [ 1016271 ]. all posts go to last forum in MB (Leendert Bottelberghs). - bugfix [ 1016271 ]. all posts go to last forum in MB (Leendert Bottelberghs).
- Added FastCGI support. (Kevin Wilson) - Added FastCGI support. (Kevin Wilson)
- Replaced Date::Calc with Date::Manip to allow for dates before 1970 and
after 2035. (Emiliano Bruni)
- Added Date::Manip to the WebGUI distribution.
6.1.1 6.1.1

View file

@ -53,6 +53,8 @@ Convert::ASN1........................Graham Barr
Data::Config.........................Sébastien Aperghis-Tramoni Data::Config.........................Sébastien Aperghis-Tramoni
Date::Manip..........................Sullivan Beck
DBIx::FullTextSearch.................T.J. Mather DBIx::FullTextSearch.................T.J. Mather
DBIx::Tree::NestedSet................Dan Collis Puro DBIx::Tree::NestedSet................Dan Collis Puro

View file

@ -18,7 +18,6 @@ QnD INSTALL INSTRUCTIONS:
DBI DBI
DBD::mysql DBD::mysql
Digest::MD5 Digest::MD5
Date::Calc
HTML::Parser HTML::Parser
Archive::Tar Archive::Tar
Compress::Zlib Compress::Zlib

7362
lib/Date/Manip.pm Normal file

File diff suppressed because it is too large Load diff

2755
lib/Date/Manip.pod Normal file

File diff suppressed because it is too large Load diff

View file

@ -14,7 +14,7 @@ package WebGUI::DateTime;
=cut =cut
use Date::Calc; use Date::Manip;
use Exporter; use Exporter;
use strict; use strict;
use WebGUI::International; use WebGUI::International;
@ -66,6 +66,14 @@ These functions are available from this package:
=cut =cut
sub epochToDate {
my $secs = shift;
return &ParseDateString("epoch $secs");
}
sub dateToEpoch {
return &UnixDate(shift,"%s");
}
@ -98,11 +106,13 @@ The number of days to add to the epoch.
=cut =cut
sub addToDate { sub addToDate {
my ($year,$month,$day, $hour,$min,$sec, $newDate); my ($date,$years,$months,$days,$newDate);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); $date = &epochToDate(shift);
($year,$month,$day) = Date::Calc::Add_Delta_YMD($year,$month,$day, $_[1],$_[2],$_[3]); $years = shift || 0;
$newDate = arrayToEpoch($year,$month,$day, $hour,$min,$sec); $months = shift || 0;
return $newDate; $days = shift || 0;
$newDate = DateCalc($date,"$years:$months:0:$days:0:0:0");
return &dateToEpoch($newDate);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -134,11 +144,13 @@ The number of seconds to add to the epoch.
=cut =cut
sub addToTime { sub addToTime {
my ($year,$month,$day, $hour,$min,$sec, $newDate); my ($date,$hours,$mins,$secs,$newDate);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); $date = &epochToDate(shift);
($year,$month,$day, $hour,$min,$sec) = Date::Calc::Add_Delta_DHMS($year,$month,$day,$hour,$min,$sec,0,$_[1],$_[2],$_[3]); $hours = shift || 0;
$newDate = arrayToEpoch($year,$month,$day, $hour,$min,$sec); $mins = shift || 0;
return $newDate; $secs = shift || 0;
$newDate = DateCalc($date,"0:0:0:0:$hours:$mins:$secs");
return &dateToEpoch($newDate);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -158,13 +170,15 @@ An array of the format year, month, day, hour, min, sec.
=cut =cut
sub arrayToEpoch { sub arrayToEpoch {
my $year = shift; my $year = shift || '0000';
my $month = shift; my $month = shift || '00';
my $day = shift; my $day = shift || '00';
my $hour = shift; my $hour = shift || '00';
my $min = shift; my $min = shift || '00';
my $sec = shift; my $sec = shift || '00';
return Date::Calc::Date_to_Time($year,$month,$day,$hour,$min,$sec); $min = "0$min" if (length($min) == 1);
$sec = "0$sec" if (length($sec) == 1);
return &dateToEpoch(&ParseDate("$year-$month-$day $hour:$min:$sec"));
} }
@ -187,8 +201,8 @@ The number of seconds since January 1, 1970.
sub dayStartEnd { sub dayStartEnd {
my ($year,$month,$day, $hour,$min,$sec, $start, $end); my ($year,$month,$day, $hour,$min,$sec, $start, $end);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); ($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]);
$start = Date::Calc::Date_to_Time($year,$month,$day,0,0,0); $start = &arrayToEpoch($year,$month,$day,0,0,0);
$end = Date::Calc::Date_to_Time($year,$month,$day,23,59,59); $end = &arrayToEpoch($year,$month,$day,23,59,59);
return ($start, $end); return ($start, $end);
} }
@ -210,7 +224,7 @@ An epoch date.
sub epochToArray { sub epochToArray {
my $epoch = shift; my $epoch = shift;
return Date::Calc::Time_to_Date($epoch); return &UnixDate(epochToDate($epoch),'%Y','%m','%d','%H','%M','%S');
} }
@ -264,6 +278,7 @@ sub epochToHuman {
$offset = $offset*3600; $offset = $offset*3600;
$temp = int($_[0]) || WebGUI::DateTime::time(); $temp = int($_[0]) || WebGUI::DateTime::time();
$temp = $temp+$offset; $temp = $temp+$offset;
my $dt = epochToDate($temp);
my ($year,$month,$day,$hour,$min,$sec) = epochToArray($temp); my ($year,$month,$day,$hour,$min,$sec) = epochToArray($temp);
$output = $_[1] || "%z %Z"; $output = $_[1] || "%z %Z";
#---GMT Offsets #---GMT Offsets
@ -293,7 +308,7 @@ sub epochToHuman {
$output =~ s/\%c/$temp/g; $output =~ s/\%c/$temp/g;
} }
if ($output =~ /\%C/) { if ($output =~ /\%C/) {
$temp = substr(Date::Calc::Month_to_Text($month),0,3); $temp = &UnixDate($dt,'%b');
$output =~ s/\%C/$temp/g; $output =~ s/\%C/$temp/g;
} }
#---day stuff #---day stuff
@ -301,11 +316,11 @@ sub epochToHuman {
$output =~ s/\%d/$value/g; $output =~ s/\%d/$value/g;
$output =~ s/\%D/$day/g; $output =~ s/\%D/$day/g;
if ($output =~ /\%w/) { if ($output =~ /\%w/) {
$temp = getDayName(Date::Calc::Day_of_Week($year,$month,$day)); $temp = getDayName(&UnixDate($dt,'%w'));
$output =~ s/\%w/$temp/g; $output =~ s/\%w/$temp/g;
} }
if ($output =~ /%W/) { if ($output =~ /%W/) {
$temp = Date::Calc::Day_of_Week_Abbreviation(Date::Calc::Day_of_Week($year,$month,$day)); $temp = &UnixDate($dt,'%a');
$output =~ s/\%W/$temp/g; $output =~ s/\%W/$temp/g;
} }
#---hour stuff #---hour stuff
@ -463,7 +478,7 @@ An epoch date.
sub getDaysInMonth { sub getDaysInMonth {
my $epoch = shift; my $epoch = shift;
my @date = WebGUI::DateTime::epochToArray($epoch); my @date = WebGUI::DateTime::epochToArray($epoch);
return Date::Calc::Days_in_Month($date[0], $date[1]); return &Date_DaysInMonth($date[1], $date[0]);
} }
@ -488,11 +503,11 @@ An epoch date.
=cut =cut
sub getDaysInInterval { sub getDaysInInterval {
my $start = shift; my $start = &epochToDate(shift);
my $end = shift; my $end = &epochToDate(shift);
my @start = WebGUI::DateTime::epochToArray($start); my $err;
my @end = WebGUI::DateTime::epochToArray($end); my $delta = &DateCalc($start,$end,\$err);
return Date::Calc::Delta_Days($start[0], $start[1], $start[2], $end[0], $end[1], $end[2]); return &Delta_Format($delta,0,'%dh');
} }
@ -516,7 +531,7 @@ An epoch date.
sub getFirstDayInMonthPosition { sub getFirstDayInMonthPosition {
my $epoch = shift; my $epoch = shift;
my @date = WebGUI::DateTime::epochToArray($epoch); my @date = WebGUI::DateTime::epochToArray($epoch);
my $firstDayInFirstWeek = Date::Calc::Day_of_Week($date[0],$date[1],1); my $firstDayInFirstWeek = &UnixDate("$date[0]-$date[1]-01",'%w');
unless ($session{user}{firstDayOfWeek}) { #american format unless ($session{user}{firstDayOfWeek}) { #american format
$firstDayInFirstWeek++; $firstDayInFirstWeek++;
if ($firstDayInFirstWeek > 7) { if ($firstDayInFirstWeek > 7) {
@ -635,14 +650,15 @@ The number of seconds since January 1, 1970. Defaults to now.
=cut =cut
sub localtime { sub localtime {
my $epoch = shift; my $epoch = shift || &dateToEpoch(&ParseDate("today"));
my ($year, $month, $day, $hour, $min, $sec) = Date::Calc::Today_and_Now(); my $date = &epochToDate($epoch);
my ($year, $month, $day, $hour, $min, $sec) = epochToArray($epoch);
if ($epoch) { if ($epoch) {
($year, $month, $day, $hour, $min, $sec) = epochToArray($epoch); ($year, $month, $day, $hour, $min, $sec) = epochToArray($epoch);
} }
my $doy = Date::Calc::Day_of_Year($year,$month,$day); my $doy = &UnixDate($date,'%j');
my $dow = Date::Calc::Day_of_Week($year,$month,$day); my $dow = &UnixDate($date,'%w');
my @temp = Date::Calc::System_Clock(); my @temp = localtime($epoch);
return ($year, $month, $day, $hour, $min, $sec, $doy, $dow, $temp[8]); return ($year, $month, $day, $hour, $min, $sec, $doy, $dow, $temp[8]);
} }
@ -666,10 +682,12 @@ An epoch datestamp corresponding to the last month.
=cut =cut
sub monthCount { sub monthCount {
my ($start, $end) = @_; my $start = &epochToDate(shift);
my @delta = Date::Calc::Delta_YMDHMS( epochToArray($start), epochToArray($end)); my $end = &epochToDate(shift);
my $change = (($delta[0]*12)+$delta[1])+1; my $err;
return $change; my $delta = &DateCalc($start,$end,\$err,1);
return $delta;
return &Delta_Format($delta,0,'%Mh');
} }
@ -690,12 +708,11 @@ The number of seconds since January 1, 1970.
=cut =cut
sub monthStartEnd { sub monthStartEnd {
my ($year,$month,$day, $hour,$min,$sec, $start, $end); my ($year,$month,$day, $hour,$min,$sec, $start, $end);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); ($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]);
$start = arrayToEpoch($year,$month,1,0,0,0); $start = &arrayToEpoch($year,$month,1,0,0,0) + 0;
($year,$month,$day, $hour,$min,$sec) = epochToArray(addToDate($_[0],0,1,0)); $end = &UnixDate(&DateCalc(&epochToDate($start), "+1 month"),'%s')-1;
$end = arrayToEpoch($year,$month,1,0,0,0)-1; return ($start, $end);
return ($start, $end);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -789,7 +806,7 @@ sub setToEpoch {
my ($date,$time) = split(/ /,$_[0]); my ($date,$time) = split(/ /,$_[0]);
my ($year, $month, $day) = split(/\-/,$date); my ($year, $month, $day) = split(/\-/,$date);
my ($hour, $minute, $second) = split(/\:/,$time); my ($hour, $minute, $second) = split(/\:/,$time);
if (int($year) < 2038 && int($year) > 1969) { if (int($year) < 3000 && int($year) > 1000) {
$year = int($year); $year = int($year);
} else { } else {
$year = $now[0]; $year = $now[0];
@ -816,7 +833,7 @@ Returns an epoch date for now.
=cut =cut
sub time { sub time {
return arrayToEpoch(Date::Calc::Today_and_Now()); return dateToEpoch(&ParseDate("now"));
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------

View file

@ -16,7 +16,7 @@ package WebGUI::Session;
use CGI; use CGI;
use Date::Calc; use Date::Manip;
use DBI; use DBI;
use Exporter; use Exporter;
use strict; use strict;
@ -128,7 +128,7 @@ sub _setupUserInfo {
#------------------------------------------------------------------- #-------------------------------------------------------------------
sub _time { sub _time {
return Date::Calc::Date_to_Time(Date::Calc::Today_and_Now()); return &UnixDate(&ParseDate("now")),"%s");
} }

View file

@ -28,7 +28,6 @@ use Cache::FileCache ();
use CGI (); CGI->compile(':all'); use CGI (); CGI->compile(':all');
use CGI::Carp (); use CGI::Carp ();
use CGI::Util (); use CGI::Util ();
use Date::Calc ();
use Digest::MD5 (); use Digest::MD5 ();
eval "use Image::Magick ();"; # eval, may not be installed eval "use Image::Magick ();"; # eval, may not be installed
use File::Copy (); use File::Copy ();
@ -56,6 +55,7 @@ DBI->install_driver("mysql"); # Change to match your database driver.
#use HTML::Parser (); # commented because it is causing problems with attachments #use HTML::Parser (); # commented because it is causing problems with attachments
#use HTML::TagFilter (); # commented because it is causing problems with attachments #use HTML::TagFilter (); # commented because it is causing problems with attachments
use Parse::PlainConfig (); use Parse::PlainConfig ();
use Date::Manip ();
use Tie::CPHash (); use Tie::CPHash ();
use Tie::IxHash (); use Tie::IxHash ();
use Tree::DAG_Node (); use Tree::DAG_Node ();

View file

@ -187,19 +187,6 @@ if (eval { require Net::SMTP }) {
} }
} }
print "Date::Calc module ........................ ";
if (eval { require Date::Calc }) {
print "OK\n";
} else {
if ($< == 0 && $os eq "Linuxish") {
print "Attempting to install...\n";
CPAN::Shell->install("Date::Calc");
} else {
print "Please install.\n";
$prereq = 0;
}
}
print "Cache::Cache module ...................... "; print "Cache::Cache module ...................... ";
if (eval { require Cache::Cache }) { if (eval { require Cache::Cache }) {
print "OK\n"; print "OK\n";