From 0cdae03f4029b3a66bda80f7d94fd3072c305db1 Mon Sep 17 00:00:00 2001
From: Bill Erickson <berick@esilibrary.com>
Date: Wed, 26 Dec 2012 11:10:23 -0500
Subject: [PATCH] SIP option to use SIP date format for due dates

New SIP configuration option "use_sip_date_format" which forces all SIP
dates to be formated using the SIP date format: YYYYMMDDZZZZHHMMSS

Without this setting, most dates already correctly use the SIP date
format.  However, for some historical reason, due dates are formatted as
ISO 8601 dates.  Enable this setting to force due dates to use the SIP
date format.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Signed-off-by: Jason Stephenson <jstephenson@mvlc.org>
---
 Open-ILS/examples/oils_sip.xml.example   |  8 ++++++++
 Open-ILS/src/perlmods/lib/OpenILS/SIP.pm | 17 ++++++++++++++---
 2 files changed, 22 insertions(+), 3 deletions(-)

diff --git a/Open-ILS/examples/oils_sip.xml.example b/Open-ILS/examples/oils_sip.xml.example
index 5d4ebd367a..8a1d7abdb0 100644
--- a/Open-ILS/examples/oils_sip.xml.example
+++ b/Open-ILS/examples/oils_sip.xml.example
@@ -103,6 +103,14 @@
 						If enabled, the PC field in patron-info requests will return the non-translated profile name
 					<option name='patron_type_uses_code' value='true' />
 					-->
+
+                    <!--
+                        By default, most dates use the SIP date format.  Some,
+                        like circulation due dates, use the ISO8601 date format 
+                        instead.  If this setting is set to true, all dates will
+                        use the SIP date format.
+                    <option name='use_sip_date_format' value='true' />
+                    -->
 				</options>
 
                 <checkin_override>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm
index 9722327908..a860910f49 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/SIP.pm
@@ -25,6 +25,8 @@ use OpenSRF::Utils qw/:datetime/;
 use DateTime::Format::ISO8601;
 use Encode;
 use Unicode::Normalize;
+use Sip::Constants qw(SIP_DATETIME);
+
 my $U = 'OpenILS::Application::AppUtils';
 
 my $editor;
@@ -178,9 +180,9 @@ sub format_date {
 
     return "" unless $date;
 
-    $date = DateTime::Format::ISO8601->new->
+    my $dt = DateTime::Format::ISO8601->new->
         parse_datetime(OpenSRF::Utils::cleanse_ISO8601($date));
-    my @time = localtime($date->epoch);
+    my @time = localtime($dt->epoch);
 
     my $year   = $time[5]+1900;
     my $mon    = $time[4]+1;
@@ -193,7 +195,16 @@ sub format_date {
 
     # Due dates need hyphen separators and time of day as well
     if ($type eq 'due') {
-        $date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", $year, $mon, $day, $hour, $minute, $second);
+
+        my $use_sdf = $class->get_option_value('use_sip_date_format') | '';
+
+        if ($use_sdf =~ /true/i) {
+            $date = $dt->strftime(SIP_DATETIME);
+
+        } else {
+            $date = sprintf("%04d-%02d-%02d %02d:%02d:%02d", 
+                $year, $mon, $day, $hour, $minute, $second);
+        }
     }
 
     syslog('LOG_DEBUG', "OILS: formatted date [type=$type]: $date");
-- 
2.11.0