UNPKG

1.5 kBJavaScriptView Raw
1import dateutil from './dateutil';
2import { DateTime } from 'luxon';
3var DateWithZone = /** @class */ (function () {
4 function DateWithZone(date, tzid) {
5 this.date = date;
6 this.tzid = tzid;
7 }
8 Object.defineProperty(DateWithZone.prototype, "isUTC", {
9 get: function () {
10 return !this.tzid || this.tzid.toUpperCase() === 'UTC';
11 },
12 enumerable: true,
13 configurable: true
14 });
15 DateWithZone.prototype.toString = function () {
16 var datestr = dateutil.timeToUntilString(this.date.getTime(), this.isUTC);
17 if (!this.isUTC) {
18 return ";TZID=" + this.tzid + ":" + datestr;
19 }
20 return ":" + datestr;
21 };
22 DateWithZone.prototype.getTime = function () {
23 return this.date.getTime();
24 };
25 DateWithZone.prototype.rezonedDate = function () {
26 if (this.isUTC) {
27 return this.date;
28 }
29 try {
30 var datetime = DateTime
31 .fromJSDate(this.date);
32 var rezoned = datetime.setZone(this.tzid, { keepLocalTime: true });
33 return rezoned.toJSDate();
34 }
35 catch (e) {
36 if (e instanceof TypeError) {
37 console.error('Using TZID without Luxon available is unsupported. Returned times are in UTC, not the requested time zone');
38 }
39 return this.date;
40 }
41 };
42 return DateWithZone;
43}());
44export { DateWithZone };
45//# sourceMappingURL=datewithzone.js.map
\No newline at end of file