-
-
Notifications
You must be signed in to change notification settings - Fork 199
/
ical.js.gs
9362 lines (9003 loc) · 304 KB
/
ical.js.gs
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch */
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.ICAL = factory());
})(this, (function () { 'use strict';
function _assertClassBrand(e, t, n) {
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
throw new TypeError("Private element is not present on this object");
}
function _callSuper(t, o, e) {
return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e));
}
function _construct(t, e, r) {
if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
var o = [null];
o.push.apply(o, e);
var p = new (t.bind.apply(t, o))();
return r && _setPrototypeOf(p, r.prototype), p;
}
function _isNativeReflectConstruct() {
try {
var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
} catch (t) {}
return (_isNativeReflectConstruct = function () {
return !!t;
})();
}
function _iterableToArrayLimit(r, l) {
var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (null != t) {
var e,
n,
i,
u,
a = [],
f = !0,
o = !1;
try {
if (i = (t = t.call(r)).next, 0 === l) {
if (Object(t) !== t) return;
f = !1;
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
} catch (r) {
o = !0, n = r;
} finally {
try {
if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
} finally {
if (o) throw n;
}
}
return a;
}
}
function _toPrimitive(t, r) {
if ("object" != typeof t || !t) return t;
var e = t[Symbol.toPrimitive];
if (void 0 !== e) {
var i = e.call(t, r || "default");
if ("object" != typeof i) return i;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === r ? String : Number)(t);
}
function _toPropertyKey(t) {
var i = _toPrimitive(t, "string");
return "symbol" == typeof i ? i : i + "";
}
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _defineProperty(obj, key, value) {
key = _toPropertyKey(key);
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function _inherits(subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function");
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
writable: true,
configurable: true
}
});
Object.defineProperty(subClass, "prototype", {
writable: false
});
if (superClass) _setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
};
return _getPrototypeOf(o);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _isNativeFunction(fn) {
try {
return Function.toString.call(fn).indexOf("[native code]") !== -1;
} catch (e) {
return typeof fn === "function";
}
}
function _wrapNativeSuper(Class) {
var _cache = typeof Map === "function" ? new Map() : undefined;
_wrapNativeSuper = function _wrapNativeSuper(Class) {
if (Class === null || !_isNativeFunction(Class)) return Class;
if (typeof Class !== "function") {
throw new TypeError("Super expression must either be null or a function");
}
if (typeof _cache !== "undefined") {
if (_cache.has(Class)) return _cache.get(Class);
_cache.set(Class, Wrapper);
}
function Wrapper() {
return _construct(Class, arguments, _getPrototypeOf(this).constructor);
}
Wrapper.prototype = Object.create(Class.prototype, {
constructor: {
value: Wrapper,
enumerable: false,
writable: true,
configurable: true
}
});
return _setPrototypeOf(Wrapper, Class);
};
return _wrapNativeSuper(Class);
}
function _assertThisInitialized(self) {
if (self === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
}
function _possibleConstructorReturn(self, call) {
if (call && (typeof call === "object" || typeof call === "function")) {
return call;
} else if (call !== void 0) {
throw new TypeError("Derived constructors may only return object or undefined");
}
return _assertThisInitialized(self);
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _createForOfIteratorHelper(o, allowArrayLike) {
var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
if (!it) {
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
if (it) o = it;
var i = 0;
var F = function () {};
return {
s: F,
n: function () {
if (i >= o.length) return {
done: true
};
return {
done: false,
value: o[i++]
};
},
e: function (e) {
throw e;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var normalCompletion = true,
didErr = false,
err;
return {
s: function () {
it = it.call(o);
},
n: function () {
var step = it.next();
normalCompletion = step.done;
return step;
},
e: function (e) {
didErr = true;
err = e;
},
f: function () {
try {
if (!normalCompletion && it.return != null) it.return();
} finally {
if (didErr) throw err;
}
}
};
}
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* Portions Copyright (C) Philipp Kewisch */
/**
* Represents the BINARY value type, which contains extra methods for encoding and decoding.
*
* @class
* @alias ICAL.Binary
*/
var Binary = /*#__PURE__*/function () {
/**
* Creates a new ICAL.Binary instance
*
* @param {String} aValue The binary data for this value
*/
function Binary(aValue) {
_classCallCheck(this, Binary);
/**
* The type name, to be used in the jCal object.
* @default "binary"
* @constant
*/
_defineProperty(this, "icaltype", "binary");
this.value = aValue;
}
return _createClass(Binary, [{
key: "decodeValue",
value:
/**
* Base64 decode the current value
*
* @return {String} The base64-decoded value
*/
function decodeValue() {
return this._b64_decode(this.value);
}
/**
* Encodes the passed parameter with base64 and sets the internal
* value to the result.
*
* @param {String} aValue The raw binary value to encode
*/
}, {
key: "setEncodedValue",
value: function setEncodedValue(aValue) {
this.value = this._b64_encode(aValue);
}
}, {
key: "_b64_encode",
value: function _b64_encode(data) {
// http://kevin.vanzonneveld.net
// + original by: Tyler Akins (http://rumkin.com)
// + improved by: Bayron Guevara
// + improved by: Thunder.m
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Pellentesque Malesuada
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Rafał Kukawski (http://kukawski.pl)
// * example 1: base64_encode('Kevin van Zonneveld');
// * returns 1: 'S2V2aW4gdmFuIFpvbm5ldmVsZA=='
// mozilla has this native
// - but breaks in 2.0.0.12!
//if (typeof this.window['atob'] == 'function') {
// return atob(data);
//}
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1,
o2,
o3,
h1,
h2,
h3,
h4,
bits,
i = 0,
ac = 0,
enc = "",
tmp_arr = [];
if (!data) {
return data;
}
do {
// pack three octets into four hexets
o1 = data.charCodeAt(i++);
o2 = data.charCodeAt(i++);
o3 = data.charCodeAt(i++);
bits = o1 << 16 | o2 << 8 | o3;
h1 = bits >> 18 & 0x3f;
h2 = bits >> 12 & 0x3f;
h3 = bits >> 6 & 0x3f;
h4 = bits & 0x3f;
// use hexets to index into b64, and append result to encoded string
tmp_arr[ac++] = b64.charAt(h1) + b64.charAt(h2) + b64.charAt(h3) + b64.charAt(h4);
} while (i < data.length);
enc = tmp_arr.join('');
var r = data.length % 3;
return (r ? enc.slice(0, r - 3) : enc) + '==='.slice(r || 3);
}
}, {
key: "_b64_decode",
value: function _b64_decode(data) {
// http://kevin.vanzonneveld.net
// + original by: Tyler Akins (http://rumkin.com)
// + improved by: Thunder.m
// + input by: Aman Gupta
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + bugfixed by: Onno Marsman
// + bugfixed by: Pellentesque Malesuada
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// * example 1: base64_decode('S2V2aW4gdmFuIFpvbm5ldmVsZA==');
// * returns 1: 'Kevin van Zonneveld'
// mozilla has this native
// - but breaks in 2.0.0.12!
//if (typeof this.window['btoa'] == 'function') {
// return btoa(data);
//}
var b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz0123456789+/=";
var o1,
o2,
o3,
h1,
h2,
h3,
h4,
bits,
i = 0,
ac = 0,
dec = "",
tmp_arr = [];
if (!data) {
return data;
}
data += '';
do {
// unpack four hexets into three octets using index points in b64
h1 = b64.indexOf(data.charAt(i++));
h2 = b64.indexOf(data.charAt(i++));
h3 = b64.indexOf(data.charAt(i++));
h4 = b64.indexOf(data.charAt(i++));
bits = h1 << 18 | h2 << 12 | h3 << 6 | h4;
o1 = bits >> 16 & 0xff;
o2 = bits >> 8 & 0xff;
o3 = bits & 0xff;
if (h3 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1);
} else if (h4 == 64) {
tmp_arr[ac++] = String.fromCharCode(o1, o2);
} else {
tmp_arr[ac++] = String.fromCharCode(o1, o2, o3);
}
} while (i < data.length);
dec = tmp_arr.join('');
return dec;
}
/**
* The string representation of this value
* @return {String}
*/
}, {
key: "toString",
value: function toString() {
return this.value;
}
}], [{
key: "fromString",
value:
/**
* Creates a binary value from the given string.
*
* @param {String} aString The binary value string
* @return {ICAL.Binary} The binary value instance
*/
function fromString(aString) {
return new Binary(aString);
}
}]);
}();
var DURATION_LETTERS = /([PDWHMTS]{1,1})/;
var DATA_PROPS_TO_COPY = ["weeks", "days", "hours", "minutes", "seconds", "isNegative"];
/**
* This class represents the "duration" value type, with various calculation
* and manipulation methods.
*
* @class
* @alias ICAL.Duration
*/
var Duration = /*#__PURE__*/function () {
/**
* Creates a new ICAL.Duration instance.
*
* @param {Object} data An object with members of the duration
* @param {Number} data.weeks Duration in weeks
* @param {Number} data.days Duration in days
* @param {Number} data.hours Duration in hours
* @param {Number} data.minutes Duration in minutes
* @param {Number} data.seconds Duration in seconds
* @param {Boolean} data.isNegative If true, the duration is negative
*/
function Duration(data) {
_classCallCheck(this, Duration);
/**
* The weeks in this duration
* @type {Number}
* @default 0
*/
_defineProperty(this, "weeks", 0);
/**
* The days in this duration
* @type {Number}
* @default 0
*/
_defineProperty(this, "days", 0);
/**
* The days in this duration
* @type {Number}
* @default 0
*/
_defineProperty(this, "hours", 0);
/**
* The minutes in this duration
* @type {Number}
* @default 0
*/
_defineProperty(this, "minutes", 0);
/**
* The seconds in this duration
* @type {Number}
* @default 0
*/
_defineProperty(this, "seconds", 0);
/**
* The seconds in this duration
* @type {Boolean}
* @default false
*/
_defineProperty(this, "isNegative", false);
/**
* The class identifier.
* @constant
* @type {String}
* @default "icalduration"
*/
_defineProperty(this, "icalclass", "icalduration");
/**
* The type name, to be used in the jCal object.
* @constant
* @type {String}
* @default "duration"
*/
_defineProperty(this, "icaltype", "duration");
this.wrappedJSObject = this;
this.fromData(data);
}
return _createClass(Duration, [{
key: "clone",
value:
/**
* Returns a clone of the duration object.
*
* @return {ICAL.Duration} The cloned object
*/
function clone() {
return Duration.fromData(this);
}
/**
* The duration value expressed as a number of seconds.
*
* @return {Number} The duration value in seconds
*/
}, {
key: "toSeconds",
value: function toSeconds() {
var seconds = this.seconds + 60 * this.minutes + 3600 * this.hours + 86400 * this.days + 7 * 86400 * this.weeks;
return this.isNegative ? -seconds : seconds;
}
/**
* Reads the passed seconds value into this duration object. Afterwards,
* members like {@link ICAL.Duration#days days} and {@link ICAL.Duration#weeks weeks} will be set up
* accordingly.
*
* @param {Number} aSeconds The duration value in seconds
* @return {ICAL.Duration} Returns this instance
*/
}, {
key: "fromSeconds",
value: function fromSeconds(aSeconds) {
var secs = Math.abs(aSeconds);
this.isNegative = aSeconds < 0;
this.days = trunc(secs / 86400);
// If we have a flat number of weeks, use them.
if (this.days % 7 == 0) {
this.weeks = this.days / 7;
this.days = 0;
} else {
this.weeks = 0;
}
secs -= (this.days + 7 * this.weeks) * 86400;
this.hours = trunc(secs / 3600);
secs -= this.hours * 3600;
this.minutes = trunc(secs / 60);
secs -= this.minutes * 60;
this.seconds = secs;
return this;
}
/**
* Sets up the current instance using members from the passed data object.
*
* @param {Object} aData An object with members of the duration
* @param {Number} aData.weeks Duration in weeks
* @param {Number} aData.days Duration in days
* @param {Number} aData.hours Duration in hours
* @param {Number} aData.minutes Duration in minutes
* @param {Number} aData.seconds Duration in seconds
* @param {Boolean} aData.isNegative If true, the duration is negative
*/
}, {
key: "fromData",
value: function fromData(aData) {
for (var _i = 0, _DATA_PROPS_TO_COPY = DATA_PROPS_TO_COPY; _i < _DATA_PROPS_TO_COPY.length; _i++) {
var prop = _DATA_PROPS_TO_COPY[_i];
if (aData && prop in aData) {
this[prop] = aData[prop];
} else {
this[prop] = 0;
}
}
}
/**
* Resets the duration instance to the default values, i.e. PT0S
*/
}, {
key: "reset",
value: function reset() {
this.isNegative = false;
this.weeks = 0;
this.days = 0;
this.hours = 0;
this.minutes = 0;
this.seconds = 0;
}
/**
* Compares the duration instance with another one.
*
* @param {ICAL.Duration} aOther The instance to compare with
* @return {Number} -1, 0 or 1 for less/equal/greater
*/
}, {
key: "compare",
value: function compare(aOther) {
var thisSeconds = this.toSeconds();
var otherSeconds = aOther.toSeconds();
return (thisSeconds > otherSeconds) - (thisSeconds < otherSeconds);
}
/**
* Normalizes the duration instance. For example, a duration with a value
* of 61 seconds will be normalized to 1 minute and 1 second.
*/
}, {
key: "normalize",
value: function normalize() {
this.fromSeconds(this.toSeconds());
}
/**
* The string representation of this duration.
* @return {String}
*/
}, {
key: "toString",
value: function toString() {
if (this.toSeconds() == 0) {
return "PT0S";
} else {
var str = "";
if (this.isNegative) str += "-";
str += "P";
if (this.weeks) str += this.weeks + "W";
if (this.days) str += this.days + "D";
if (this.hours || this.minutes || this.seconds) {
str += "T";
if (this.hours) str += this.hours + "H";
if (this.minutes) str += this.minutes + "M";
if (this.seconds) str += this.seconds + "S";
}
return str;
}
}
/**
* The iCalendar string representation of this duration.
* @return {String}
*/
}, {
key: "toICALString",
value: function toICALString() {
return this.toString();
}
}], [{
key: "fromSeconds",
value:
/**
* Returns a new ICAL.Duration instance from the passed seconds value.
*
* @param {Number} aSeconds The seconds to create the instance from
* @return {ICAL.Duration} The newly created duration instance
*/
function fromSeconds(aSeconds) {
return new Duration().fromSeconds(aSeconds);
}
/**
* Checks if the given string is an iCalendar duration value.
*
* @param {String} value The raw ical value
* @return {Boolean} True, if the given value is of the
* duration ical type
*/
}, {
key: "isValueString",
value: function isValueString(string) {
return string[0] === 'P' || string[1] === 'P';
}
/**
* Creates a new {@link ICAL.Duration} instance from the passed string.
*
* @param {String} aStr The string to parse
* @return {ICAL.Duration} The created duration instance
*/
}, {
key: "fromString",
value: function fromString(aStr) {
var pos = 0;
var dict = Object.create(null);
var chunks = 0;
while ((pos = aStr.search(DURATION_LETTERS)) !== -1) {
var type = aStr[pos];
var numeric = aStr.slice(0, Math.max(0, pos));
aStr = aStr.slice(pos + 1);
chunks += parseDurationChunk(type, numeric, dict);
}
if (chunks < 2) {
// There must be at least a chunk with "P" and some unit chunk
throw new Error('invalid duration value: Not enough duration components in "' + aStr + '"');
}
return new Duration(dict);
}
/**
* Creates a new ICAL.Duration instance from the given data object.
*
* @param {Object} aData An object with members of the duration
* @param {Number} aData.weeks Duration in weeks
* @param {Number} aData.days Duration in days
* @param {Number} aData.hours Duration in hours
* @param {Number} aData.minutes Duration in minutes
* @param {Number} aData.seconds Duration in seconds
* @param {Boolean} aData.isNegative If true, the duration is negative
* @return {ICAL.Duration} The createad duration instance
*/
}, {
key: "fromData",
value: function fromData(aData) {
return new Duration(aData);
}
}]);
}();
/**
* Internal helper function to handle a chunk of a duration.
*
* @private
* @param {String} letter type of duration chunk
* @param {String} number numeric value or -/+
* @param {Object} dict target to assign values to
*/
function parseDurationChunk(letter, number, object) {
var type;
switch (letter) {
case 'P':
if (number && number === '-') {
object.isNegative = true;
} else {
object.isNegative = false;
}
// period
break;
case 'D':
type = 'days';
break;
case 'W':
type = 'weeks';
break;
case 'H':
type = 'hours';
break;
case 'M':
type = 'minutes';
break;
case 'S':
type = 'seconds';
break;
default:
// Not a valid chunk
return 0;
}
if (type) {
if (!number && number !== 0) {
throw new Error('invalid duration value: Missing number before "' + letter + '"');
}
var num = parseInt(number, 10);
if (isStrictlyNaN(num)) {
throw new Error('invalid duration value: Invalid number "' + number + '" before "' + letter + '"');
}
object[type] = num;
}
return 1;
}
var _Time;
/**
* @classdesc
* iCalendar Time representation (similar to JS Date object). Fully
* independent of system (OS) timezone / time. Unlike JS Date, the month
* January is 1, not zero.
*
* @example
* var time = new ICAL.Time({
* year: 2012,
* month: 10,
* day: 11
* minute: 0,
* second: 0,
* isDate: false
* });
*
*
* @alias ICAL.Time
* @class
*/
var Time = /*#__PURE__*/function () {
// MONDAY
/**
* Creates a new ICAL.Time instance.
*
* @param {Object} data Time initialization
* @param {Number=} data.year The year for this date
* @param {Number=} data.month The month for this date
* @param {Number=} data.day The day for this date
* @param {Number=} data.hour The hour for this date
* @param {Number=} data.minute The minute for this date
* @param {Number=} data.second The second for this date
* @param {Boolean=} data.isDate If true, the instance represents a date (as
* opposed to a date-time)
* @param {ICAL.Timezone} zone timezone this position occurs in
*/
function Time(data, zone) {
_classCallCheck(this, Time);
/**
* The class identifier.
* @constant
* @type {String}
* @default "icaltime"
*/
_defineProperty(this, "icalclass", "icaltime");
_defineProperty(this, "_cachedUnixTime", null);
/**
* The timezone for this time.
* @type {ICAL.Timezone}
*/
_defineProperty(this, "zone", null);
/**
* Internal uses to indicate that a change has been made and the next read
* operation must attempt to normalize the value (for example changing the
* day to 33).
*
* @type {Boolean}
* @private
*/
_defineProperty(this, "_pendingNormalization", false);
this.wrappedJSObject = this;
var time = this._time = Object.create(null);
/* time defaults */
time.year = 0;
time.month = 1;
time.day = 1;
time.hour = 0;
time.minute = 0;
time.second = 0;
time.isDate = false;
this.fromData(data, zone);
}
return _createClass(Time, [{
key: "icaltype",
get:
/**
* The type name, to be used in the jCal object. This value may change and
* is strictly defined by the {@link ICAL.Time#isDate isDate} member.
* @readonly
* @type {String}
* @default "date-time"
*/
function get() {
return this.isDate ? 'date' : 'date-time';
}
}, {
key: "clone",
value:
/**
* Returns a clone of the time object.
*
* @return {ICAL.Time} The cloned object
*/
function clone() {
return new Time(this._time, this.zone);
}
/**
* Reset the time instance to epoch time
*/
}, {
key: "reset",
value: function reset() {
this.fromData(Time.epochTime);
this.zone = Timezone.utcTimezone;
}
/**
* Reset the time instance to the given date/time values.
*
* @param {Number} year The year to set
* @param {Number} month The month to set
* @param {Number} day The day to set
* @param {Number} hour The hour to set
* @param {Number} minute The minute to set
* @param {Number} second The second to set
* @param {ICAL.Timezone} timezone The timezone to set
*/
}, {
key: "resetTo",
value: function resetTo(year, month, day, hour, minute, second, timezone) {
this.fromData({
year: year,
month: month,
day: day,
hour: hour,
minute: minute,
second: second,
zone: timezone
});
}
/**
* Set up the current instance from the Javascript date value.
*
* @param {?Date} aDate The Javascript Date to read, or null to reset
* @param {Boolean} useUTC If true, the UTC values of the date will be used
*/
}, {
key: "fromJSDate",
value: function fromJSDate(aDate, useUTC) {
if (!aDate) {
this.reset();
} else {
if (useUTC) {
this.zone = Timezone.utcTimezone;
this.year = aDate.getUTCFullYear();
this.month = aDate.getUTCMonth() + 1;
this.day = aDate.getUTCDate();
this.hour = aDate.getUTCHours();
this.minute = aDate.getUTCMinutes();
this.second = aDate.getUTCSeconds();
} else {
this.zone = Timezone.localTimezone;
this.year = aDate.getFullYear();
this.month = aDate.getMonth() + 1;
this.day = aDate.getDate();
this.hour = aDate.getHours();
this.minute = aDate.getMinutes();
this.second = aDate.getSeconds();
}
}
this._cachedUnixTime = null;
return this;
}
/**
* Sets up the current instance using members from the passed data object.
*
* @param {Object} aData Time initialization
* @param {Number=} aData.year The year for this date
* @param {Number=} aData.month The month for this date
* @param {Number=} aData.day The day for this date
* @param {Number=} aData.hour The hour for this date
* @param {Number=} aData.minute The minute for this date
* @param {Number=} aData.second The second for this date
* @param {Boolean=} aData.isDate If true, the instance represents a date
* (as opposed to a date-time)
* @param {ICAL.Timezone=} aZone Timezone this position occurs in
*/
}, {
key: "fromData",
value: function fromData(aData, aZone) {
if (aData) {
for (var _i = 0, _Object$entries = Object.entries(aData); _i < _Object$entries.length; _i++) {
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
key = _Object$entries$_i[0],
value = _Object$entries$_i[1];
// ical type cannot be set
if (key === 'icaltype') continue;
this[key] = value;
}
}
if (aZone) {