Use the 'format.time' OUS to format library hours
authorDan Scott <dscott@laurentian.ca>
Mon, 6 Jan 2014 17:22:28 +0000 (12:22 -0500)
committerDan Wells <dbw2@calvin.edu>
Tue, 21 Jan 2014 19:57:42 +0000 (14:57 -0500)
Sparked by a concern that Ben Shum had over the display of library hours in 24
hour format, I eventually figured out that we could use the Template::Toolkit
Date module to format the times according to library preferences. And given
that we already have a format.time OUS, let's use it.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/templates/opac/parts/library/hours.tt2

index 37513b1..823701c 100644 (file)
@@ -1,57 +1,67 @@
+[% time_format = ctx.get_org_setting(ctx.library.id, 'format.time');
+
+   UNLESS time_fmt;
+       time_format = '%H:%M %p';
+   END;
+
+   USE date (format = time_format);
+   today = date.format(format = '%Y-%d-%b ');
+   # We need to add "today" to the opening/closing hours for Date input
+-%]
 <h2>[% l('Opening hours') %]</h2>
 [%- IF ctx.hours.dow_0_open == ctx.hours.dow_0_close; %]
 <div class="opening-hours">[% l('Monday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Monday" />[%
-    l('Monday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_0_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_0_close.substr(0, 5) _ '</span>') -%]
+    l('Monday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_0_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_0_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_1_open == ctx.hours.dow_1_close; %]
 <div class="opening-hours">[% l('Tuesday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Tuesday" />[%
-    l('Tuesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_1_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_1_close.substr(0, 5) _ '</span>') -%]
+    l('Tuesday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_1_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_1_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_2_open == ctx.hours.dow_2_close; %]
 <div class="opening-hours">[% l('Wednesday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Wednesday" />[%
-    l('Wednesday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_2_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_2_close.substr(0, 5) _ '</span>') -%]
+    l('Wednesday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_2_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_2_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_3_open == ctx.hours.dow_3_close; %]
 <div class="opening-hours">[% l('Thursday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Thursday" />[%
-    l('Thursday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_3_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_3_close.substr(0, 5) _ '</span>') -%]
+    l('Thursday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_3_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_3_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_4_open == ctx.hours.dow_4_close; %]
 <div class="opening-hours">[% l('Friday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Friday" />[%
-    l('Friday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_4_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_4_close.substr(0, 5) _ '</span>') -%]
+    l('Friday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_4_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_4_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_5_open == ctx.hours.dow_5_close; %]
 <div class="opening-hours">[% l('Saturday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Saturday" />[%
-    l('Saturday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_5_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_5_close.substr(0, 5) _ '</span>') -%]
+    l('Saturday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_5_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_5_close) _ '</span>') -%]
 </div>
 [%- END %]
 [%- IF ctx.hours.dow_6_open == ctx.hours.dow_6_close; %]
 <div class="opening-hours">[% l('Sunday: closed') %]</div>
 [%- ELSE %]
 <div class="opening-hours" property="openingHoursSpecification" typeof="OpeningHoursSpecification"><link property="dayOfWeek" href="http://purl.org/goodrelations/v1#Sunday" />[%
-    l('Sunday: [_1]-[_2]', '<span property="opens">' _ ctx.hours.dow_6_open.substr(0, 5) _ '</span>',
-     '<span property="closes">' _ ctx.hours.dow_6_close.substr(0, 5) _ '</span>') -%]
+    l('Sunday: [_1] - [_2]', '<span property="opens">' _ date.format(today _ ctx.hours.dow_6_open) _ '</span>',
+     '<span property="closes">' _ date.format(today _ ctx.hours.dow_6_close) _ '</span>') -%]
 </div>
 [%- END %]