1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.timestamp = exports.floatTime = exports.intTime = void 0;
var _stringify = require("../../stringify");
var parseSexagesimal = function parseSexagesimal(sign, parts) {
var n = parts.split(':').reduce(function (n, p) {
return n * 60 + Number(p);
}, 0);
return sign === '-' ? -n : n;
}; // hhhh:mm:ss.sss
var stringifySexagesimal = function stringifySexagesimal(_ref) {
var value = _ref.value;
if (isNaN(value) || !isFinite(value)) return (0, _stringify.stringifyNumber)(value);
var sign = '';
if (value < 0) {
sign = '-';
value = Math.abs(value);
}
var parts = [value % 60]; // seconds, including ms
if (value < 60) {
parts.unshift(0); // at least one : is required
} else {
value = Math.round((value - parts[0]) / 60);
parts.unshift(value % 60); // minutes
if (value >= 60) {
value = Math.round((value - parts[0]) / 60);
parts.unshift(value); // hours
}
}
return sign + parts.map(function (n) {
return n < 10 ? '0' + String(n) : String(n);
}).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
;
};
var intTime = {
identify: function identify(value) {
return typeof value === 'number';
},
default: true,
tag: 'tag:yaml.org,2002:int',
format: 'TIME',
test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
resolve: function resolve(str, sign, parts) {
return parseSexagesimal(sign, parts.replace(/_/g, ''));
},
stringify: stringifySexagesimal
};
exports.intTime = intTime;
var floatTime = {
identify: function identify(value) {
return typeof value === 'number';
},
default: true,
tag: 'tag:yaml.org,2002:float',
format: 'TIME',
test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
resolve: function resolve(str, sign, parts) {
return parseSexagesimal(sign, parts.replace(/_/g, ''));
},
stringify: stringifySexagesimal
};
exports.floatTime = floatTime;
var timestamp = {
identify: function identify(value) {
return value instanceof Date;
},
default: true,
tag: 'tag:yaml.org,2002:timestamp',
// If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
// may be omitted altogether, resulting in a date format. In such a case, the time part is
// assumed to be 00:00:00Z (start of day, UTC).
test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
'(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
'([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
'(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
')?' + ')$'),
resolve: function resolve(str, year, month, day, hour, minute, second, millisec, tz) {
if (millisec) millisec = (millisec + '00').substr(1, 3);
var date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
if (tz && tz !== 'Z') {
var d = parseSexagesimal(tz[0], tz.slice(1));
if (Math.abs(d) < 30) d *= 60;
date -= 60000 * d;
}
return new Date(date);
},
stringify: function stringify(_ref2) {
var value = _ref2.value;
return value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '');
}
};
exports.timestamp = timestamp;
|