summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Util.pm
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2005-05-11 05:30:11 +0200
committerlpsolit%gmail.com <>2005-05-11 05:30:11 +0200
commita32c764ba4f84270e5730e643d099b46313e071a (patch)
tree69f13d696a293e47c41f2ab1af483628e9f87752 /Bugzilla/Util.pm
parentd5c3b178067c1d9c0c7f5cf7756c1969443410fd (diff)
downloadbugzilla-a32c764ba4f84270e5730e643d099b46313e071a.tar.gz
bugzilla-a32c764ba4f84270e5730e643d099b46313e071a.tar.xz
Bug 287487: User with no privs can not add comments to bugs that have a deadline field set - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=myk
Diffstat (limited to 'Bugzilla/Util.pm')
-rw-r--r--Bugzilla/Util.pm73
1 files changed, 42 insertions, 31 deletions
diff --git a/Bugzilla/Util.pm b/Bugzilla/Util.pm
index 70b4c6845..ed415c7be 100644
--- a/Bugzilla/Util.pm
+++ b/Bugzilla/Util.pm
@@ -249,38 +249,44 @@ sub find_wrap_point ($$) {
return $wrappoint;
}
-sub format_time {
- my ($time) = @_;
-
- my ($year, $month, $day, $hour, $min, $sec);
- if ($time =~ m/^\d{14}$/) {
- # We appear to have a timestamp direct from MySQL
- $year = substr($time,0,4);
- $month = substr($time,4,2);
- $day = substr($time,6,2);
- $hour = substr($time,8,2);
- $min = substr($time,10,2);
- }
- elsif ($time =~ m/^(\d{4})[-\.](\d{2})[-\.](\d{2}) (\d{2}):(\d{2})(:(\d{2}))?$/) {
- $year = $1;
- $month = $2;
- $day = $3;
- $hour = $4;
- $min = $5;
- $sec = $7;
+sub format_time ($;$) {
+ my ($date, $format) = @_;
+
+ # If $format is undefined, try to guess the correct date format.
+ my $show_timezone;
+ if (!defined($format)) {
+ if ($date =~ m/^(\d{4})[-\.](\d{2})[-\.](\d{2}) (\d{2}):(\d{2})(:(\d{2}))?$/) {
+ my $sec = $7;
+ if (defined $sec) {
+ $format = "%Y-%m-%d %T";
+ } else {
+ $format = "%Y-%m-%d %R";
+ }
+ } else {
+ # Default date format. See Date::Format for other formats available.
+ $format = "%Y-%m-%d %R";
+ }
+ # By default, we want the timezone to be displayed.
+ $show_timezone = 1;
}
else {
- warn "Date/Time format ($time) unrecogonzied";
+ # Search for %Z or %z, meaning we want the timezone to be displayed.
+ # Till bug 182238 gets fixed, we assume Param('timezone') is used.
+ $show_timezone = ($format =~ s/\s?%Z$//i);
}
- if (defined $year) {
- $time = "$year-$month-$day $hour:$min";
- if (defined $sec) {
- $time .= ":$sec";
- }
- $time .= " " . &::Param('timezone') if &::Param('timezone');
+ # str2time($date) is undefined if $date has an invalid date format.
+ my $time = str2time($date);
+
+ if (defined $time) {
+ $date = time2str($format, $time);
+ $date .= " " . &::Param('timezone') if $show_timezone;
+ }
+ else {
+ # Don't let invalid (time) strings to be passed to templates!
+ $date = '';
}
- return $time;
+ return trim($date);
}
sub format_time_decimal {
@@ -531,10 +537,15 @@ The search starts at $maxpos and goes back to the beginning of the string.
=item C<format_time($time)>
-Takes a time and appends the timezone as defined in editparams.cgi. This routine
-will be expanded in the future to adjust for user preferences regarding what
-timezone to display times in. In the future, it may also allow for the time to be
-shown in different formats.
+Takes a time, converts it to the desired format and appends the timezone
+as defined in editparams.cgi, if desired. This routine will be expanded
+in the future to adjust for user preferences regarding what timezone to
+display times in.
+
+This routine is mainly called from templates to filter dates, see
+"FILTER time" in Templates.pm. In this case, $format is undefined and
+the routine has to "guess" the date format that was passed to $dbh->sql_date_format().
+
=item C<format_time_decimal($time)>