Revision eb474565
Von Sven Schöling vor fast 7 Jahren hinzugefügt
js/kivi.Validator.js | ||
---|---|---|
104 | 104 |
ns.annotate($e); |
105 | 105 |
return true; |
106 | 106 |
} |
107 |
}, |
|
108 |
time: function($e) { |
|
109 |
var time_string = $e.val(); |
|
110 |
|
|
111 |
var parsed_time = kivi.parse_time(time_string); |
|
112 |
if (parsed_time === null) { |
|
113 |
$e.val(''); |
|
114 |
ns.annotate($e); |
|
115 |
return true; |
|
116 |
} else |
|
117 |
if (parsed_time === undefined) { |
|
118 |
ns.annotate($e, kivi.t8('Wrong time format (#1)', [ kivi.myconfig.timeformat ])); |
|
119 |
return false; |
|
120 |
} else |
|
121 |
{ |
|
122 |
var formatted_time = kivi.format_time(parsed_time); |
|
123 |
if (formatted_time != time_string) |
|
124 |
$e.val(formatted_time); |
|
125 |
ns.annotate($e); |
|
126 |
return true; |
|
127 |
} |
|
107 | 128 |
} |
108 | 129 |
}; |
109 | 130 |
|
js/kivi.js | ||
---|---|---|
8 | 8 |
m: 1, |
9 | 9 |
d: 0 |
10 | 10 |
}; |
11 |
ns._time_format = { |
|
12 |
sep: ':', |
|
13 |
h: 0, |
|
14 |
m: 1, |
|
15 |
}; |
|
11 | 16 |
ns._number_format = { |
12 | 17 |
decimalSep: ',', |
13 | 18 |
thousandSep: '.' |
... | ... | |
22 | 27 |
ns._date_format[res[4].substr(0, 1)] = 2; |
23 | 28 |
} |
24 | 29 |
|
30 |
res = (params.times || "").match(/^([hm]+)([^a-z])([hm]+)$/); |
|
31 |
if (res) { |
|
32 |
ns._time_format = { sep: res[2] }; |
|
33 |
ns._time_format[res[1].substr(0, 1)] = 0; |
|
34 |
ns._time_format[res[3].substr(0, 1)] = 1; |
|
35 |
} |
|
36 |
|
|
25 | 37 |
res = (params.numbers || "").match(/^\d*([^\d]?)\d+([^\d])\d+$/); |
26 | 38 |
if (res) |
27 | 39 |
ns._number_format = { |
... | ... | |
101 | 113 |
return parts.join(ns._date_format.sep); |
102 | 114 |
}; |
103 | 115 |
|
116 |
ns.parse_time = function(time) { |
|
117 |
var now = new Date(); |
|
118 |
|
|
119 |
if (time === undefined) |
|
120 |
return undefined; |
|
121 |
|
|
122 |
if (time === '') |
|
123 |
return null; |
|
124 |
|
|
125 |
if (time === '0') |
|
126 |
return now; |
|
127 |
|
|
128 |
// special case 1: military time in fixed "hhmm" format |
|
129 |
if (time.length == 4) { |
|
130 |
var res = time.match(/(\d\d)(\d\d)/); |
|
131 |
if (res) { |
|
132 |
now.setHours(res[1], res[2]); |
|
133 |
return now; |
|
134 |
} else { |
|
135 |
return undefined; |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
var parts = time.replace(/\s+/g, "").split(ns._time_format.sep); |
|
140 |
if (parts.length == 2) { |
|
141 |
now.setHours(parts[ns._time_format.h], parts[ns._time_format.m]); |
|
142 |
return now; |
|
143 |
} else |
|
144 |
return undefined; |
|
145 |
} |
|
146 |
|
|
147 |
ns.format_time = function(date) { |
|
148 |
if (isNaN(date.getTime())) |
|
149 |
return undefined; |
|
150 |
|
|
151 |
var parts = [ "", "" ] |
|
152 |
parts[ ns._time_format.h ] = date.getHours().toString().padStart(2, '0'); |
|
153 |
parts[ ns._time_format.m ] = date.getMinutes().toString().padStart(2, '0'); |
|
154 |
return parts.join(ns._time_format.sep); |
|
155 |
}; |
|
156 |
|
|
104 | 157 |
ns.parse_amount = function(amount) { |
105 | 158 |
if (amount === undefined) |
106 | 159 |
return undefined; |
js/locale/de.js | ||
---|---|---|
134 | 134 |
"Version actions":"Aktionen für Versionen", |
135 | 135 |
"Wrong date format (#1)":"Falsches Datumsformat (#1)", |
136 | 136 |
"Wrong number format (#1)":"Falsches Zahlenformat (#1)", |
137 |
"Wrong time format (#1)":"Falsches Zeitformat (#1)", |
|
137 | 138 |
"Yes":"Ja", |
138 | 139 |
"filename has not uploadable characters ":"Bitte Dateinamen ändern. Er hat für den Upload nicht verwendbare Sonderzeichen ", |
139 | 140 |
"filesize too big: ":"Datei zu groß: ", |
js/t/kivi/parse_format_time.js | ||
---|---|---|
1 |
function custom_time(h,m) { |
|
2 |
var time = new Date(); |
|
3 |
time.setHours(h,m); |
|
4 |
return time; |
|
5 |
} |
|
6 |
|
|
7 |
QUnit.test("kivi.parse_time function for German time style with colon", function( assert ) { |
|
8 |
kivi.setup_formats({ times: "hh:mm" }); |
|
9 |
|
|
10 |
assert.deepEqual(kivi.parse_time("12:34"), custom_time(12,34)); |
|
11 |
assert.deepEqual(kivi.parse_time("10:00"), custom_time(10,0)); |
|
12 |
assert.deepEqual(kivi.parse_time(" 12 : 23 "), custom_time(12,23)); |
|
13 |
|
|
14 |
assert.deepEqual(kivi.parse_time("00:20"), custom_time(0,20)); |
|
15 |
|
|
16 |
assert.deepEqual(kivi.parse_time("23:60"), custom_time(23,60)); |
|
17 |
|
|
18 |
assert.deepEqual(kivi.parse_time("1142"), custom_time(11,42)); |
|
19 |
|
|
20 |
assert.deepEqual(kivi.parse_time("Totally Invalid!"), undefined); |
|
21 |
assert.deepEqual(kivi.parse_time("."), undefined); |
|
22 |
assert.deepEqual(kivi.parse_time(".."), undefined); |
|
23 |
assert.deepEqual(kivi.parse_time(":"), custom_time(0,0)); |
|
24 |
assert.deepEqual(kivi.parse_time("::"), undefined); |
|
25 |
assert.deepEqual(kivi.parse_time(""), null); |
|
26 |
assert.deepEqual(kivi.parse_time("0"), new Date()); |
|
27 |
assert.deepEqual(kivi.parse_time("29:20008"), custom_time(29,20008)); |
|
28 |
}); |
|
29 |
|
locale/de/all | ||
---|---|---|
3819 | 3819 |
'Wrong number format (#1)' => 'Falsches Zahlenformat (#1)', |
3820 | 3820 |
'Wrong tax keys recorded' => 'Gespeicherte Steuerschlüssel sind falsch', |
3821 | 3821 |
'Wrong taxes recorded' => 'Gespeicherte Steuern passen nicht zum Steuerschlüssel', |
3822 |
'Wrong time format (#1)' => 'Falsches Zeitformat (#1)', |
|
3822 | 3823 |
'X' => 'X', |
3823 | 3824 |
'YYYY' => 'JJJJ', |
3824 | 3825 |
'Year' => 'Jahr', |
templates/webpages/layout/javascript_setup.js | ||
---|---|---|
16 | 16 |
|
17 | 17 |
kivi.setup_formats({ |
18 | 18 |
numbers: kivi.myconfig.numberformat, |
19 |
dates: kivi.myconfig.dateformat |
|
19 |
dates: kivi.myconfig.dateformat, |
|
20 |
times: kivi.myconfig.timeformat |
|
20 | 21 |
}); |
21 | 22 |
|
22 | 23 |
kivi.reinit_widgets(); |
Auch abrufbar als: Unified diff
Validator: time