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 / +13 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(
14
    if (date === "") return 1;
14
        dateText,
15
    var dateformat = flatpickr_dateformat_string;
15
        get_dateformat_str(dateformat_pref).toUpperCase(),
16
    if (dateformat == "us") {
16
        true
17
        if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
17
    ).isValid();
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
}
18
}
36
19
37
function get_dateformat_str(dateformat) {
20
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")
47
            "Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n")
65
        );
48
        );
66
    }
49
    }
67
    if (dateformat_pref === "iso") {
50
    let d = dayjs(
68
        return new Date(dateX[0], dateX[1] - 1, dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
51
        dstring,
69
    } else if (dateformat_pref === "us") {
52
        get_dateformat_str(dateformat_pref).toUpperCase(),
70
        return new Date(dateX[2], dateX[0] - 1, dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
53
        true
71
    } else if (dateformat_pref === "metric") {
54
    );
72
        return new Date(dateX[2], dateX[1] - 1, dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
55
    if (!d.isValid()) {
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) {
56
        if (debug > 0) {
77
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
57
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
78
        }
58
        }
79
        return 0;
59
        return 0;
80
    }
60
    }
61
    return d.toDate();
81
}
62
}
82
63
83
function DateTime_from_syspref(date_time) {
64
function DateTime_from_syspref(date_time) {
84
- 

Return to bug 31149