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

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/calendar.inc (+1 lines)
Lines 27-32 Link Here
27
    var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
27
    var flatpickr_timeformat = [% IF Koha.Preference('TimeFormat') == '12hr' %]false[% ELSE %]true[% END %];
28
</script>
28
</script>
29
<!-- / calendar.inc -->
29
<!-- / calendar.inc -->
30
[% Asset.js("lib/moment/moment.min.js") | $raw %]
30
[% Asset.js("js/calendar.js") | $raw %]
31
[% Asset.js("js/calendar.js") | $raw %]
31
[% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
32
[% Asset.js("lib/flatpickr/flatpickr.min.js") | $raw %]
32
[% Asset.js("lib/flatpickr/shortcut-buttons-flatpickr.min.js") | $raw %]
33
[% Asset.js("lib/flatpickr/shortcut-buttons-flatpickr.min.js") | $raw %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/calendar.js (-32 / +5 lines)
Lines 5-33 if (debug > 1) { Link Here
5
    alert("dateformat: " + dateformat_pref + "\ndebug is on (level " + debug + ")");
5
    alert("dateformat: " + dateformat_pref + "\ndebug is on (level " + debug + ")");
6
}
6
}
7
7
8
function is_valid_date(date) {
8
function is_valid_date(dateText) {
9
    // An empty string is considered as a valid date for convenient reasons.
9
    return moment(dateText, get_dateformat_str(dateformat_pref).toUpperCase(), true ).isValid();
10
    if (date === '') return 1;
11
    var dateformat = flatpickr_dateformat_string;
12
    if (dateformat == 'us') {
13
        if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
14
        dateformat = 'm/d/Y';
15
    } else if (dateformat == 'metric') {
16
        if (date.search(/^\d{2}\/\d{2}\/\d{4}($|\s)/) == -1) return 0;
17
        dateformat = 'd/m/Y';
18
    } else if (dateformat == 'iso') {
19
        if (date.search(/^\d{4}-\d{2}-\d{2}($|\s)/) == -1) return 0;
20
        dateformat = 'Y-m-d';
21
    } else if (dateformat == 'dmydot') {
22
        if (date.search(/^\d{2}\.\d{2}\.\d{4}($|\s)/) == -1) return 0;
23
        dateformat = 'd.m.Y';
24
    }
25
    try {
26
        flatpickr.parseDate(date, dateformat);
27
    } catch (e) {
28
        return 0;
29
    }
30
    return 1;
31
}
10
}
32
11
33
function get_dateformat_str(dateformat) {
12
function get_dateformat_str(dateformat) {
Lines 58-77 function Date_from_syspref(dstring) { Link Here
58
        sentmsg++;
37
        sentmsg++;
59
        alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));
38
        alert("Date_from_syspref(" + dstring + ") splits to:\n" + dateX.join("\n"));
60
    }
39
    }
61
    if (dateformat_pref === "iso") {
40
    let m = moment(dstring, get_dateformat_str(dateformat_pref).toUpperCase(), true);
62
        return new Date(dateX[0], (dateX[1] - 1), dateX[2]); // YYYY-MM-DD to (YYYY,m(0-11),d)
41
    if ( !m.isValid() ) {
63
    } else if (dateformat_pref === "us") {
64
        return new Date(dateX[2], (dateX[0] - 1), dateX[1]); // MM/DD/YYYY to (YYYY,m(0-11),d)
65
    } else if (dateformat_pref === "metric") {
66
        return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD/MM/YYYY to (YYYY,m(0-11),d)
67
    } else if (dateformat_pref === "dmydot") {
68
        return new Date(dateX[2], (dateX[1] - 1), dateX[0]); // DD.MM.YYYY to (YYYY,m(0-11),d)
69
    } else {
70
        if (debug > 0) {
42
        if (debug > 0) {
71
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
43
            alert("KOHA ERROR - Unrecognized date format: " + dateformat_pref);
72
        }
44
        }
73
        return 0;
45
        return 0;
74
    }
46
    }
47
    return m.toDate();
75
}
48
}
76
49
77
function DateTime_from_syspref(date_time) {
50
function DateTime_from_syspref(date_time) {
(-)a/koha-tmpl/intranet-tmpl/prog/js/members.js (-6 / +3 lines)
Lines 129-136 function select_user(borrowernumber, borrower, relationship) { Link Here
129
function CalculateAge(dateofbirth) {
129
function CalculateAge(dateofbirth) {
130
    var today = new Date();
130
    var today = new Date();
131
    var dob = Date_from_syspref(dateofbirth);
131
    var dob = Date_from_syspref(dateofbirth);
132
    var age = {};
132
    if (!dob) return;
133
133
134
    var age = {};
134
    age.year = today.getFullYear() - dob.getFullYear();
135
    age.year = today.getFullYear() - dob.getFullYear();
135
    age.month = today.getMonth() - dob.getMonth();
136
    age.month = today.getMonth() - dob.getMonth();
136
    var day = today.getDate() - dob.getDate();
137
    var day = today.getDate() - dob.getDate();
Lines 152-161 function write_age() { Link Here
152
    hint.html(dateformat);
153
    hint.html(dateformat);
153
154
154
    var age = CalculateAge(document.form.dateofbirth.value);
155
    var age = CalculateAge(document.form.dateofbirth.value);
155
156
    if (!age) return;
156
    if (!age.year && !age.month) {
157
        return;
158
    }
159
157
160
    var age_string;
158
    var age_string;
161
    if (age.year || age.month) {
159
    if (age.year || age.month) {
162
- 

Return to bug 30673