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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc (+1 lines)
Lines 37-42 Link Here
37
        var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
37
        var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
38
    </script>
38
    </script>
39
    <!-- / calendar.inc -->
39
    <!-- / calendar.inc -->
40
    [% Asset.js("lib/dayjs/dayjs.min.js") | $raw %]
40
    [% Asset.js("js/calendar.js") | $raw %]
41
    [% Asset.js("js/calendar.js") | $raw %]
41
    [% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
42
    [% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
42
    [% Asset.js("lib/flatpickr/shortcut-buttons-flatpickr.min.js") | $raw %]
43
    [% Asset.js("lib/flatpickr/shortcut-buttons-flatpickr.min.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/calendar.js (-33 / +5 lines)
Lines 9-37 if (debug > 1) { Link Here
9
    );
9
    );
10
}
10
}
11
11
12
function is_valid_date(date) {
12
function is_valid_date(dateText) {
13
    // An empty string is considered as a valid date for convenient reasons.
13
    return dayjs(dateText, get_dateformat_str(dateformat_pref).toUpperCase(), true ).isValid();
14
    if (date === "") return 1;
15
    var dateformat = flatpickr_dateformat_string;
16
    if (dateformat == "us") {
17
        if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
18
        dateformat = "m/d/Y";
19
    } else if (dateformat == "metric") {
20
        if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
21
        dateformat = "d/m/Y";
22
    } else if (dateformat == "iso") {
23
        if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0;
24
        dateformat = "Y-m-d";
25
    } else if (dateformat == "dmydot") {
26
        if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0;
27
        dateformat = "d.m.Y";
28
    }
29
    try {
30
        flatpickr.parseDate(date, dateformat);
31
    } catch (e) {
32
        return 0;
33
    }
34
    return 1;
35
}
14
}
36
15
37
function get_dateformat_str(dateformat) {
16
function get_dateformat_str(dateformat) {
Lines 64-83 function Date_from_syspref(dstring) { Link Here
64
            "Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n")
43
            "Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n")
65
        );
44
        );
66
    }
45
    }
67
    if (dateformat_pref === "iso") {
46
    let d = dayjs(dstring, get_dateformat_str(dateformat_pref).toUpperCase(), true);
68
        return new Date(dateX[0], dateX[1] - 1, dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
47
    if ( !d.isValid() ) {
69
    } else if (dateformat_pref === "us") {
70
        return new Date(dateX[2], dateX[0] - 1, dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
71
    } else if (dateformat_pref === "metric") {
72
        return new Date(dateX[2], dateX[1] - 1, dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
73
    } else if (dateformat_pref === "dmydot") {
74
        return new Date(dateX[2], dateX[1] - 1, dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d)
75
    } else {
76
        if (debug > 0) {
48
        if (debug > 0) {
77
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
49
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
78
        }
50
        }
79
        return 0;
51
        return 0;
80
    }
52
    }
53
    return d.toDate();
81
}
54
}
82
55
83
function DateTime_from_syspref(date_time) {
56
function DateTime_from_syspref(date_time) {
84
- 

Return to bug 31149