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

(-)a/Koha/Template/Plugin/KohaDates.pm (+5 lines)
Lines 23-28 use Template::Plugin::Filter; Link Here
23
use base qw( Template::Plugin::Filter );
23
use base qw( Template::Plugin::Filter );
24
24
25
use Koha::DateUtils;
25
use Koha::DateUtils;
26
use C4::Context;
26
our $DYNAMIC = 1;
27
our $DYNAMIC = 1;
27
28
28
sub filter {
29
sub filter {
Lines 42-45 sub output_preference { Link Here
42
    return output_pref( @params );
43
    return output_pref( @params );
43
}
44
}
44
45
46
sub tz {
47
    return C4::Context->tz->name;
48
}
49
45
1;
50
1;
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/js-date-format.inc (+62 lines)
Line 0 Link Here
1
[% USE Koha %]
2
[% USE raw %]
3
[% USE Asset %]
4
[% USE KohaDates %]
5
[% Asset.js("lib/moment/moment.min.js") | $raw %]
6
[% Asset.js("lib/moment/moment-timezone-with-data-10-year-range.min.js") | $raw %]
7
<script>
8
    (function() {
9
        var def_date_format = '[% Koha.Preference('dateformat') | html %]';
10
        var def_time_format = '[% Koha.Preference('TimeFormat') | html %]';
11
        var def_tz = '[% KohaDates.tz | html %]';
12
13
        var get_date_pattern = function(format) {
14
            var date_pattern = 'YYYY-MM-DD';
15
            if(format == 'us') date_pattern = 'MM/DD/YYYY';
16
            if(format == 'metric') date_pattern = 'DD/MM/YYYY';
17
            if(format == 'dmydot') date_pattern = 'DD.MM.YYYY';
18
            return date_pattern;
19
        };
20
21
        var get_time_pattern = function(format) {
22
            var time_pattern = 'HH:mm';
23
            if(format == '12hr') time_pattern = 'hh:mm a';
24
            return time_pattern;
25
        };
26
27
        window.$date = function(value, options) {
28
            var tz = (opitons&&options.tz)||def_tz;
29
            var m = moment(value);
30
            if(tz) m.tz(tz);
31
32
            var dateformat = (options&&options.dateformat)||def_date_format;
33
            var withtime = (options&&options.withtime)||false;
34
35
            if(dateformat=='rfc3339' && withtime) return m.format();
36
            
37
            var timeformat = (options&&options.timeformat)||def_time_format;
38
            var date_pattern = get_date_pattern(dateformat);
39
            var time_pattern = !withtime?'':' '+get_time_pattern(timeformat);
40
            
41
            return m.format(date_pattern+time_pattern);
42
        }
43
44
        window.$datetime = function(value, options) {
45
            options = options||{};
46
            options.withtime = true;
47
            return $date(value, options);
48
        };
49
50
        window.$time = function(value, options) {
51
            var tz = (opitons&&options.tz)||def_tz;
52
            var m = moment(value);
53
            if(tz) m.tz(tz);
54
55
            var dateformat = (options&&options.dateformat);
56
            var timeformat = (dateformat=='rfc3339'&&'24hr')||(options&&options.timeformat)||def_time_format;
57
58
            return m.format(get_time_pattern(timeformat)+(dateformat=='rfc3339'?':ss'+(!m.isUTC()?'Z':''):''))+(dateformat=='rfc3339' && m.isUTC()?'Z':'');
59
        }
60
61
    })();
62
</script>
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/js-date-format.inc (-1 / +62 lines)
Line 0 Link Here
0
- 
1
[% USE Koha %]
2
[% USE raw %]
3
[% USE Asset %]
4
[% USE KohaDates %]
5
[% Asset.js("lib/moment.min.js") | $raw %]
6
[% Asset.js("lib/moment-timezone-with-data-10-year-range.min.js") | $raw %]
7
<script>
8
    (function() {
9
        var def_date_format = '[% Koha.Preference('dateformat') | html %]';
10
        var def_time_format = '[% Koha.Preference('TimeFormat') | html %]';
11
        var def_tz = '[% KohaDates.tz | html %]';
12
13
        var get_date_pattern = function(format) {
14
            var date_pattern = 'YYYY-MM-DD';
15
            if(format == 'us') date_pattern = 'MM/DD/YYYY';
16
            if(format == 'metric') date_pattern = 'DD/MM/YYYY';
17
            if(format == 'dmydot') date_pattern = 'DD.MM.YYYY';
18
            return date_pattern;
19
        };
20
21
        var get_time_pattern = function(format) {
22
            var time_pattern = 'HH:mm';
23
            if(format == '12hr') time_pattern = 'hh:mm a';
24
            return time_pattern;
25
        };
26
27
        window.$date = function(value, options) {
28
            var tz = (opitons&&options.tz)||def_tz;
29
            var m = moment(value);
30
            if(tz) m.tz(tz);
31
32
            var dateformat = (options&&options.dateformat)||def_date_format;
33
            var withtime = (options&&options.withtime)||false;
34
35
            if(dateformat=='rfc3339' && withtime) return m.format();
36
            
37
            var timeformat = (options&&options.timeformat)||def_time_format;
38
            var date_pattern = get_date_pattern(dateformat);
39
            var time_pattern = !withtime?'':' '+get_time_pattern(timeformat);
40
            
41
            return m.format(date_pattern+time_pattern);
42
        }
43
44
        window.$datetime = function(value, options) {
45
            options = options||{};
46
            options.withtime = true;
47
            return $date(value, options);
48
        };
49
50
        window.$time = function(value, options) {
51
            var tz = (opitons&&options.tz)||def_tz;
52
            var m = moment(value);
53
            if(tz) m.tz(tz);
54
55
            var dateformat = (options&&options.dateformat);
56
            var timeformat = (dateformat=='rfc3339'&&'24hr')||(options&&options.timeformat)||def_time_format;
57
58
            return m.format(get_time_pattern(timeformat)+(dateformat=='rfc3339'?':ss'+(!m.isUTC()?'Z':''):''))+(dateformat=='rfc3339' && m.isUTC()?'Z':'');
59
        }
60
61
    })();
62
</script>

Return to bug 24455