|
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 dayjs(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 d = dayjs(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 ( !d.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 d.toDate(); |
| 75 |
} |
48 |
} |
| 76 |
|
49 |
|
| 77 |
function DateTime_from_syspref(date_time) { |
50 |
function DateTime_from_syspref(date_time) { |
| 78 |
- |
|
|