Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision eb474565

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

  • ID eb4745651abf3b484577fd051624826bc16d2467
  • Vorgänger 06806380
  • Nachfolger cc125b4f

Validator: time

Unterschiede anzeigen:

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;

Auch abrufbar als: Unified diff