source: trip-planner-front/node_modules/ajv/dist/runtime/timestamp.js

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const DT_SEPARATOR = /t|\s/i;
4const DATE = /^(\d\d\d\d)-(\d\d)-(\d\d)$/;
5const TIME = /^(\d\d):(\d\d):(\d\d)(?:\.\d+)?(?:z|([+-]\d\d)(?::?(\d\d))?)$/i;
6const DAYS = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
7function validTimestamp(str, allowDate) {
8 // http://tools.ietf.org/html/rfc3339#section-5.6
9 const dt = str.split(DT_SEPARATOR);
10 return ((dt.length === 2 && validDate(dt[0]) && validTime(dt[1])) ||
11 (allowDate && dt.length === 1 && validDate(dt[0])));
12}
13exports.default = validTimestamp;
14function validDate(str) {
15 const matches = DATE.exec(str);
16 if (!matches)
17 return false;
18 const y = +matches[1];
19 const m = +matches[2];
20 const d = +matches[3];
21 return (m >= 1 &&
22 m <= 12 &&
23 d >= 1 &&
24 (d <= DAYS[m] ||
25 // leap year: https://tools.ietf.org/html/rfc3339#appendix-C
26 (m === 2 && d === 29 && (y % 100 === 0 ? y % 400 === 0 : y % 4 === 0))));
27}
28function validTime(str) {
29 const matches = TIME.exec(str);
30 if (!matches)
31 return false;
32 const hr = +matches[1];
33 const min = +matches[2];
34 const sec = +matches[3];
35 const tzH = +(matches[4] || 0);
36 const tzM = +(matches[5] || 0);
37 return ((hr <= 23 && min <= 59 && sec <= 59) ||
38 // leap second
39 (hr - tzH === 23 && min - tzM === 59 && sec === 60));
40}
41validTimestamp.code = 'require("ajv/dist/runtime/timestamp").default';
42//# sourceMappingURL=timestamp.js.map
Note: See TracBrowser for help on using the repository browser.