Bug 12072: Add system preference for New dateformat dd.mm.yyyy (dmydot)
authorMarc Véron <veron@veron.ch>
Sat, 7 Mar 2015 07:38:04 +0000 (08:38 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 19 Nov 2015 16:12:00 +0000 (13:12 -0300)
Note: This feature depends on Bug 14870 'Delete C4/Dates from system'

System preferences:
To test:
- apply the patch
- run updatedatabase.pl
- go to Admin > Sysprefs > I18N, change dateformat to dd.mm.yyyy, save
- verify that the value was saved

Date handling:
- go through the staff client and verify that dates behave as expected.
- go through Opac and verify that dates behave as expected.

  The Bugs where Bug 14870 depends on contain test plans that can be
  used for the overall testing.

Note: Make sure that you reset the dateformat to the former value after
      testing.

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Works as expected

Amended to apply on top of Bug 15166 11.11.2015/mv

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/DateUtils.pm
installer/data/mysql/atomicupdate/bug_12072_update_syspref_dateformat.sql [new file with mode: 0644]
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref
t/DateUtils.t

index e2e8cfc..65afaea 100644 (file)
@@ -85,6 +85,16 @@ sub dt_from_string {
             (?<year>\d{4})
         |xms;
     }
+    elsif ( $date_format eq 'dmydot' ) {
+        # dmydot 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|
@@ -231,6 +241,12 @@ sub output_pref {
           ? $dt->strftime("%d/%m/%Y")
           : $dt->strftime("%d/%m/%Y $time");
     }
+    elsif ( $pref =~ m/^dmydot/ ) {
+        $date = $dateonly
+          ? $dt->strftime("%d.%m.%Y")
+          : $dt->strftime("%d.%m.%Y $time");
+    }
+
     elsif ( $pref =~ m/^us/ ) {
         $date = $dateonly
           ? $dt->strftime("%m/%d/%Y")
diff --git a/installer/data/mysql/atomicupdate/bug_12072_update_syspref_dateformat.sql b/installer/data/mysql/atomicupdate/bug_12072_update_syspref_dateformat.sql
new file mode 100644 (file)
index 0000000..b5f96c9
--- /dev/null
@@ -0,0 +1 @@
+UPDATE systempreferences SET options = 'metric|us|iso|dmydot', explanation = 'Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd, DMY separated by dots dd.mm.yyyy)' WHERE variable = 'dateformat'
index 60b776a..484b3cd 100644 (file)
@@ -99,7 +99,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `
 ('ConsiderOnSiteCheckoutsAsNormalCheckouts','1',NULL,'Consider on-site checkouts as normal checkouts','YesNo'),
 ('CronjobLog','0',NULL,'If ON, log information from cron jobs.','YesNo'),
 ('CurrencyFormat','US','US|FR','Determines the display format of currencies. eg: \'36000\' is displayed as \'360 000,00\'  in \'FR\' or \'360,000.00\'  in \'US\'.','Choice'),
-('dateformat','us','metric|us|iso','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd)','Choice'),
+('dateformat','us','metric|us|iso|dmydot','Define global date format (us mm/dd/yyyy, metric dd/mm/yyy, ISO yyyy-mm-dd, dmydot dd.mm.yyyy)','Choice'),
 ('DebugLevel','2','0|1|2','Define the level of debugging information sent to the browser when errors are encountered (set to 0 in production). 0=none, 1=some, 2=most','Choice'),
 ('decreaseLoanHighHolds',NULL,'','Decreases the loan period for items with number of holds above the threshold specified in decreaseLoanHighHoldsValue','YesNo'),
 ('decreaseLoanHighHoldsDuration',NULL,'','Specifies a number of days that a loan is reduced to when used in conjunction with decreaseLoanHighHolds','Integer'),
index 6bf9793..89e4436 100644 (file)
@@ -6,6 +6,7 @@ I18N/L10N:
           choices:
               us: mm/dd/yyyy
               metric: dd/mm/yyyy
+              dmydot: dd.mm.yyyy
               iso: yyyy-mm-dd
         - . <b>Note:</b> Do not change this preference on a production server with overdue items that are accruing fines. Doing so will result in duplicate fines!
     -
index 92f8777..b82ed02 100755 (executable)
@@ -3,7 +3,9 @@ use DateTime;
 use DateTime::TimeZone;
 
 use C4::Context;
-use Test::More tests => 59;
+
+use Test::More tests => 60;
+
 use Test::MockModule;
 use Test::Warn;
 use Time::HiRes qw/ gettimeofday /;
@@ -195,6 +197,8 @@ $dt = eval { dt_from_string( '31/01/2015', 'us' ); };
 is( ref($dt), '', '31/01/2015 is not a correct date in us format' );
 $dt = dt_from_string( '01/01/2015', 'us' );
 is( ref($dt), 'DateTime', '01/01/2015 is a correct date in us format' );
+$dt = dt_from_string( '01.01.2015', 'dmydot' );
+is( ref($dt), 'DateTime', '01.01.2015 is a correct date in dmydot format' );
 
 
 # default value for hh and mm is 00:00