Bugzilla – Attachment 37088 Details for
Bug 13601
Get rid of DateTime::Format::DateParse
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 13601: Make dt_from_string not using DateTime::Format::DateParse
PASSED-QA-Bug-13601-Make-dtfromstring-not-using-Da.patch (text/plain), 6.28 KB, created by
Katrin Fischer
on 2015-03-22 19:57:02 UTC
(
hide
)
Description:
[PASSED QA] Bug 13601: Make dt_from_string not using DateTime::Format::DateParse
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2015-03-22 19:57:02 UTC
Size:
6.28 KB
patch
obsolete
>From f5c2125304b3e4b74ce247c06ad0acb0102956aa Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@biblibre.com> >Date: Tue, 20 Jan 2015 15:28:56 +0100 >Subject: [PATCH] [PASSED QA] Bug 13601: Make dt_from_string not using > DateTime::Format::DateParse >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >For a couple of reasons, dt_from_string should not use >DateTime::Format::DateParse: >1/ It does not manage date < 1900, certainly caused by l.47 of this >module: > $p{ year } = $year ? $year + 1900 : DateTime->now->year; > >2/ It considers 31/01/2015 as a valid us date, which is not. > >Test plan: >1/ Verify that > prove t/DateUtils.t >returns green >2/ Play with dates in Koha (yes I know, it's vague...) >3/ Try to find a regression with dates >4/ Create a date with year <= 1900 and confirm it works > >QA comment: >Why the sql format switch was: >- $date_string =~ >-s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/; > >From where a date like "yyyymmdd hhmmss" can come? > >Tested patches 1 - 3 together. Worked as expected. >Signed-off-by: Marc Véron <veron@veron.ch> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > Koha/DateUtils.pm | 145 ++++++++++++++++++++++++++++++++++++------------------ > 1 file changed, 97 insertions(+), 48 deletions(-) > >diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm >index 61877b9..0a5e15a 100644 >--- a/Koha/DateUtils.pm >+++ b/Koha/DateUtils.pm >@@ -20,7 +20,6 @@ use strict; > use warnings; > use 5.010; > use DateTime; >-use DateTime::Format::DateParse; > use C4::Context; > > use base 'Exporter'; >@@ -54,56 +53,106 @@ to the system preferences. If the date string is empty DateTime->now is returned > sub dt_from_string { > my ( $date_string, $date_format, $tz ) = @_; > >- # FIXME: see bug 13242 => no TZ for dates 'infinite' >- return DateTime::Format::DateParse->parse_datetime($date_string) >- if $date_string and $date_string =~ /^9999-/; >- >- my $dt; >- $tz ||= C4::Context->tz; >- if ( !$date_format ) { >- $date_format = C4::Context->preference('dateformat'); >- } >- if ($date_string) { >- if ( ref($date_string) eq 'DateTime' ) { # already a dt return it >- return $date_string; >- } >- >- if ( $date_format eq 'metric' ) { >- $date_string =~ s#-#/#g; >- $date_string =~ s/^00/01/; # system allows the 0th of the month >- $date_string =~ s#^(\d{1,2})/(\d{1,2})#$2/$1#; >- } else { >- if ( $date_format eq 'iso' ) { >- $date_string =~ s/-00/-01/; >- if ( $date_string =~ m/^0000-0/ ) { >- return; # invalid date in db >- } >- } elsif ( $date_format eq 'us' ) { >- $date_string =~ s#-#/#g; >- $date_string =~ s[/00/][/01/]; >- } elsif ( $date_format eq 'sql' ) { >- $date_string =~ >-s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/; >- return if ($date_string =~ /^0000-00-00/); >- $date_string =~ s/00T/01T/; >- } >- } >- >- $dt = eval { >- DateTime::Format::DateParse->parse_datetime( $date_string, >- $tz->name() ); >- }; >- if ($@) { >- $tz = DateTime::TimeZone->new( name => 'floating' ); >- $dt = DateTime::Format::DateParse->parse_datetime( $date_string, >- $tz->name() ); >- } >- } else { >- $dt = DateTime->now( time_zone => $tz ); >+ return if $date_string and $date_string =~ m|^0000-0|; >+ >+ $tz = C4::Context->tz unless $tz;; >+ >+ return DateTime->now( time_zone => $tz ) unless $date_string; >+ >+ $date_format = C4::Context->preference('dateformat') unless $date_format; >+ >+ if ( ref($date_string) eq 'DateTime' ) { # already a dt return it >+ return $date_string; > } > >- return $dt; >+ my $regex; >+ if ( $date_format eq 'metric' ) { >+ # metric format is "dd/mm/yyyy[ hh:mm:ss]" >+ $regex = qr| >+ (?<day>\d{2}) >+ / >+ (?<month>\d{2}) >+ / >+ (?<year>\d{4}) >+ |xms; >+ } >+ elsif ( $date_format eq 'us' ) { >+ # us format is "mm/dd/yyyy[ hh:mm:ss]" >+ $regex = qr| >+ (?<month>\d{2}) >+ / >+ (?<day>\d{2}) >+ / >+ (?<year>\d{4}) >+ |xms; >+ } >+ elsif ( $date_format eq 'iso' or $date_format eq 'sql' ) { >+ # iso format is yyyy-dd-mm[ hh:mm:ss]" >+ $regex = qr| >+ (?<year>\d{4}) >+ - >+ (?<month>\d{2}) >+ - >+ (?<day>\d{2}) >+ |xms; >+ } >+ else { >+ die "Invalid dateformat parameter ($date_format)"; >+ } > >+ # Add the faculative time part [hh:mm[:ss]] >+ $regex .= qr| >+ ( >+ \s* >+ (?<hour>\d{2}) >+ : >+ (?<minute>\d{2}) >+ ( >+ : >+ (?<second>\d{2}) >+ )? >+ )? >+ |xms; >+ >+ my %dt_params; >+ if ( $date_string =~ $regex ) { >+ %dt_params = ( >+ year => $+{year}, >+ month => $+{month}, >+ day => $+{day}, >+ hour => $+{hour}, >+ minute => $+{minute}, >+ second => $+{second}, >+ ); >+ } >+ else { >+ die "The given date ($date_string) does not match the date format ($date_format)"; >+ } >+ >+ # system allows the 0th of the month >+ $dt_params{day} = '01' if $dt_params{day} eq '00'; >+ >+ # Set default hh:mm:ss to 00:00:00 >+ $dt_params{hour} = 00 unless defined $dt_params{hour}; >+ $dt_params{minute} = 00 unless defined $dt_params{minute}; >+ $dt_params{second} = 00 unless defined $dt_params{second}; >+ >+ my $dt = eval { >+ DateTime->new( >+ %dt_params, >+ # No TZ for dates 'infinite' => see bug 13242 >+ ( $dt_params{year} < 9999 ? ( time_zone => $tz->name ) : () ), >+ ); >+ }; >+ if ($@) { >+ $tz = DateTime::TimeZone->new( name => 'floating' ); >+ $dt = DateTime->new( >+ %dt_params, >+ # No TZ for dates 'infinite' => see bug 13242 >+ ( $dt_params{year} < 9999 ? ( time_zone => $tz->name ) : () ), >+ ); >+ } >+ return $dt; > } > > =head2 output_pref >-- >1.9.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 13601
:
35405
|
35406
|
35407
|
35408
|
35433
|
36733
|
36734
|
36735
|
36736
|
36737
|
36745
|
36746
|
36747
|
36748
|
36754
|
36755
|
36756
|
36928
|
36933
|
36939
|
37023
|
37087
| 37088 |
37089
|
37090
|
37091
|
37092
|
37093