Commit ca0b897d authored by gerd's avatar gerd

Fix: check_date accepts date literals with leading zeroes.


git-svn-id: https://godirepo.camlcity.org/svn/app-wtimer/trunk@13 f6fe576d-e0d0-0310-b8e7-f4ac0f1a5269
parent 53b38fec
......@@ -167,6 +167,19 @@ function check_time_string (widget) {
}
}
function parseDec (s) {
// parse s as decimal string, ignoring leading zeros
var k;
var n = 0;
for (k = 0; k < s.length; k++) {
var j = parseInt(s.substr(k,1));
n = 10 * n + j;
}
return n;
}
var date_re = /^[ \t]*(\d{4})-(\d{1,2})-(\d{1,2})[ \t]*$/;
function check_date_string (widget) {
......@@ -174,9 +187,9 @@ function check_date_string (widget) {
var valid = 0;
var slots = date_re.exec(widget.value);
if (slots != null) {
var yr = parseInt(slots[1]);
var mon = parseInt(slots[2]);
var day = parseInt(slots[3]);
var yr = parseDec(slots[1]);
var mon = parseDec(slots[2]);
var day = parseDec(slots[3]);
var d = new Date(yr,mon-1,day);
valid = (yr == d.getYear()+1900) &&
(mon == d.getMonth()+1) &&
......@@ -205,8 +218,8 @@ var year_re = /^\d\d\d\d$/;
function check_year_string (widget) {
var v;
if (! year_re.test(widget.value) || parseInt(widget.value) < 1902 ||
parseInt(widget.value) > 2037) {
if (! year_re.test(widget.value) || parseDec(widget.value) < 1902 ||
parseDec(widget.value) > 2037) {
v = previous_values[widget.name];
if (v == null) {
v = widget.defaultValue;
......@@ -230,8 +243,8 @@ function check_number (widget, min, max) {
/* widget must contain a number >= min and <= max */
var v;
if (! /^-?\d+$/.test(widget.value) ||
parseInt(widget.value) < min ||
parseInt(widget.value) > max) {
parseDec(widget.value) < min ||
parseDec(widget.value) > max) {
v = previous_values[widget.name];
if (v == null) {
v = widget.defaultValue;
......@@ -268,13 +281,13 @@ function admin_pw_check (pw1, pw2) {
/* For the "+" and "-" buttons on the calendar page: */
function inc_year ( wdg ) {
var v = parseInt(wdg.value) + 1;
var v = parseDec(wdg.value) + 1;
if (v > 2037) v = 2037;
wdg.value = v;
}
function dec_year ( wdg ) {
var v = parseInt(wdg.value) - 1;
var v = parseDec(wdg.value) - 1;
if (v < 1902) v = 1902;
wdg.value = v;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment