1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.DateTime = exports.LocalDateTime = exports.Date = exports.Time = exports.LocalTime = exports.Duration = undefined;
|
7 |
|
8 | var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
|
9 |
|
10 | var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
|
11 |
|
12 | var _defineProperty = require('babel-runtime/core-js/object/define-property');
|
13 |
|
14 | var _defineProperty2 = _interopRequireDefault(_defineProperty);
|
15 |
|
16 | var _freeze = require('babel-runtime/core-js/object/freeze');
|
17 |
|
18 | var _freeze2 = _interopRequireDefault(_freeze);
|
19 |
|
20 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
21 |
|
22 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
23 |
|
24 | var _createClass2 = require('babel-runtime/helpers/createClass');
|
25 |
|
26 | var _createClass3 = _interopRequireDefault(_createClass2);
|
27 |
|
28 | exports.isDuration = isDuration;
|
29 | exports.isLocalTime = isLocalTime;
|
30 | exports.isTime = isTime;
|
31 | exports.isDate = isDate;
|
32 | exports.isLocalDateTime = isLocalDateTime;
|
33 | exports.isDateTime = isDateTime;
|
34 |
|
35 | var _temporalUtil = require('./internal/temporal-util');
|
36 |
|
37 | var _error = require('./error');
|
38 |
|
39 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | var IDENTIFIER_PROPERTY_ATTRIBUTES = {
|
60 | value: true,
|
61 | enumerable: false,
|
62 | configurable: false
|
63 | };
|
64 |
|
65 | var DURATION_IDENTIFIER_PROPERTY = '__isDuration__';
|
66 | var LOCAL_TIME_IDENTIFIER_PROPERTY = '__isLocalTime__';
|
67 | var TIME_IDENTIFIER_PROPERTY = '__isTime__';
|
68 | var DATE_IDENTIFIER_PROPERTY = '__isDate__';
|
69 | var LOCAL_DATE_TIME_IDENTIFIER_PROPERTY = '__isLocalDateTime__';
|
70 | var DATE_TIME_IDENTIFIER_PROPERTY = '__isDateTime__';
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 | var Duration = exports.Duration = function () {
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | function Duration(months, days, seconds, nanoseconds) {
|
87 | (0, _classCallCheck3.default)(this, Duration);
|
88 |
|
89 | this.months = months;
|
90 | this.days = days;
|
91 | this.seconds = seconds;
|
92 | this.nanoseconds = nanoseconds;
|
93 | (0, _freeze2.default)(this);
|
94 | }
|
95 |
|
96 | (0, _createClass3.default)(Duration, [{
|
97 | key: 'toString',
|
98 | value: function toString() {
|
99 | return (0, _temporalUtil.durationToIsoString)(this.months, this.days, this.seconds, this.nanoseconds);
|
100 | }
|
101 | }]);
|
102 | return Duration;
|
103 | }();
|
104 |
|
105 | (0, _defineProperty2.default)(Duration.prototype, DURATION_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | function isDuration(obj) {
|
113 | return hasIdentifierProperty(obj, DURATION_IDENTIFIER_PROPERTY);
|
114 | }
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 | var LocalTime = exports.LocalTime = function () {
|
122 |
|
123 | |
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 | function LocalTime(hour, minute, second, nanosecond) {
|
131 | (0, _classCallCheck3.default)(this, LocalTime);
|
132 |
|
133 | this.hour = hour;
|
134 | this.minute = minute;
|
135 | this.second = second;
|
136 | this.nanosecond = nanosecond;
|
137 | (0, _freeze2.default)(this);
|
138 | }
|
139 |
|
140 | (0, _createClass3.default)(LocalTime, [{
|
141 | key: 'toString',
|
142 | value: function toString() {
|
143 | return (0, _temporalUtil.timeToIsoString)(this.hour, this.minute, this.second, this.nanosecond);
|
144 | }
|
145 | }]);
|
146 | return LocalTime;
|
147 | }();
|
148 |
|
149 | (0, _defineProperty2.default)(LocalTime.prototype, LOCAL_TIME_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 | function isLocalTime(obj) {
|
157 | return hasIdentifierProperty(obj, LOCAL_TIME_IDENTIFIER_PROPERTY);
|
158 | }
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 | var Time = exports.Time = function () {
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | function Time(hour, minute, second, nanosecond, timeZoneOffsetSeconds) {
|
176 | (0, _classCallCheck3.default)(this, Time);
|
177 |
|
178 | this.hour = hour;
|
179 | this.minute = minute;
|
180 | this.second = second;
|
181 | this.nanosecond = nanosecond;
|
182 | this.timeZoneOffsetSeconds = timeZoneOffsetSeconds;
|
183 | (0, _freeze2.default)(this);
|
184 | }
|
185 |
|
186 | (0, _createClass3.default)(Time, [{
|
187 | key: 'toString',
|
188 | value: function toString() {
|
189 | return (0, _temporalUtil.timeToIsoString)(this.hour, this.minute, this.second, this.nanosecond) + (0, _temporalUtil.timeZoneOffsetToIsoString)(this.timeZoneOffsetSeconds);
|
190 | }
|
191 | }]);
|
192 | return Time;
|
193 | }();
|
194 |
|
195 | (0, _defineProperty2.default)(Time.prototype, TIME_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
196 |
|
197 |
|
198 |
|
199 |
|
200 |
|
201 |
|
202 | function isTime(obj) {
|
203 | return hasIdentifierProperty(obj, TIME_IDENTIFIER_PROPERTY);
|
204 | }
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 | var Date = exports.Date = function () {
|
212 |
|
213 | |
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 | function Date(year, month, day) {
|
220 | (0, _classCallCheck3.default)(this, Date);
|
221 |
|
222 | this.year = year;
|
223 | this.month = month;
|
224 | this.day = day;
|
225 | (0, _freeze2.default)(this);
|
226 | }
|
227 |
|
228 | (0, _createClass3.default)(Date, [{
|
229 | key: 'toString',
|
230 | value: function toString() {
|
231 | return (0, _temporalUtil.dateToIsoString)(this.year, this.month, this.day);
|
232 | }
|
233 | }]);
|
234 | return Date;
|
235 | }();
|
236 |
|
237 | (0, _defineProperty2.default)(Date.prototype, DATE_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | function isDate(obj) {
|
245 | return hasIdentifierProperty(obj, DATE_IDENTIFIER_PROPERTY);
|
246 | }
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | var LocalDateTime = exports.LocalDateTime = function () {
|
254 |
|
255 | |
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | function LocalDateTime(year, month, day, hour, minute, second, nanosecond) {
|
266 | (0, _classCallCheck3.default)(this, LocalDateTime);
|
267 |
|
268 | this.year = year;
|
269 | this.month = month;
|
270 | this.day = day;
|
271 | this.hour = hour;
|
272 | this.minute = minute;
|
273 | this.second = second;
|
274 | this.nanosecond = nanosecond;
|
275 | (0, _freeze2.default)(this);
|
276 | }
|
277 |
|
278 | (0, _createClass3.default)(LocalDateTime, [{
|
279 | key: 'toString',
|
280 | value: function toString() {
|
281 | return localDateTimeToString(this.year, this.month, this.day, this.hour, this.minute, this.second, this.nanosecond);
|
282 | }
|
283 | }]);
|
284 | return LocalDateTime;
|
285 | }();
|
286 |
|
287 | (0, _defineProperty2.default)(LocalDateTime.prototype, LOCAL_DATE_TIME_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 | function isLocalDateTime(obj) {
|
295 | return hasIdentifierProperty(obj, LOCAL_DATE_TIME_IDENTIFIER_PROPERTY);
|
296 | }
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 | var DateTime = exports.DateTime = function () {
|
304 |
|
305 | |
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | function DateTime(year, month, day, hour, minute, second, nanosecond, timeZoneOffsetSeconds, timeZoneId) {
|
318 | (0, _classCallCheck3.default)(this, DateTime);
|
319 |
|
320 | this.year = year;
|
321 | this.month = month;
|
322 | this.day = day;
|
323 | this.hour = hour;
|
324 | this.minute = minute;
|
325 | this.second = second;
|
326 | this.nanosecond = nanosecond;
|
327 |
|
328 | var _verifyTimeZoneArgume = verifyTimeZoneArguments(timeZoneOffsetSeconds, timeZoneId),
|
329 | _verifyTimeZoneArgume2 = (0, _slicedToArray3.default)(_verifyTimeZoneArgume, 2),
|
330 | offset = _verifyTimeZoneArgume2[0],
|
331 | id = _verifyTimeZoneArgume2[1];
|
332 |
|
333 | this.timeZoneOffsetSeconds = offset;
|
334 | this.timeZoneId = id;
|
335 |
|
336 | (0, _freeze2.default)(this);
|
337 | }
|
338 |
|
339 | (0, _createClass3.default)(DateTime, [{
|
340 | key: 'toString',
|
341 | value: function toString() {
|
342 | var localDateTimeStr = localDateTimeToString(this.year, this.month, this.day, this.hour, this.minute, this.second, this.nanosecond);
|
343 | var timeZoneStr = this.timeZoneId ? '[' + this.timeZoneId + ']' : (0, _temporalUtil.timeZoneOffsetToIsoString)(this.timeZoneOffsetSeconds);
|
344 | return localDateTimeStr + timeZoneStr;
|
345 | }
|
346 | }]);
|
347 | return DateTime;
|
348 | }();
|
349 |
|
350 | (0, _defineProperty2.default)(DateTime.prototype, DATE_TIME_IDENTIFIER_PROPERTY, IDENTIFIER_PROPERTY_ATTRIBUTES);
|
351 |
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 | function isDateTime(obj) {
|
358 | return hasIdentifierProperty(obj, DATE_TIME_IDENTIFIER_PROPERTY);
|
359 | }
|
360 |
|
361 | function hasIdentifierProperty(obj, property) {
|
362 | return (obj && obj[property]) === true;
|
363 | }
|
364 |
|
365 | function localDateTimeToString(year, month, day, hour, minute, second, nanosecond) {
|
366 | return (0, _temporalUtil.dateToIsoString)(year, month, day) + 'T' + (0, _temporalUtil.timeToIsoString)(hour, minute, second, nanosecond);
|
367 | }
|
368 |
|
369 | function verifyTimeZoneArguments(timeZoneOffsetSeconds, timeZoneId) {
|
370 | var offsetDefined = timeZoneOffsetSeconds || timeZoneOffsetSeconds === 0;
|
371 | var idDefined = timeZoneId && timeZoneId !== '';
|
372 |
|
373 | if (offsetDefined && !idDefined) {
|
374 | return [timeZoneOffsetSeconds, null];
|
375 | } else if (!offsetDefined && idDefined) {
|
376 | return [null, timeZoneId];
|
377 | } else if (offsetDefined && idDefined) {
|
378 | throw (0, _error.newError)('Unable to create DateTime with both time zone offset and id. Please specify either of them. Given offset: ' + timeZoneOffsetSeconds + ' and id: ' + timeZoneId);
|
379 | } else {
|
380 | throw (0, _error.newError)('Unable to create DateTime without either time zone offset or id. Please specify either of them. Given offset: ' + timeZoneOffsetSeconds + ' and id: ' + timeZoneId);
|
381 | }
|
382 | } |
\ | No newline at end of file |