1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = formatISO9075;
|
7 |
|
8 | var _index = _interopRequireDefault(require("../toDate/index.js"));
|
9 |
|
10 | var _index2 = _interopRequireDefault(require("../isValid/index.js"));
|
11 |
|
12 | var _index3 = _interopRequireDefault(require("../_lib/addLeadingZeros/index.js"));
|
13 |
|
14 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
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 | function formatISO9075(dirtyDate, dirtyOptions) {
|
55 | if (arguments.length < 1) {
|
56 | throw new TypeError("1 argument required, but only ".concat(arguments.length, " present"));
|
57 | }
|
58 |
|
59 | var originalDate = (0, _index.default)(dirtyDate);
|
60 |
|
61 | if (!(0, _index2.default)(originalDate)) {
|
62 | throw new RangeError('Invalid time value');
|
63 | }
|
64 |
|
65 | var options = dirtyOptions || {};
|
66 | var format = options.format == null ? 'extended' : String(options.format);
|
67 | var representation = options.representation == null ? 'complete' : String(options.representation);
|
68 |
|
69 | if (format !== 'extended' && format !== 'basic') {
|
70 | throw new RangeError("format must be 'extended' or 'basic'");
|
71 | }
|
72 |
|
73 | if (representation !== 'date' && representation !== 'time' && representation !== 'complete') {
|
74 | throw new RangeError("representation must be 'date', 'time', or 'complete'");
|
75 | }
|
76 |
|
77 | var result = '';
|
78 | var dateDelimiter = format === 'extended' ? '-' : '';
|
79 | var timeDelimiter = format === 'extended' ? ':' : '';
|
80 |
|
81 | if (representation !== 'time') {
|
82 | var day = (0, _index3.default)(originalDate.getDate(), 2);
|
83 | var month = (0, _index3.default)(originalDate.getMonth() + 1, 2);
|
84 | var year = (0, _index3.default)(originalDate.getFullYear(), 4);
|
85 |
|
86 | result = "".concat(year).concat(dateDelimiter).concat(month).concat(dateDelimiter).concat(day);
|
87 | }
|
88 |
|
89 |
|
90 | if (representation !== 'date') {
|
91 | var hour = (0, _index3.default)(originalDate.getHours(), 2);
|
92 | var minute = (0, _index3.default)(originalDate.getMinutes(), 2);
|
93 | var second = (0, _index3.default)(originalDate.getSeconds(), 2);
|
94 |
|
95 | var separator = result === '' ? '' : ' ';
|
96 |
|
97 | result = "".concat(result).concat(separator).concat(hour).concat(timeDelimiter).concat(minute).concat(timeDelimiter).concat(second);
|
98 | }
|
99 |
|
100 | return result;
|
101 | }
|
102 |
|
103 | module.exports = exports.default; |
\ | No newline at end of file |