View | Details | Raw Unified | Return to bug 9014
Collapse All | Expand All

(-)a/C4/Letters.pm (-2 / +2 lines)
Lines 29-34 use C4::Branch; Link Here
29
use C4::Log;
29
use C4::Log;
30
use C4::SMS;
30
use C4::SMS;
31
use C4::Debug;
31
use C4::Debug;
32
use Koha::DateUtils;
32
use Date::Calc qw( Add_Delta_Days );
33
use Date::Calc qw( Add_Delta_Days );
33
use Encode;
34
use Encode;
34
use Carp;
35
use Carp;
Lines 614-621 sub _parseletter { Link Here
614
    }
615
    }
615
616
616
    if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
617
    if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
617
        my @da = localtime();
618
        my $todaysdate = output_pref( DateTime->now() );
618
        my $todaysdate = "$da[2]:$da[1]  " . C4::Dates->today();
619
        $letter->{content} =~ s/<<today>>/$todaysdate/go;
619
        $letter->{content} =~ s/<<today>>/$todaysdate/go;
620
    }
620
    }
621
621
(-)a/C4/Members.pm (-2 / +2 lines)
Lines 2318-2325 sub IssueSlip { Link Here
2318
        elsif ((substr $it->{'date_due'}, 0, 10) le $now) {
2318
        elsif ((substr $it->{'date_due'}, 0, 10) le $now) {
2319
            $it->{'overdue'} = 1;
2319
            $it->{'overdue'} = 1;
2320
        }
2320
        }
2321
2321
        my $dt = dt_from_string( $it->{'date_due'} );
2322
        $it->{'date_due'}=format_date($it->{'date_due'});
2322
        $it->{'date_due'} = output_pref( $dt );;
2323
    }
2323
    }
2324
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
2324
    my @issues = sort { $b->{'timestamp'} <=> $a->{'timestamp'} } @$issueslist;
2325
2325
(-)a/Koha/DateUtils.pm (-12 / +26 lines)
Lines 93-99 s/(\d{4})(\d{2})(\d{2})\s+(\d{2})(\d{2})(\d{2})/$1-$2-$3T$4:$5:$6/; Link Here
93
93
94
=head2 output_pref
94
=head2 output_pref
95
95
96
$date_string = output_pref($dt, [$format] );
96
$date_string = output_pref($dt, [$date_format], [$time_format] );
97
97
98
Returns a string containing the time & date formatted as per the C4::Context setting,
98
Returns a string containing the time & date formatted as per the C4::Context setting,
99
or C<undef> if C<undef> was provided.
99
or C<undef> if C<undef> was provided.
Lines 101-107 or C<undef> if C<undef> was provided. Link Here
101
A second parameter allows overriding of the syspref value. This is for testing only
101
A second parameter allows overriding of the syspref value. This is for testing only
102
In usage use the DateTime objects own methods for non standard formatting
102
In usage use the DateTime objects own methods for non standard formatting
103
103
104
A third parameter allows to specify if the output format contains the hours and minutes.
104
A third parameter allows overriding of the TimeFormat syspref value
105
106
A fourth parameter allows to specify if the output format contains the hours and minutes.
105
If it is not defined, the default value is 0;
107
If it is not defined, the default value is 0;
106
108
107
=cut
109
=cut
Lines 109-140 If it is not defined, the default value is 0; Link Here
109
sub output_pref {
111
sub output_pref {
110
    my $dt         = shift;
112
    my $dt         = shift;
111
    my $force_pref = shift;         # if testing we want to override Context
113
    my $force_pref = shift;         # if testing we want to override Context
114
    my $force_time = shift;
112
    my $dateonly   = shift || 0;    # if you don't want the hours and minutes
115
    my $dateonly   = shift || 0;    # if you don't want the hours and minutes
113
116
114
    return unless defined $dt;
117
    return unless defined $dt;
115
118
116
    my $pref =
119
    my $pref =
117
      defined $force_pref ? $force_pref : C4::Context->preference('dateformat');
120
      defined $force_pref ? $force_pref : C4::Context->preference('dateformat');
121
122
    my $time_format = $force_time || C4::Context->preference('TimeFormat');
123
    my $time = ( $time_format eq '12hr' ) ? '%I:%M %p' : '%H:%M';
124
118
    given ($pref) {
125
    given ($pref) {
119
        when (/^iso/) {
126
        when (/^iso/) {
120
            return $dateonly
127
            return $dateonly
121
                ? $dt->strftime('%Y-%m-%d')
128
                ? $dt->strftime("%Y-%m-%d")
122
                : $dt->strftime('%Y-%m-%d %H:%M');
129
                : $dt->strftime("%Y-%m-%d $time");
123
        }
130
        }
124
        when (/^metric/) {
131
        when (/^metric/) {
125
            return $dateonly
132
            return $dateonly
126
                ? $dt->strftime('%d/%m/%Y')
133
                ? $dt->strftime("%d/%m/%Y")
127
                : $dt->strftime('%d/%m/%Y %H:%M');
134
                : $dt->strftime("%d/%m/%Y $time");
128
        }
135
        }
129
        when (/^us/) {
136
        when (/^us/) {
137
130
            return $dateonly
138
            return $dateonly
131
                ? $dt->strftime('%m/%d/%Y')
139
                ? $dt->strftime("%m/%d/%Y")
132
                : $dt->strftime('%m/%d/%Y %H:%M');
140
                : $dt->strftime("%m/%d/%Y $time");
133
        }
141
        }
134
        default {
142
        default {
135
            return $dateonly
143
            return $dateonly
136
                ? $dt->strftime('%Y-%m-%d')
144
                ? $dt->strftime("%Y-%m-%d")
137
                : $dt->strftime('%Y-%m-%d %H:%M');
145
                : $dt->strftime("%Y-%m-%d $time");
138
        }
146
        }
139
147
140
    }
148
    }
Lines 173-183 with output_pref as it is a frequent activity in scripts Link Here
173
sub format_sqldatetime {
181
sub format_sqldatetime {
174
    my $str        = shift;
182
    my $str        = shift;
175
    my $force_pref = shift;    # if testing we want to override Context
183
    my $force_pref = shift;    # if testing we want to override Context
184
    my $force_time = shift;
185
    my $dateonly   = shift;
186
176
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
187
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
177
        my $dt = dt_from_string( $str, 'sql' );
188
        my $dt = dt_from_string( $str, 'sql' );
178
        return q{} unless $dt;
189
        return q{} unless $dt;
179
        $dt->truncate( to => 'minute' );
190
        $dt->truncate( to => 'minute' );
180
        return output_pref( $dt, $force_pref );
191
        return output_pref( $dt, $force_pref, $force_time, $dateonly );
181
    }
192
    }
182
    return q{};
193
    return q{};
183
}
194
}
Lines 194-203 with output_pref_due as it is a frequent activity in scripts Link Here
194
sub format_sqlduedatetime {
205
sub format_sqlduedatetime {
195
    my $str        = shift;
206
    my $str        = shift;
196
    my $force_pref = shift;    # if testing we want to override Context
207
    my $force_pref = shift;    # if testing we want to override Context
208
    my $force_time = shift;
209
    my $dateonly   = shift;
210
197
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
211
    if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
198
        my $dt = dt_from_string( $str, 'sql' );
212
        my $dt = dt_from_string( $str, 'sql' );
199
        $dt->truncate( to => 'minute' );
213
        $dt->truncate( to => 'minute' );
200
        return output_pref_due( $dt, $force_pref );
214
        return output_pref_due( $dt, $force_pref, $force_time, $dateonly );
201
    }
215
    }
202
    return q{};
216
    return q{};
203
}
217
}
(-)a/acqui/lateorders.pl (-2 / +2 lines)
Lines 86-95 my $estimateddeliverydateto_dt = $estimateddeliverydateto Link Here
86
86
87
# Format the output of "date from" and "date to"
87
# Format the output of "date from" and "date to"
88
if ($estimateddeliverydatefrom_dt) {
88
if ($estimateddeliverydatefrom_dt) {
89
    $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, 1);
89
    $estimateddeliverydatefrom = output_pref($estimateddeliverydatefrom_dt, undef, undef, 1);
90
}
90
}
91
if ($estimateddeliverydateto_dt) {
91
if ($estimateddeliverydateto_dt) {
92
    $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, 1);
92
    $estimateddeliverydateto = output_pref($estimateddeliverydateto_dt, undef, undef, 1);
93
}
93
}
94
94
95
my $branch     = $input->param('branch');
95
my $branch     = $input->param('branch');
(-)a/installer/data/mysql/sysprefs.sql (+1 lines)
Lines 406-408 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES(' Link Here
406
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free');
406
INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('NotesBlacklist','','List of notes fields that should not appear in the title notes/description separator of details',NULL,'free');
407
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free');
407
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserCSS', '', NULL, 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free');
408
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserJS', '', NULL, 'Define custom javascript for inclusion in the SCO module', 'free');
408
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('SCOUserJS', '', NULL, 'Define custom javascript for inclusion in the SCO module', 'free');
409
INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('TimeFormat','24hr','12hr|24hr','Defines the global time format for visual output.','Choice');
(-)a/installer/data/mysql/updatedatabase.pl (+6 lines)
Lines 6336-6341 if ( CheckVersion($DBversion) ) { Link Here
6336
   $dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserCSS', '', 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free' )");
6336
   $dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserCSS', '', 'Add CSS to be included in the SCO module in an embedded <style> tag.', 'free' )");
6337
   $dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserJS', '', 'Define custom javascript for inclusion in the SCO module', 'free' )");
6337
   $dbh->do("INSERT INTO systempreferences ( variable, value, explanation, type ) VALUES ( 'SCOUserJS', '', 'Define custom javascript for inclusion in the SCO module', 'free' )");
6338
   print "Upgrade to $DBversion done (Bug 9009: Add SCOUserCSS and SCOUserJS sysprefs)\n";
6338
   print "Upgrade to $DBversion done (Bug 9009: Add SCOUserCSS and SCOUserJS sysprefs)\n";
6339
}
6340
6341
$DBversion = "3.11.00.XXX";
6342
if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
6343
   $dbh->do("INSERT INTO systempreferences (variable,value,options,explanation,type) VALUES ('TimeFormat','24hr','12hr|24hr','Defines the global time format for visual output.','Choice')");
6344
   print "Upgrade to $DBversion done (Bug 9014: Add syspref TimeFormat)\n";
6339
   SetVersion ($DBversion);
6345
   SetVersion ($DBversion);
6340
}
6346
}
6341
6347
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/i18n_l10n.pref (+8 lines)
Lines 9-14 I18N/L10N: Link Here
9
              iso: yyyy-mm-dd
9
              iso: yyyy-mm-dd
10
        - .
10
        - .
11
    -
11
    -
12
        - Format times in
13
        - pref: TimeFormat
14
          default: 24hr
15
          choices:
16
              24hr: 24 hour format ( e.g. "14:18" )
17
              12hr: 12 hour format ( e.g. "02:18 PM" )
18
        - .
19
    -
12
        - Use
20
        - Use
13
        - pref: CalendarFirstDayOfWeek
21
        - pref: CalendarFirstDayOfWeek
14
          default: Sunday
22
          default: Sunday
(-)a/t/DateUtils.t (-13 / +18 lines)
Lines 5-11 use DateTime; Link Here
5
use DateTime::TimeZone;
5
use DateTime::TimeZone;
6
6
7
use C4::Context;
7
use C4::Context;
8
use Test::More tests => 28;
8
use Test::More tests => 30;
9
9
10
BEGIN { use_ok('Koha::DateUtils'); }
10
BEGIN { use_ok('Koha::DateUtils'); }
11
11
Lines 23-54 cmp_ok( $dt->ymd(), 'eq', $testdate_iso, 'Returned object matches input' ); Link Here
23
$dt->set_hour(12);
23
$dt->set_hour(12);
24
$dt->set_minute(0);
24
$dt->set_minute(0);
25
25
26
my $date_string = output_pref( $dt, 'iso' );
26
my $date_string = output_pref( $dt, 'iso', '24hr' );
27
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
27
cmp_ok $date_string, 'eq', '2011-06-16 12:00', 'iso output';
28
28
29
my $date_string = output_pref( $dt, 'iso',1 );
29
my $date_string = output_pref( $dt, 'iso', '12hr' );
30
cmp_ok $date_string, 'eq', '2011-06-16 12:00 PM', 'iso output 12hr';
31
32
$date_string = output_pref( $dt, 'iso', undef, 1 );
30
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
33
cmp_ok $date_string, 'eq', '2011-06-16', 'iso output (date only)';
31
34
32
$date_string = output_pref( $dt, 'us' );
35
$date_string = output_pref( $dt, 'us', '24hr' );
33
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
36
cmp_ok $date_string, 'eq', '06/16/2011 12:00', 'us output';
34
37
35
$date_string = output_pref( $dt, 'us', 1 );
38
$date_string = output_pref( $dt, 'us', '12hr' );
39
cmp_ok $date_string, 'eq', '06/16/2011 12:00 PM', 'us output 12hr';
40
41
$date_string = output_pref( $dt, 'us', undef, 1 );
36
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)';
42
cmp_ok $date_string, 'eq', '06/16/2011', 'us output (date only)';
37
43
38
# metric should return the French Revolutionary Calendar Really
44
# metric should return the French Revolutionary Calendar Really
39
$date_string = output_pref( $dt, 'metric' );
45
$date_string = output_pref( $dt, 'metric', '24hr' );
40
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
46
cmp_ok $date_string, 'eq', '16/06/2011 12:00', 'metric output';
41
47
42
$date_string = output_pref( $dt, 'metric',1 );
48
$date_string = output_pref( $dt, 'metric', undef, 1 );
43
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
49
cmp_ok $date_string, 'eq', '16/06/2011', 'metric output (date only)';
44
50
45
$date_string = output_pref_due( $dt, 'metric' );
51
$date_string = output_pref_due( $dt, 'metric', '24hr' );
46
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
52
cmp_ok $date_string, 'eq', '16/06/2011 12:00',
47
  'output_pref_due preserves non midnight HH:SS';
53
  'output_pref_due preserves non midnight HH:SS';
48
54
49
$dt->set_hour(23);
55
$dt->set_hour(23);
50
$dt->set_minute(59);
56
$dt->set_minute(59);
51
$date_string = output_pref_due( $dt, 'metric' );
57
$date_string = output_pref_due( $dt, 'metric', '24hr' );
52
cmp_ok $date_string, 'eq', '16/06/2011',
58
cmp_ok $date_string, 'eq', '16/06/2011',
53
  'output_pref_due truncates HH:SS at midnight';
59
  'output_pref_due truncates HH:SS at midnight';
54
60
Lines 87-106 cmp_ok( $dt0->ymd(), 'eq', $ymd, 'Returned object corrects iso day 0' ); Link Here
87
$dt0 = dt_from_string( '0000-00-00', 'iso' );
93
$dt0 = dt_from_string( '0000-00-00', 'iso' );
88
is( $dt0, undef, "undefined returned for 0 iso date" );
94
is( $dt0, undef, "undefined returned for 0 iso date" );
89
95
90
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric' );
96
my $formatted = format_sqldatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
91
cmp_ok( $formatted, 'eq', '16/06/2011 12:00', 'format_sqldatetime conversion' );
97
cmp_ok( $formatted, 'eq', '16/06/2011 12:00', 'format_sqldatetime conversion' );
92
98
93
$formatted = format_sqldatetime( undef, 'metric' );
99
$formatted = format_sqldatetime( undef, 'metric' );
94
cmp_ok( $formatted, 'eq', q{},
100
cmp_ok( $formatted, 'eq', q{},
95
    'format_sqldatetime formats undef as empty string' );
101
    'format_sqldatetime formats undef as empty string' );
96
102
97
$formatted = format_sqlduedatetime( '2011-06-16 12:00:07', 'metric' );
103
$formatted = format_sqlduedatetime( '2011-06-16 12:00:07', 'metric', '24hr' );
98
cmp_ok(
104
cmp_ok(
99
    $formatted, 'eq',
105
    $formatted, 'eq',
100
    '16/06/2011 12:00',
106
    '16/06/2011 12:00',
101
    'format_sqlduedatetime conversion for hourly loans'
107
    'format_sqlduedatetime conversion for hourly loans'
102
);
108
);
103
109
104
$formatted = format_sqlduedatetime( '2011-06-16 23:59:07', 'metric' );
110
$formatted = format_sqlduedatetime( '2011-06-16 23:59:07', 'metric', '24hr' );
105
cmp_ok( $formatted, 'eq', '16/06/2011',
111
cmp_ok( $formatted, 'eq', '16/06/2011',
106
    'format_sqlduedatetime conversion for daily loans' );
112
    'format_sqlduedatetime conversion for daily loans' );
107
- 

Return to bug 9014