ns.annotate($e);
return true;
}
+ },
+ time: function($e) {
+ var time_string = $e.val();
+
+ var parsed_time = kivi.parse_time(time_string);
+ if (parsed_time === null) {
+ $e.val('');
+ ns.annotate($e);
+ return true;
+ } else
+ if (parsed_time === undefined) {
+ ns.annotate($e, kivi.t8('Wrong time format (#1)', [ kivi.myconfig.timeformat ]));
+ return false;
+ } else
+ {
+ var formatted_time = kivi.format_time(parsed_time);
+ if (formatted_time != time_string)
+ $e.val(formatted_time);
+ ns.annotate($e);
+ return true;
+ }
}
};
m: 1,
d: 0
};
+ ns._time_format = {
+ sep: ':',
+ h: 0,
+ m: 1,
+ };
ns._number_format = {
decimalSep: ',',
thousandSep: '.'
ns._date_format[res[4].substr(0, 1)] = 2;
}
+ res = (params.times || "").match(/^([hm]+)([^a-z])([hm]+)$/);
+ if (res) {
+ ns._time_format = { sep: res[2] };
+ ns._time_format[res[1].substr(0, 1)] = 0;
+ ns._time_format[res[3].substr(0, 1)] = 1;
+ }
+
res = (params.numbers || "").match(/^\d*([^\d]?)\d+([^\d])\d+$/);
if (res)
ns._number_format = {
return parts.join(ns._date_format.sep);
};
+ ns.parse_time = function(time) {
+ var now = new Date();
+
+ if (time === undefined)
+ return undefined;
+
+ if (time === '')
+ return null;
+
+ if (time === '0')
+ return now;
+
+ // special case 1: military time in fixed "hhmm" format
+ if (time.length == 4) {
+ var res = time.match(/(\d\d)(\d\d)/);
+ if (res) {
+ now.setHours(res[1], res[2]);
+ return now;
+ } else {
+ return undefined;
+ }
+ }
+
+ var parts = time.replace(/\s+/g, "").split(ns._time_format.sep);
+ if (parts.length == 2) {
+ now.setHours(parts[ns._time_format.h], parts[ns._time_format.m]);
+ return now;
+ } else
+ return undefined;
+ }
+
+ ns.format_time = function(date) {
+ if (isNaN(date.getTime()))
+ return undefined;
+
+ var parts = [ "", "" ]
+ parts[ ns._time_format.h ] = date.getHours().toString().padStart(2, '0');
+ parts[ ns._time_format.m ] = date.getMinutes().toString().padStart(2, '0');
+ return parts.join(ns._time_format.sep);
+ };
+
ns.parse_amount = function(amount) {
if (amount === undefined)
return undefined;
"Version actions":"Aktionen für Versionen",
"Wrong date format (#1)":"Falsches Datumsformat (#1)",
"Wrong number format (#1)":"Falsches Zahlenformat (#1)",
+"Wrong time format (#1)":"Falsches Zeitformat (#1)",
"Yes":"Ja",
"filename has not uploadable characters ":"Bitte Dateinamen ändern. Er hat für den Upload nicht verwendbare Sonderzeichen ",
"filesize too big: ":"Datei zu groß: ",
--- /dev/null
+function custom_time(h,m) {
+ var time = new Date();
+ time.setHours(h,m);
+ return time;
+}
+
+QUnit.test("kivi.parse_time function for German time style with colon", function( assert ) {
+ kivi.setup_formats({ times: "hh:mm" });
+
+ assert.deepEqual(kivi.parse_time("12:34"), custom_time(12,34));
+ assert.deepEqual(kivi.parse_time("10:00"), custom_time(10,0));
+ assert.deepEqual(kivi.parse_time(" 12 : 23 "), custom_time(12,23));
+
+ assert.deepEqual(kivi.parse_time("00:20"), custom_time(0,20));
+
+ assert.deepEqual(kivi.parse_time("23:60"), custom_time(23,60));
+
+ assert.deepEqual(kivi.parse_time("1142"), custom_time(11,42));
+
+ assert.deepEqual(kivi.parse_time("Totally Invalid!"), undefined);
+ assert.deepEqual(kivi.parse_time("."), undefined);
+ assert.deepEqual(kivi.parse_time(".."), undefined);
+ assert.deepEqual(kivi.parse_time(":"), custom_time(0,0));
+ assert.deepEqual(kivi.parse_time("::"), undefined);
+ assert.deepEqual(kivi.parse_time(""), null);
+ assert.deepEqual(kivi.parse_time("0"), new Date());
+ assert.deepEqual(kivi.parse_time("29:20008"), custom_time(29,20008));
+});
+
'Wrong number format (#1)' => 'Falsches Zahlenformat (#1)',
'Wrong tax keys recorded' => 'Gespeicherte Steuerschlüssel sind falsch',
'Wrong taxes recorded' => 'Gespeicherte Steuern passen nicht zum Steuerschlüssel',
+ 'Wrong time format (#1)' => 'Falsches Zeitformat (#1)',
'X' => 'X',
'YYYY' => 'JJJJ',
'Year' => 'Jahr',
kivi.setup_formats({
numbers: kivi.myconfig.numberformat,
- dates: kivi.myconfig.dateformat
+ dates: kivi.myconfig.dateformat,
+ times: kivi.myconfig.timeformat
});
kivi.reinit_widgets();