Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7f414d7b

Von Sven Schöling vor fast 7 Jahren hinzugefügt

  • ID 7f414d7b101046679e311f35c849a9ecfe60a538
  • Vorgänger 61a57179
  • Nachfolger 144e96c1

Validator: time - striktere Prüfung und tests

Unterschiede anzeigen:

js/kivi.js
138 138

  
139 139
    var parts = time.replace(/\s+/g, "").split(ns._time_format.sep);
140 140
    if (parts.length == 2) {
141
      for (var idx in parts) {
142
        if (Number.isNaN(Number.parseInt(parts[idx])))
143
          return undefined;
144
      }
141 145
      now.setHours(parts[ns._time_format.h], parts[ns._time_format.m]);
142 146
      return now;
143 147
    } else
js/t/kivi/parse_format_time.js
5 5
}
6 6

  
7 7
QUnit.test("kivi.parse_time function for German time style with colon", function( assert ) {
8
  assert.equalTimes = function(actual, expected, message) {
9
    console.log(this);
10
    var result = (expected === undefined && actual === undefined)
11
                || (expected === null      && actual === null)
12
                || (expected instanceof Date && actual instanceof Date &&
13
                    expected.getHours()   == actual.getHours() &&
14
                    expected.getMinutes() == actual.getMinutes());
15

  
16
    this.push( {
17
        result: result,
18
        actual: actual,
19
        expected: expected,
20
        message: message
21
    } );
22
  }
23

  
8 24
  kivi.setup_formats({ times: "hh:mm" });
9 25

  
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));
26
  assert.equalTimes(kivi.parse_time("12:34"), custom_time(12,34));
27
  assert.equalTimes(kivi.parse_time("10:00"), custom_time(10,0));
28
  assert.equalTimes(kivi.parse_time("      12 :  23  ") - custom_time(12,23));
13 29

  
14
  assert.deepEqual(kivi.parse_time("00:20"), custom_time(0,20));
30
  assert.equalTimes(kivi.parse_time("00:20"), custom_time(0,20));
15 31

  
16
  assert.deepEqual(kivi.parse_time("23:60"), custom_time(23,60));
32
  assert.equalTimes(kivi.parse_time("23:60"), custom_time(23,60));
17 33

  
18
  assert.deepEqual(kivi.parse_time("1142"), custom_time(11,42));
34
  assert.equalTimes(kivi.parse_time("1142"), custom_time(11,42));
19 35

  
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));
36
  assert.equalTimes(kivi.parse_time("Totally Invalid!"), undefined);
37
  assert.equalTimes(kivi.parse_time("."), undefined);
38
  assert.equalTimes(kivi.parse_time(".."), undefined);
39
  assert.equalTimes(kivi.parse_time(":"), undefined);
40
  assert.equalTimes(kivi.parse_time("::"), undefined);
41
  assert.equalTimes(kivi.parse_time("aa:bb"), undefined);
42
  assert.equalTimes(kivi.parse_time("aasd:bbaf"), undefined);
43
  assert.equalTimes(kivi.parse_time(""), null);
44
  assert.equalTimes(kivi.parse_time("0"), new Date());
45
  assert.equalTimes(kivi.parse_time("29:20008"), custom_time(29,20008));
28 46
});
29 47

  

Auch abrufbar als: Unified diff