Bug 11244: notices ignoring the dateformat preference
authorJonathan Druart <jonathan.druart@biblibre.com>
Thu, 28 Nov 2013 14:01:55 +0000 (15:01 +0100)
committerTomas Cohen Arazi <tomascohen@gmail.com>
Wed, 20 Aug 2014 16:42:19 +0000 (13:42 -0300)
Overdue notices are using the MySQL date format and not the dateformat
in the system preferences.

Test Plan:
1) Enable checkout notices for a patron, make sure the date due is in
   the notice.
2) Check out an item to that patron, note the date is in the mysql
   datetime format
3) Apply this patch
4) Check out another item to the patron, not the date is now in the
   preferred date format.

Signed-off-by: David Cook <dcook@prosentient.com.au>
I love this patch! It is the best solution to this problem that I've
seen. I think it is set up to perfectly handle dates in the notices.

Unfortunately, the $dateonly flag is backwards, so the time is stripped
from timestamps and 00:00:00 is added to dates without times.

I'm adding a follow-up to reverse the setting of this flag.

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@gmail.com>
C4/Letters.pm

index 1d916e0..0ccbd3a 100644 (file)
@@ -620,6 +620,14 @@ sub _parseletter {
 
         $val = GetAuthorisedValueByCode ('ROADTYPE', $val, 0) if $table=~/^borrowers$/ && $field=~/^streettype$/;
         my $replacedby   = defined ($val) ? $val : '';
+        if ( $replacedby and $replacedby =~ m|^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}:\d{2})?$| ) {
+            # If the value is XXXX-YY-ZZ[ AA:BB:CC] we assume it is a date
+            my $dateonly = defined $1 ? 1 : 0;
+            eval {
+                $replacedby = output_pref({ dt => dt_from_string( $replacedby ), dateonly => $dateonly });
+            };
+            warn "$replacedby seems to be a date but an error occurs on generating it ($@)" if $@;
+        }
         ($letter->{title}  ) and do {
             $letter->{title}   =~ s/$replacetablefield/$replacedby/g;
             $letter->{title}   =~ s/$replacefield/$replacedby/g;