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 = (options&&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> |