now using DateTime instead of Date::Manip

This commit is contained in:
JT Smith 2005-11-02 09:37:49 +00:00
parent f6f9a46eba
commit 8ac8530227
11 changed files with 247 additions and 453 deletions

View file

@ -1,7 +1,7 @@
6.8.0 6.8.0
- Switched Date::Manip to DateTime and Time::HiRes to DateTime::HiRes for - Switched Date::Manip to DateTime for better performance and more
better performance and more functionality. See gotchas for details. functionality. See gotchas for details. In our benchmarks DateTime runs
about 13 times faster than Date::Manip.
6.7.7 6.7.7

View file

@ -11,11 +11,17 @@ save you many hours of grief.
-------------------------------------------------------------------- --------------------------------------------------------------------
* Before upgrading you must install the following new Perl modules: * Before upgrading you must install the following new Perl modules:
DateTime DateTime
DateTime::HiRes DateTime::Format::Strptime
DateTime::Cron::Simple DateTime::Cron::Simple
POE POE
POE::Component::IKC::Server POE::Component::IKC::Server
* The API has changed. Check docs/migration.txt for details.
* Due to the performance increase achieved by switching to DateTime we
no longer need date caching so the enableDateCache directive can
be removed from your config file.
6.7.0 6.7.0

View file

@ -481,3 +481,11 @@ by any WebGUI core package since 6.3 and wasn't really used much prior to that.
If you were using it, just copy it's subs into your app. If you were using it, just copy it's subs into your app.
5.22 DateTime API Changed Slightly
In 6.8.0, as a result of migrating the DateTime API away from Date::Manip and
to DateTime we've eliminated the need for several utility functions, and
therefore removed them. This shouldn't affect almost anybody, but we're
mentioning it just in case you're using WebGUI::DateTime in an odd mannner.
They are: epochToDate, dateToEpoch, epochToArray, arrayToEpoch

View file

@ -45,14 +45,6 @@ fileCacheSizeLimit=100000000
# memcached_servers = 10.0.0.6:11211 # memcached_servers = 10.0.0.6:11211
# If you enable date caching you can speed up your sites a little
# bit. If you use a lot of events calendars, this is highly
# recommended. However, note that this will likely create
# several hundred megabytes of cache files that are shared
# between your various sites that have date caching enabled
enableDateCache = 0
# Set this to 1 to disable WebGUI's caching subsystems. This is # Set this to 1 to disable WebGUI's caching subsystems. This is
# mainly useful for developers. # mainly useful for developers.

View file

@ -14,7 +14,9 @@ package WebGUI::DateTime;
=cut =cut
use Date::Manip; use DateTime;
use DateTime::Format::Strptime;
use DateTime::TimeZone;
use Exporter; use Exporter;
use strict; use strict;
use WebGUI::International; use WebGUI::International;
@ -39,9 +41,7 @@ This package provides easy to use date math functions, which are normally a comp
use WebGUI::DateTime; use WebGUI::DateTime;
$epoch = WebGUI::DateTime::addToDate($epoch, $years, $months, $days); $epoch = WebGUI::DateTime::addToDate($epoch, $years, $months, $days);
$epoch = WebGUI::DateTime::addToTime($epoch, $hours, $minutes, $seconds); $epoch = WebGUI::DateTime::addToTime($epoch, $hours, $minutes, $seconds);
$epoch = WebGUI::DateTime::arrayToEpoch(@date);
($startEpoch, $endEpoch) = WebGUI::DateTime::dayStartEnd($epoch); ($startEpoch, $endEpoch) = WebGUI::DateTime::dayStartEnd($epoch);
@date = WebGUI::DateTime::epochToArray($epoch);
$dateString = WebGUI::DateTime::epochToHuman($epoch, $formatString); $dateString = WebGUI::DateTime::epochToHuman($epoch, $formatString);
$setString = WebGUI::DateTime::epochToSet($epoch); $setString = WebGUI::DateTime::epochToSet($epoch);
$day = WebGUI::DateTime::getDayName($dayInteger); $day = WebGUI::DateTime::getDayName($dayInteger);
@ -50,6 +50,7 @@ This package provides easy to use date math functions, which are normally a comp
$integer = WebGUI::DateTime::getFirstDayInMonthPosition($epoch); $integer = WebGUI::DateTime::getFirstDayInMonthPosition($epoch);
$month = WebGUI::DateTime::getMonthName($monthInteger); $month = WebGUI::DateTime::getMonthName($monthInteger);
$seconds = WebGUI::DateTime::getSecondsFromEpoch($seconds); $seconds = WebGUI::DateTime::getSecondsFromEpoch($seconds);
$zones = WebGUI::DateTime::getTimeZones();
$epoch = WebGUI::DateTime::humanToEpoch($dateString); $epoch = WebGUI::DateTime::humanToEpoch($dateString);
$seconds = WebGUI::DateTime::intervalToSeconds($interval, $units); $seconds = WebGUI::DateTime::intervalToSeconds($interval, $units);
@date = WebGUI::DateTime::localtime($epoch); @date = WebGUI::DateTime::localtime($epoch);
@ -66,33 +67,6 @@ These functions are available from this package:
=cut =cut
sub epochToDate {
my $secs = shift;
my ($cache, $value);
if ($session{config}{enableDateCache}) {
$cache = WebGUI::Cache->new(["epochToDate",$secs],"DateTime");
$value = $cache->get;
}
return $value if ($value);
my $converted = &ParseDateString("epoch $secs");
$cache->set($converted) if ($session{config}{enableDateCache});
return $converted;
}
sub dateToEpoch {
my $date = shift;
my ($cache, $value);
if ($session{config}{enableDateCache}) {
$cache = WebGUI::Cache->new(["dateToEpoch",$date],"DateTime");
$value = $cache->get;
}
return $value if ($value);
my $converted = &UnixDate($date,"%s");
$cache->set($converted) if ($session{config}{enableDateCache});
return $converted;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -119,13 +93,15 @@ The number of days to add to the epoch.
=cut =cut
sub addToDate { sub addToDate {
my ($date,$years,$months,$days,$newDate); my $date = DateTime->from_epoch( epoch =>shift);
$date = &epochToDate(shift); my $years = shift || 0;
$years = shift || 0; my $months = shift || 0;
$months = shift || 0; my $days = shift || 0;
$days = shift || 0; my $currentTimeZone = $date->time_zone->name;
$newDate = DateCalc($date,"+$years:$months:0:$days:0:0:0"); $date->set_time_zone('UTC'); # do this to prevent date math errors due to daylight savings time shifts
return &dateToEpoch($newDate); $date->add(years=>$years, months=>$months, days=>$days);
$date->set_time_zone($currentTimeZone);
return $date->epoch;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -153,40 +129,14 @@ The number of seconds to add to the epoch.
=cut =cut
sub addToTime { sub addToTime {
my ($date,$hours,$mins,$secs,$newDate); my $date = DateTime->from_epoch( epoch =>shift);
$date = &epochToDate(shift); my $hours = shift || 0;
$hours = shift || 0; my $mins = shift || 0;
$mins = shift || 0; my $secs = shift || 0;
$secs = shift || 0; $date->add(hours=>$hours, minutes=>$mins, seconds=>$secs);
$newDate = DateCalc($date,"+0:0:0:0:$hours:$mins:$secs"); return $date->epoch;
return &dateToEpoch($newDate);
} }
#-------------------------------------------------------------------
=head2 arrayToEpoch ( date )
Returns an epoch date.
=head3 date
An array of the format year, month, day, hour, min, sec.
=cut
sub arrayToEpoch {
my $year = shift || '0000';
my $month = shift || '00';
my $day = shift || '00';
my $hour = shift || '00';
my $min = shift || '00';
my $sec = shift || '00';
$min = "0$min" if (length($min) == 1);
$sec = "0$sec" if (length($sec) == 1);
return &dateToEpoch(&ParseDate("$year-$month-$day $hour:$min:$sec"));
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 dayStartEnd ( epoch ) =head2 dayStartEnd ( epoch )
@ -200,35 +150,15 @@ The number of seconds since January 1, 1970.
=cut =cut
sub dayStartEnd { sub dayStartEnd {
my ($year,$month,$day, $hour,$min,$sec, $start, $end); my $dt = DateTime->from_epoch( epoch => shift);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); my $end = $dt->clone;
$start = &arrayToEpoch($year,$month,$day,0,0,0); $dt->set_hour(0);
$end = &arrayToEpoch($year,$month,$day,23,59,59); $dt->set_minute(0);
return ($start, $end); $dt->set_second(0);
} $end->set_hour(23);
$end->set_minute(59);
#------------------------------------------------------------------- $end->set_second(59);
return ($dt->epoch, $end->epoch);
=head2 epochToArray ( epoch )
Returns a date array in the form of year, month, day, hour, min, sec.
=head3 epoch
An epoch date.
=cut
sub epochToArray {
my $epoch = shift;
my @date = &UnixDate(epochToDate($epoch),'%Y','%m','%d','%H','%M','%S');
$date[0] = $date[0]+0;
$date[1] = $date[1]+0;
$date[2] = $date[2]+0;
$date[3] = $date[3]+0;
$date[4] = $date[4]+0;
$date[5] = $date[5]+0;
return @date;
} }
@ -248,7 +178,7 @@ A string representing the output format for the date. Defaults to '%z %Z'. You c
%% = % (percent) symbol. %% = % (percent) symbol.
%c = The calendar month name. %c = The calendar month name.
%C = The calendar month name abbreviated to 3 characters and represented in English. %C = The calendar month name abbreviated.
%d = A two digit day. %d = A two digit day.
%D = A variable digit day. %D = A variable digit day.
%h = A two digit hour (on a 12 hour clock). %h = A two digit hour (on a 12 hour clock).
@ -258,13 +188,12 @@ A string representing the output format for the date. Defaults to '%z %Z'. You c
%m = A two digit month. %m = A two digit month.
%M = A variable digit month. %M = A variable digit month.
%n = A two digit minute. %n = A two digit minute.
%o = Offset from local time represented as an integer. %O = Offset from GMT/UTC represented in four digit form with a sign. Example: -0600
%O = Offset from GMT represented in four digit form with a sign. Example: -0600
%p = A lower-case am/pm. %p = A lower-case am/pm.
%P = An upper-case AM/PM. %P = An upper-case AM/PM.
%s = A two digit second. %s = A two digit second.
%w = Day of the week. %w = Day of the week.
%W = Day of the week abbreviated to 3 characters and represented in English. %W = Day of the week abbreviated.
%y = A four digit year. %y = A four digit year.
%Y = A two digit year. %Y = A two digit year.
%z = The current user's date format preference. %z = The current user's date format preference.
@ -273,85 +202,50 @@ A string representing the output format for the date. Defaults to '%z %Z'. You c
=cut =cut
sub epochToHuman { sub epochToHuman {
my ($offset, $temp, $hour12, $value, $output); my $language = WebGUI::International::get($session{user}{language});
$offset = $session{user}{timeOffset} || 0; my $locale = $language->{languageAbbreviation} || "en";
$offset = $offset*3600; $locale .= "_".$language->{locale} if ($language->{locale});
$temp = int($_[0]) || WebGUI::DateTime::time(); my $dt = DateTime->from_epoch( epoch=>shift||time(), time_zone=>$session{user}{timeZone}, locale=>$locale );
$temp = $temp+$offset; my $output = shift || "%z %Z";
my $dt = epochToDate($temp); my $temp;
my ($year,$month,$day,$hour,$min,$sec) = epochToArray($temp);
$output = $_[1] || "%z %Z";
#---GMT Offsets
if ($output =~ /\%O/) {
$temp = $session{user}{timeOffset}*100;
$temp = sprintf("%+05d",Date::Manip::UnixDate("now","%z")+$temp);
$output =~ s/\%O/$temp/g;
}
$temp = $session{user}{timeOffset}+0;
$output =~ s/\%o/$temp/g;
#---dealing with percent symbol
$output =~ s/\%\%/\%/g;
#---date format preference #---date format preference
$temp = $session{user}{dateFormat} || '%M/%D/%y'; $temp = $session{user}{dateFormat} || '%M/%D/%y';
$output =~ s/\%z/$temp/g; $output =~ s/\%z/$temp/g;
#---time format preference #---time format preference
$temp = $session{user}{timeFormat} || '%H:%n %p'; $temp = $session{user}{timeFormat} || '%H:%n %p';
$output =~ s/\%Z/$temp/g; $output =~ s/\%Z/$temp/g;
#---year stuff #--- convert WebGUI date formats to DateTime formats
$output =~ s/\%y/$year/g; my %conversion = (
$value = substr($year,2,2); "c" => "B",
$output =~ s/\%Y/$value/g; "C" => "b",
#---month stuff "d" => "d",
$value = sprintf("%02d",$month); "D" => "e",
$output =~ s/\%m/$value/g; "h" => "I",
$output =~ s/\%M/$month/g; "H" => "l",
if ($output =~ /\%c/) { "j" => "H",
$temp = getMonthName($month); "J" => "k",
$output =~ s/\%c/$temp/g; "m" => "m",
"M" => "_varmonth_",
"n" => "M",
"O" => "z",
"p" => "P",
"P" => "p",
"s" => "S",
"w" => "A",
"W" => "a",
"y" => "Y",
"Y" => "y"
);
$output =~ s/\%(\w)/\~$1/g;
foreach my $key (keys %conversion) {
my $replacement = $conversion{$key};
$output =~ s/\~$key/\%$replacement/g;
} }
if ($output =~ /\%C/) { #--- %M
$temp = &UnixDate($dt,'%b'); $output = $dt->strftime($output);
$output =~ s/\%C/$temp/g; $temp = int($dt->month);
} $output =~ s/\%_varmonth_/$temp/g;
#---day stuff #--- return
$value = sprintf("%02d",$day);
$output =~ s/\%d/$value/g;
$output =~ s/\%D/$day/g;
if ($output =~ /\%w/) {
$temp = getDayName(&UnixDate($dt,'%w'));
$output =~ s/\%w/$temp/g;
}
if ($output =~ /%W/) {
$temp = &UnixDate($dt,'%a');
$output =~ s/\%W/$temp/g;
}
#---hour stuff
$hour12 = $hour;
if ($hour12 > 12) {
$hour12 = $hour12 - 12;
}
if ($hour12 == 0) {
$hour12 = 12;
}
$value = sprintf("%02d",$hour12);
$output =~ s/\%h/$value/g;
$output =~ s/\%H/$hour12/g;
$value = sprintf("%02d",$hour);
$output =~ s/\%j/$value/g;
$output =~ s/\%J/$hour/g;
if ($hour > 11) {
$output =~ s/\%p/pm/g;
$output =~ s/\%P/PM/g;
} else {
$output =~ s/\%p/am/g;
$output =~ s/\%P/AM/g;
}
#---minute stuff
$value = sprintf("%02d",$min);
$output =~ s/\%n/$value/g;
#---second stuff
$value = sprintf("%02d",$sec);
$output =~ s/\%s/$value/g;
return $output; return $output;
} }
@ -372,50 +266,12 @@ A boolean indicating that the time should be added to the output, thust turning
=cut =cut
sub epochToSet { sub epochToSet {
if ($_[1]) { my $dt = DateTime->from_epoch( epoch =>shift, time_zone=>$session{user}{timeZone});
return epochToHuman($_[0],"%y-%m-%d %j:%n:%s"); my $withTime = shift;
if ($withTime) {
return $dt->strftime("%Y-%m-%d %H:%M:%S");
} }
return epochToHuman($_[0],"%y-%m-%d"); return $dt->strftime("%Y-%m-%d");
}
#-------------------------------------------------------------------
=head2 getMonthName ( month )
Returns a string containing the calendar month name in the language of the current user.
=head3 month
An integer ranging from 1-12 representing the month.
=cut
sub getMonthName {
if ($_[0] == 1) {
return WebGUI::International::get(15);
} elsif ($_[0] == 2) {
return WebGUI::International::get(16);
} elsif ($_[0] == 3) {
return WebGUI::International::get(17);
} elsif ($_[0] == 4) {
return WebGUI::International::get(18);
} elsif ($_[0] == 5) {
return WebGUI::International::get(19);
} elsif ($_[0] == 6) {
return WebGUI::International::get(20);
} elsif ($_[0] == 7) {
return WebGUI::International::get(21);
} elsif ($_[0] == 8) {
return WebGUI::International::get(22);
} elsif ($_[0] == 9) {
return WebGUI::International::get(23);
} elsif ($_[0] == 10) {
return WebGUI::International::get(24);
} elsif ($_[0] == 11) {
return WebGUI::International::get(25);
} elsif ($_[0] == 12) {
return WebGUI::International::get(26);
}
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -433,19 +289,19 @@ An integer ranging from 1-7 representing the day of the week (Sunday is 1 and Sa
sub getDayName { sub getDayName {
my $day = $_[0]; my $day = $_[0];
if ($day == 7) { if ($day == 7) {
return WebGUI::International::get(27); return WebGUI::International::get('sunday','DateTime');
} elsif ($day == 1) { } elsif ($day == 1) {
return WebGUI::International::get(28); return WebGUI::International::get('monday','DateTime');
} elsif ($day == 2) { } elsif ($day == 2) {
return WebGUI::International::get(29); return WebGUI::International::get('tuesday','DateTime');
} elsif ($day == 3) { } elsif ($day == 3) {
return WebGUI::International::get(30); return WebGUI::International::get('wednesday','DateTime');
} elsif ($day == 4) { } elsif ($day == 4) {
return WebGUI::International::get(31); return WebGUI::International::get('thursday','DateTime');
} elsif ($day == 5) { } elsif ($day == 5) {
return WebGUI::International::get(32); return WebGUI::International::get('friday','DateTime');
} elsif ($day == 6) { } elsif ($day == 6) {
return WebGUI::International::get(33); return WebGUI::International::get('saturday','DateTime');
} }
} }
@ -462,9 +318,9 @@ An epoch date.
=cut =cut
sub getDaysInMonth { sub getDaysInMonth {
my $epoch = shift; my $dt = DateTime->from_epoch( epoch =>shift);
my @date = WebGUI::DateTime::epochToArray($epoch); my $last = DateTime->last_day_of_month(year=>$dt->year, month=>$dt->month);
return &Date_DaysInMonth($date[1], $date[0]); return $last->day;
} }
@ -485,20 +341,18 @@ An epoch date.
=cut =cut
sub getDaysInInterval { sub getDaysInInterval {
my $start = &epochToDate(shift); my $start = DateTime->from_epoch( epoch =>shift);
my $end = &epochToDate(shift); my $end = DateTime->from_epoch( epoch =>shift);
my $err; my $duration = $end - $start;
my $delta = &DateCalc($start,$end,\$err); return $duration->delta_days;
return &Delta_Format($delta,0,'%dh');
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getFirstDayInMonthPosition ( epoch) { =head2 getFirstDayInMonthPosition ( epoch) {
Returns the position (1 - 7) of the first day in the month. Returns the position (1 - 7) of the first day in the month. 1 is Monday.
=head3 epoch =head3 epoch
@ -507,19 +361,52 @@ An epoch date.
=cut =cut
sub getFirstDayInMonthPosition { sub getFirstDayInMonthPosition {
my $epoch = shift; my $dt = DateTime->from_epoch( epoch => shift );
my @date = WebGUI::DateTime::epochToArray($epoch); $dt->set_day(1);
my $firstDayInFirstWeek = &UnixDate("$date[0]-$date[1]-01",'%w'); return $dt->day_of_week;
unless ($session{user}{firstDayOfWeek}) { #american format
$firstDayInFirstWeek++;
if ($firstDayInFirstWeek > 7) {
$firstDayInFirstWeek = 1;
}
}
return $firstDayInFirstWeek;
} }
#-------------------------------------------------------------------
=head2 getMonthName ( month )
Returns a string containing the calendar month name in the language of the current user.
=head3 month
An integer ranging from 1-12 representing the month.
=cut
sub getMonthName {
if ($_[0] == 1) {
return WebGUI::International::get('january','DateTime');
} elsif ($_[0] == 2) {
return WebGUI::International::get('february','DateTime');
} elsif ($_[0] == 3) {
return WebGUI::International::get('march','DateTime');
} elsif ($_[0] == 4) {
return WebGUI::International::get('april','DateTime');
} elsif ($_[0] == 5) {
return WebGUI::International::get('may','DateTime');
} elsif ($_[0] == 6) {
return WebGUI::International::get('june','DateTime');
} elsif ($_[0] == 7) {
return WebGUI::International::get('july','DateTime');
} elsif ($_[0] == 8) {
return WebGUI::International::get('august','DateTime');
} elsif ($_[0] == 9) {
return WebGUI::International::get('september','DateTime');
} elsif ($_[0] == 10) {
return WebGUI::International::get('october','DateTime');
} elsif ($_[0] == 11) {
return WebGUI::International::get('november','DateTime');
} elsif ($_[0] == 12) {
return WebGUI::International::get('december','DateTime');
}
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getSecondsFromEpoch ( epoch ) =head2 getSecondsFromEpoch ( epoch )
@ -533,10 +420,34 @@ The number of seconds since January 1, 1970 00:00:00.
=cut =cut
sub getSecondsFromEpoch { sub getSecondsFromEpoch {
return timeToSeconds(epochToHuman($_[0],"%j:%n:%s")); my $dt = DateTime->from_epoch( epoch => shift );
my $start = $dt->clone;
$start->set_hour(0);
$start->set_minute(0);
$start->set_second(0);
my $duration = $dt - $start;
return $duration->delta_seconds;
} }
#-------------------------------------------------------------------
=head2 getTimeZones ( )
Returns a hash reference containing name/value pairs both with the list of time zones.
=cut
sub getTimeZones {
my %zones;
foreach my $zone (@{DateTime::TimeZone::all_names()}) {
my $zoneLabel = $zone;
$zoneLabel =~ s/\_/ /g;
$zones{$zone} = $zoneLabel;
}
return \%zones;
}
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -551,18 +462,11 @@ The human date string. YYYY-MM-DD HH:MM:SS
=cut =cut
sub humanToEpoch { sub humanToEpoch {
my (@temp, $dateString, $timeString, $output, @date); my ($dateString,$timeString) = split(/ /,shift);
($dateString,$timeString) = split(/ /,$_[0]); my @date = split(/-/,$dateString);
@temp = split(/-/,$dateString); my @time = split(/:/,$timeString);
$date[0] = int($temp[0]); my $dt = DateTime->new(year => $date[0], month=> $date[1], day=> $date[2], hour=> $time[0], minute => $time[1], second => $time[2]);
$date[1] = int($temp[1]); return $dt->epoch;
$date[2] = int($temp[2]);
@temp = split(/:/,$timeString);
$date[3] = int($temp[0]);
$date[4] = int($temp[1]);
$date[5] = int($temp[2]);
$output = arrayToEpoch(@date);
return $output;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -582,20 +486,22 @@ A string which represents the units of the interval. The string must be 'years',
=cut =cut
sub intervalToSeconds { sub intervalToSeconds {
if ($_[1] eq "years") { my $interval = shift;
return ($_[0]*31536000); my $units = shift;
} elsif ($_[1] eq "months") { if ($units eq "years") {
return ($_[0]*2592000); return ($interval*31536000);
} elsif ($_[1] eq "weeks") { } elsif ($units eq "months") {
return ($_[0]*604800); return ($interval*2592000);
} elsif ($_[1] eq "days") { } elsif ($units eq "weeks") {
return ($_[0]*86400); return ($interval*604800);
} elsif ($_[1] eq "hours") { } elsif ($units eq "days") {
return ($_[0]*3600); return ($interval*86400);
} elsif ($_[1] eq "minutes") { } elsif ($units eq "hours") {
return ($_[0]*60); return ($interval*3600);
} elsif ($units eq "minutes") {
return ($interval*60);
} else { } else {
return $_[0]; return $interval;
} }
} }
@ -612,16 +518,8 @@ The number of seconds since January 1, 1970. Defaults to now.
=cut =cut
sub localtime { sub localtime {
my $epoch = shift || &dateToEpoch(&ParseDate("today")); my $dt = DateTime->from_epoch( epoch => shift || time() );
my $date = &epochToDate($epoch); return ( $dt->year, $dt->month, $dt->day, $dt->hour, $dt->minute, $dt->second, $dt->day_of_year, $dt->day_of_week, $dt->is_dst );
my ($year, $month, $day, $hour, $min, $sec) = epochToArray($epoch);
if ($epoch) {
($year, $month, $day, $hour, $min, $sec) = epochToArray($epoch);
}
my $doy = &UnixDate($date,'%j');
my $dow = &UnixDate($date,'%w');
my @temp = localtime($epoch);
return ($year, $month, $day, $hour, $min, $sec, $doy, $dow, $temp[8]);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -640,12 +538,10 @@ An epoch datestamp corresponding to the last month.
=cut =cut
sub monthCount { sub monthCount {
my $start = &epochToDate(shift); my $start = DateTime->from_epoch( epoch => shift );
my $end = &epochToDate(shift); my $end = DateTime->from_epoch( epoch => shift );
my $err; my $duration = $end - $start;
my $delta = &DateCalc($start,$end,\$err,1); return $duration->delta_months;
my $count = 1+&Delta_Format($delta,0,'%Mv')+&Delta_Format($delta,0,'%yv')*12;
return $count;
} }
@ -662,11 +558,15 @@ The number of seconds since January 1, 1970.
=cut =cut
sub monthStartEnd { sub monthStartEnd {
my ($year,$month,$day, $hour,$min,$sec, $start, $end); my $dt = DateTime->from_epoch( epoch => shift);
($year,$month,$day, $hour,$min,$sec) = epochToArray($_[0]); my $end = DateTime->last_day_of_month(year=>$dt->year, month=>$dt->month);
$start = &arrayToEpoch($year,$month,1,0,0,0) + 0; $dt->set_hour(0);
$end = &UnixDate(&DateCalc(&epochToDate($start), "+1 month"),'%s')-1; $dt->set_minute(0);
return ($start, $end); $dt->set_second(0);
$end->set_hour(23);
$end->set_minute(59);
$end->set_second(59);
return ($dt->epoch, $end->epoch);
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -682,27 +582,28 @@ The number of seconds in the interval.
=cut =cut
sub secondsToInterval { sub secondsToInterval {
my $seconds = shift;
my ($interval, $units); my ($interval, $units);
if ($_[0] >= 31536000) { if ($seconds >= 31536000) {
$interval = round($_[0]/31536000); $interval = round($seconds/31536000);
$units = "years"; $units = "years";
} elsif ($_[0] >= 2592000) { } elsif ($seconds >= 2592000) {
$interval = round($_[0]/2592000); $interval = round($seconds/2592000);
$units = "months"; $units = "months";
} elsif ($_[0] >= 604800) { } elsif ($seconds >= 604800) {
$interval = round($_[0]/604800); $interval = round($seconds/604800);
$units = "weeks"; $units = "weeks";
} elsif ($_[0] >= 86400) { } elsif ($seconds >= 86400) {
$interval = round($_[0]/86400); $interval = round($seconds/86400);
$units = "days"; $units = "days";
} elsif ($_[0] >= 3600) { } elsif ($seconds >= 3600) {
$interval = round($_[0]/3600); $interval = round($seconds/3600);
$units = "hours"; $units = "hours";
} elsif ($_[0] >= 60) { } elsif ($seconds >= 60) {
$interval = round($_[0]/60); $interval = round($seconds/60);
$units = "minutes"; $units = "minutes";
} else { } else {
$interval = $_[0]; $interval = $seconds;
$units = "seconds"; $units = "seconds";
} }
return ($interval, $units); return ($interval, $units);
@ -721,7 +622,7 @@ A number of seconds.
=cut =cut
sub secondsToTime { sub secondsToTime {
my $seconds = $_[0]; my $seconds = shift;
my $timeString = sprintf("%02d",int($seconds / 3600)).":"; my $timeString = sprintf("%02d",int($seconds / 3600)).":";
$seconds = $seconds % 3600; $seconds = $seconds % 3600;
$timeString .= sprintf("%02d",int($seconds / 60)).":"; $timeString .= sprintf("%02d",int($seconds / 60)).":";
@ -745,31 +646,13 @@ A string in the format of YYYY-MM-DD or YYYY-MM-DD HH:MM:SS.
sub setToEpoch { sub setToEpoch {
my $set = shift; my $set = shift;
my @now = epochToArray(WebGUI::DateTime::time()); my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d %H:%M:%S' );
my ($date,$time) = split(/ /,$set); my $dt = $parser->parse_datetime($set);
my ($year, $month, $day) = split(/\-/,$date); # in epochToSet we apply the user's time zone, so now we have to remove it.
my ($hour, $minute, $second) = split(/\:/,$time); $dt->set_time_zone($session{user}{timeZone}); # assign the user's timezone
if (int($year) < 3000 && int($year) > 1000) { my $u = WebGUI::User->new(1);
$year = int($year); $dt->set_time_zone($u->profileField("timeZone")); # convert to the visitor's or default time zone
} else { return $dt->epoch;
$year = $now[0];
}
if (int($month) < 13 && int($month) > 0) {
$month = int($month);
} else {
$month = $now[1]++;
}
if (int($day) < 32 && int($day) > 0) {
$day = int($day);
} else {
$day = $now[2];
}
my $epoch = arrayToEpoch($year,$month,$day,$hour,$minute,$second);
# in epochToSet we use epochToHuman, which includes the time
# offset of the user, so we need to remove that here.
my $offset = $session{user}{timeOffset} || 0;
$epoch -= $offset*3600;
return $epoch;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -781,8 +664,7 @@ Returns an epoch date for now.
=cut =cut
sub time { sub time {
#return dateToEpoch(&ParseDate("now")); return time();
return time;
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -799,7 +681,7 @@ A string that looks similar to this: 15:05:32
sub timeToSeconds { sub timeToSeconds {
my ($hour,$min,$sec) = split(/:/,$_[0]); my ($hour,$min,$sec) = split(/:/,$_[0]);
return ($hour*3600+$min*60+$sec); return ($hour*60*60+$min*60+$sec);
} }

View file

@ -22,7 +22,7 @@ use WebGUI::Session;
=head1 NAME =head1 NAME
Package WebGUI::Form::selectList Package WebGUI::Form::SelectList
=head1 DESCRIPTION =head1 DESCRIPTION

View file

@ -218,7 +218,7 @@ sub www_editProfileField {
-hoverHelp=>WebGUI::International::get('486 description',"WebGUIProfile"), -hoverHelp=>WebGUI::International::get('486 description',"WebGUIProfile"),
-value=>$data{dataType}, -value=>$data{dataType},
-defaultValue=>"text", -defaultValue=>"text",
-types=>[qw(dateTime TimeField float zipcode text textarea HTMLArea url date email phone integer yesNo selectList radioList checkList)] -types=>[qw(dateTime timeZone TimeField float zipcode text textarea HTMLArea url date email phone integer yesNo selectList radioList checkList)]
); );
$f->textarea( $f->textarea(
-name => "dataValues", -name => "dataValues",

View file

@ -6,8 +6,8 @@ use strict;
our $LANGUAGE = { our $LANGUAGE = {
label => 'English', label => 'English',
toolbar => 'metal', toolbar => 'metal',
languageAbbreviation => 'en', languageAbbreviation => 'en', # used by plugins such as javascript helpers and third-party perl modules
locale => 'US' locale => 'US' # same as above
}; };
sub makeUrlCompliant { sub makeUrlCompliant {

View file

@ -41,11 +41,6 @@ our $I18N = {
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'32' => {
message => q|Friday|,
lastUpdated => 1031514049
},
'443' => { '443' => {
message => q|Home Information|, message => q|Home Information|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -127,11 +122,6 @@ our $I18N = {
lastUpdated => 1065356764 lastUpdated => 1065356764
}, },
'31' => {
message => q|Thursday|,
lastUpdated => 1031514049
},
'578' => { '578' => {
message => q|You have a pending message to approve.|, message => q|You have a pending message to approve.|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -167,11 +157,6 @@ our $I18N = {
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'29' => {
message => q|Tuesday|,
lastUpdated => 1031514049
},
'889' => { '889' => {
message => q|Style Sheets, Tabs|, message => q|Style Sheets, Tabs|,
lastUpdated => 1046067380 lastUpdated => 1046067380
@ -202,11 +187,6 @@ our $I18N = {
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'15' => {
message => q|January|,
lastUpdated => 1031514049
},
'527' => { '527' => {
message => q|Default Home Page|, message => q|Default Home Page|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -317,11 +297,6 @@ our $I18N = {
lastUpdated => 1056151382 lastUpdated => 1056151382
}, },
'23' => {
message => q|September|,
lastUpdated => 1031514049
},
'364' => { '364' => {
message => q|Search|, message => q|Search|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -397,11 +372,6 @@ Be aware that any database links you create here will be available to all conten
lastUpdated => 1035246389 lastUpdated => 1035246389
}, },
'21' => {
message => q|July|,
lastUpdated => 1031514049
},
'523' => { '523' => {
message => q|Notification|, message => q|Notification|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -718,11 +688,6 @@ to add or remove user from their groups.
lastUpdated => 1037583186 lastUpdated => 1037583186
}, },
'22' => {
message => q|August|,
lastUpdated => 1031514049
},
'42' => { '42' => {
message => q|Please Confirm|, message => q|Please Confirm|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -788,11 +753,6 @@ to add or remove user from their groups.
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'27' => {
message => q|Sunday|,
lastUpdated => 1031514049
},
'161' => { '161' => {
message => q|Submitted By|, message => q|Submitted By|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -823,11 +783,6 @@ to add or remove user from their groups.
lastUpdated => 1035864828 lastUpdated => 1035864828
}, },
'20' => {
message => q|June|,
lastUpdated => 1031514049
},
'1011' => { '1011' => {
message => q|Code|, message => q|Code|,
lastUpdated => 1060433339 lastUpdated => 1060433339
@ -938,11 +893,6 @@ That particular example will help you get good ranking on search engines.
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'17' => {
message => q|March|,
lastUpdated => 1031514049
},
'333' => { '333' => {
message => q|Work Country|, message => q|Work Country|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -1044,11 +994,6 @@ removed from the system after a set period of time. That period of time is set
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'33' => {
message => q|Saturday|,
lastUpdated => 1031514049
},
'660' => { '660' => {
message => q|Groups, Manage|, message => q|Groups, Manage|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -1064,11 +1009,6 @@ removed from the system after a set period of time. That period of time is set
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'26' => {
message => q|December|,
lastUpdated => 1031514049
},
'977' => { '977' => {
message => q|Is secondary admin?|, message => q|Is secondary admin?|,
lastUpdated => 1053803387 lastUpdated => 1053803387
@ -1417,11 +1357,6 @@ The Groups page displays all groups that you are allowed to edit. The form on t
lastUpdated => 1057208065 lastUpdated => 1057208065
}, },
'28' => {
message => q|Monday|,
lastUpdated => 1031514049
},
'40' => { '40' => {
message => q|Vital Component|, message => q|Vital Component|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -1602,11 +1537,6 @@ As with any delete operation, you are prompted to be sure you wish to proceed wi
lastUpdated => 1033836642 lastUpdated => 1033836642
}, },
'16' => {
message => q|February|,
lastUpdated => 1031514049
},
'1069' => { '1069' => {
message => q|Host To Use|, message => q|Host To Use|,
lastUpdated => 1066641432 lastUpdated => 1066641432
@ -1899,11 +1829,6 @@ This group could then be named "Employees in HMO 1", and would allow you to rest
lastUpdated => 1053278089 lastUpdated => 1053278089
}, },
'24' => {
message => q|October|,
lastUpdated => 1031514049
},
'858' => { '858' => {
message => q|Alias|, message => q|Alias|,
lastUpdated => 1043879848 lastUpdated => 1043879848
@ -2437,11 +2362,6 @@ A list of links to the 10 nearest in the paginator relative to the current page.
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'25' => {
message => q|November|,
lastUpdated => 1031514049
},
'738' => { '738' => {
message => q|9 Guru|, message => q|9 Guru|,
lastUpdated => 1033836704 lastUpdated => 1033836704
@ -2664,11 +2584,6 @@ As with any delete operation, you are prompted to be sure you wish to proceed wi
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'18' => {
message => q|April|,
lastUpdated => 1031514049
},
'125' => { '125' => {
message => q|Company Name|, message => q|Company Name|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -3130,11 +3045,6 @@ that Asset and all Assets below it.</p>
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'19' => {
message => q|May|,
lastUpdated => 1031514049
},
'54' => { '54' => {
message => q|Create Account|, message => q|Create Account|,
lastUpdated => 1031514049 lastUpdated => 1031514049
@ -3180,11 +3090,6 @@ that Asset and all Assets below it.</p>
lastUpdated => 1031514049 lastUpdated => 1031514049
}, },
'30' => {
message => q|Wednesday|,
lastUpdated => 1031514049
},
'403' => { '403' => {
message => q|Prefer not to say.|, message => q|Prefer not to say.|,
lastUpdated => 1031514049 lastUpdated => 1031514049

View file

@ -44,22 +44,23 @@ use Net::SMTP ();
use Log::Log4perl (); use Log::Log4perl ();
use Tie::IxHash (); use Tie::IxHash ();
use Tie::CPHash (); use Tie::CPHash ();
use Time::HiRes ();
use DateTime (); use DateTime ();
use DateTime::HiRes (); use DateTime::Format::Strptime ();
use DateTime::TimeZone ();
use Image::Magick (); use Image::Magick ();
use Storable; use Storable;
use XML::Simple (); use XML::Simple ();
use Compress::Zlib ();
use Archive::Tar ();
use IO::Zlib ();
#### ####
# less commonly used so you may not want them to load into memory # less commonly used so you may not want them to load into memory
### ###
#use Compress::Zlib (); # used only by themes
#use Archive::Tar (); # used only by themes
#use IO::Zlib (); # used only by themes
#use SOAP::Lite (); # used only by WS Client #use SOAP::Lite (); # used only by WS Client
#use Net::LDAP (); # used only by LDAP authentication module #use Net::LDAP (); # used only by LDAP authentication module
#use XML::RSSLite (); # used only by syndicated content wobject #use XML::RSSLite (); # used only by syndicated content wobject
#use DBIx::FullTextSearch (); #used only by search engine
#use HTML::Highlight (); # used only by search engine #use HTML::Highlight (); # used only by search engine
@ -139,6 +140,7 @@ use WebGUI::i18n::English::Asset_Navigation ();
#use WebGUI::i18n::English::AuthLDAP (); #use WebGUI::i18n::English::AuthLDAP ();
use WebGUI::i18n::English::AuthWebGUI (); use WebGUI::i18n::English::AuthWebGUI ();
use WebGUI::i18n::English::WebGUI (); use WebGUI::i18n::English::WebGUI ();
use WebGUI::i18n::English::DateTime ();
use WebGUI::i18n::English::WebGUIProfile (); use WebGUI::i18n::English::WebGUIProfile ();
# you can significantly reduce your memory usage by preloading the plugins used on your sites, only the most commonly used ones are preloaded by default # you can significantly reduce your memory usage by preloading the plugins used on your sites, only the most commonly used ones are preloaded by default
@ -156,9 +158,7 @@ use WebGUI::Asset::Wobject::Collaboration ();
# auth methods # auth methods
use WebGUI::Auth::WebGUI (); use WebGUI::Auth::WebGUI ();
#use WebGUI::Auth::LDAP ();
#use Net::LDAP (); # used by ldap authentication
use WebGUI::Auth::LDAP ();
# macros # macros
use WebGUI::Macro::AdminBar (); use WebGUI::Macro::AdminBar ();

View file

@ -58,7 +58,8 @@ checkModule("Tie::CPHash",1.001);
checkModule("XML::Simple",2.09); checkModule("XML::Simple",2.09);
checkModule("SOAP::Lite",0.60); checkModule("SOAP::Lite",0.60);
checkModule("DateTime",0.2901); checkModule("DateTime",0.2901);
checkModule("DateTime::HiRes",0.01); checkModule("Time::HiRes",1.38);
checkModule("DateTime::Format::Strptime");
checkModule("DateTime::Cron::Simple",0.2); checkModule("DateTime::Cron::Simple",0.2);
checkModule("Image::Magick",5.47,1); checkModule("Image::Magick",5.47,1);
checkModule("Log::Log4perl",0.51); checkModule("Log::Log4perl",0.51);