iamcal 2.1.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/component.d.ts +25 -4
- package/lib/component.d.ts.map +1 -1
- package/lib/component.js +60 -51
- package/lib/components/Calendar.d.ts +0 -20
- package/lib/components/Calendar.d.ts.map +1 -1
- package/lib/components/Calendar.js +2 -24
- package/lib/components/CalendarEvent.d.ts +1 -25
- package/lib/components/CalendarEvent.d.ts.map +1 -1
- package/lib/components/CalendarEvent.js +4 -29
- package/lib/components/TimeZone.d.ts +0 -38
- package/lib/components/TimeZone.d.ts.map +1 -1
- package/lib/components/TimeZone.js +1 -40
- package/lib/components/TimeZoneOffset.d.ts +0 -28
- package/lib/components/TimeZoneOffset.d.ts.map +1 -1
- package/lib/components/TimeZoneOffset.js +1 -30
- package/lib/date.d.ts +2 -10
- package/lib/date.d.ts.map +1 -1
- package/lib/date.js +15 -20
- package/lib/parse.d.ts +9 -16
- package/lib/parse.d.ts.map +1 -1
- package/lib/parse.js +188 -35
- package/lib/patterns.d.ts +28 -0
- package/lib/patterns.d.ts.map +1 -1
- package/lib/patterns.js +56 -2
- package/lib/property/Property.d.ts +344 -0
- package/lib/property/Property.d.ts.map +1 -0
- package/lib/property/Property.js +508 -0
- package/lib/property/escape.d.ts +46 -0
- package/lib/property/escape.d.ts.map +1 -0
- package/lib/property/escape.js +101 -0
- package/lib/property/index.d.ts +7 -0
- package/lib/property/index.d.ts.map +1 -0
- package/lib/property/index.js +23 -0
- package/lib/property/names.d.ts +11 -0
- package/lib/property/names.d.ts.map +1 -0
- package/lib/property/names.js +62 -0
- package/lib/property/parameter.d.ts +10 -0
- package/lib/property/parameter.d.ts.map +1 -0
- package/lib/property/parameter.js +3 -0
- package/lib/{property.d.ts → property/validate.d.ts} +9 -35
- package/lib/property/validate.d.ts.map +1 -0
- package/lib/property/validate.js +317 -0
- package/lib/property/valueType.d.ts +18 -0
- package/lib/property/valueType.d.ts.map +1 -0
- package/lib/property/valueType.js +82 -0
- package/package.json +3 -1
- package/src/component.ts +58 -52
- package/src/components/Calendar.ts +6 -30
- package/src/components/CalendarEvent.ts +7 -33
- package/src/components/TimeZone.ts +3 -51
- package/src/components/TimeZoneOffset.ts +5 -40
- package/src/date.ts +14 -30
- package/src/parse.ts +212 -40
- package/src/patterns.ts +64 -0
- package/src/property/Property.ts +609 -0
- package/src/property/escape.ts +102 -0
- package/src/property/index.ts +6 -0
- package/src/property/names.ts +65 -0
- package/src/property/parameter.ts +33 -0
- package/src/{property.ts → property/validate.ts} +23 -204
- package/src/property/valueType.ts +87 -0
- package/lib/property.d.ts.map +0 -1
- package/lib/property.js +0 -450
package/src/component.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { CalendarDateOrTime } from './date'
|
|
2
|
+
import { Property } from './property/Property'
|
|
3
|
+
import type { AllowedPropertyName, KnownPropertyName } from './property/names'
|
|
2
4
|
import {
|
|
3
|
-
AllowedPropertyName,
|
|
4
|
-
KnownPropertyName,
|
|
5
5
|
MissingPropertyError,
|
|
6
|
-
Property,
|
|
7
6
|
PropertyValidationError,
|
|
8
7
|
validateProperty,
|
|
9
|
-
} from './property'
|
|
8
|
+
} from './property/validate'
|
|
10
9
|
|
|
11
|
-
/**
|
|
10
|
+
/**
|
|
11
|
+
* Represents an error which occurs while validating a calendar component.
|
|
12
|
+
*/
|
|
12
13
|
export class ComponentValidationError extends Error {
|
|
13
14
|
constructor(message: string) {
|
|
14
15
|
super(message)
|
|
@@ -16,9 +17,16 @@ export class ComponentValidationError extends Error {
|
|
|
16
17
|
}
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Represents an error which occurs when trying to perform an operation which
|
|
22
|
+
* would break the state of a calendar component.
|
|
23
|
+
*/
|
|
24
|
+
export class IllegalOperationError extends Error {
|
|
25
|
+
constructor(message: string) {
|
|
26
|
+
super(message)
|
|
27
|
+
this.name = 'IllegalOperationError'
|
|
28
|
+
}
|
|
29
|
+
}
|
|
22
30
|
export class Component {
|
|
23
31
|
name: string
|
|
24
32
|
properties: Property[]
|
|
@@ -31,7 +39,10 @@ export class Component {
|
|
|
31
39
|
) {
|
|
32
40
|
this.name = name
|
|
33
41
|
if (properties) {
|
|
34
|
-
this.properties =
|
|
42
|
+
this.properties = []
|
|
43
|
+
properties.forEach(property => {
|
|
44
|
+
this.addProperty(property)
|
|
45
|
+
})
|
|
35
46
|
} else {
|
|
36
47
|
this.properties = []
|
|
37
48
|
}
|
|
@@ -47,17 +58,7 @@ export class Component {
|
|
|
47
58
|
const lines = [`BEGIN:${this.name}`]
|
|
48
59
|
|
|
49
60
|
for (const property of this.properties) {
|
|
50
|
-
|
|
51
|
-
property['name'] + //
|
|
52
|
-
property.params.map(p => ';' + p).join('') +
|
|
53
|
-
':' +
|
|
54
|
-
property['value']
|
|
55
|
-
|
|
56
|
-
// Wrap lines
|
|
57
|
-
while (line.length > MAX_LINE_LENGTH) {
|
|
58
|
-
lines.push(line.substring(0, MAX_LINE_LENGTH))
|
|
59
|
-
line = ' ' + line.substring(MAX_LINE_LENGTH)
|
|
60
|
-
}
|
|
61
|
+
const line = property.serialize()
|
|
61
62
|
lines.push(line)
|
|
62
63
|
}
|
|
63
64
|
|
|
@@ -84,29 +85,52 @@ export class Component {
|
|
|
84
85
|
|
|
85
86
|
setProperty(name: string, value: string | CalendarDateOrTime): this {
|
|
86
87
|
for (const property of this.properties) {
|
|
87
|
-
if (property.name
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const prop = value.toProperty(name)
|
|
92
|
-
property.params = prop.params
|
|
93
|
-
property.value = prop.value
|
|
94
|
-
}
|
|
88
|
+
if (property.name !== name) continue
|
|
89
|
+
|
|
90
|
+
if (typeof value === 'string') {
|
|
91
|
+
property.value = value
|
|
95
92
|
return this
|
|
96
93
|
}
|
|
94
|
+
|
|
95
|
+
const dateProperty = Property.fromDate(name, value)
|
|
96
|
+
|
|
97
|
+
// Update value type
|
|
98
|
+
if (dateProperty.getValueType() === 'DATE')
|
|
99
|
+
property.setValueType('DATE')
|
|
100
|
+
else property.removeValueType()
|
|
101
|
+
|
|
102
|
+
// Update value
|
|
103
|
+
property.value = dateProperty.value
|
|
104
|
+
|
|
105
|
+
return this
|
|
97
106
|
}
|
|
107
|
+
// Property is new
|
|
98
108
|
this.properties.push(
|
|
99
109
|
typeof value === 'string'
|
|
100
|
-
?
|
|
101
|
-
|
|
102
|
-
params: [],
|
|
103
|
-
value: value,
|
|
104
|
-
}
|
|
105
|
-
: value.toProperty(name)
|
|
110
|
+
? new Property(name, value)
|
|
111
|
+
: Property.fromDate(name, value)
|
|
106
112
|
)
|
|
107
113
|
return this
|
|
108
114
|
}
|
|
109
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Add a property to this component.
|
|
118
|
+
* @param property The property to add.
|
|
119
|
+
* @returns This component for chaining.
|
|
120
|
+
* @throws {IllegalOperationError} If the property cannot be added to this component.
|
|
121
|
+
*/
|
|
122
|
+
addProperty(property: Property): this {
|
|
123
|
+
// TODO: Validate if property can be added to this component.
|
|
124
|
+
this.properties.push(property)
|
|
125
|
+
return this
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Check whether this component has a certain property.
|
|
130
|
+
* @param name The property name to check.
|
|
131
|
+
* @param value An optional value to check against the property. If this is specified the property value must equal this value.
|
|
132
|
+
* @returns Whether the property is present and matches the value if given.
|
|
133
|
+
*/
|
|
110
134
|
hasProperty(name: string, value?: string): boolean {
|
|
111
135
|
for (const property of this.properties) {
|
|
112
136
|
if (
|
|
@@ -126,24 +150,6 @@ export class Component {
|
|
|
126
150
|
this.properties.splice(index, 1)
|
|
127
151
|
}
|
|
128
152
|
|
|
129
|
-
getPropertyParams(name: string): string[] | null {
|
|
130
|
-
for (const property of this.properties) {
|
|
131
|
-
if (property.name === name) {
|
|
132
|
-
return property.params
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return null
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
setPropertyParams(name: string, params: string[]): this {
|
|
139
|
-
for (const property of this.properties) {
|
|
140
|
-
if (property.name === name) {
|
|
141
|
-
property.params = params
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
return this
|
|
145
|
-
}
|
|
146
|
-
|
|
147
153
|
addComponent(component: Component): this {
|
|
148
154
|
this.components.push(component)
|
|
149
155
|
return this
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KnownPropertyName } from '../property'
|
|
1
|
+
import { KnownPropertyName } from '../property/names'
|
|
2
2
|
import { Component, ComponentValidationError } from '../component'
|
|
3
3
|
import { CalendarEvent } from './CalendarEvent'
|
|
4
4
|
|
|
@@ -27,13 +27,13 @@ export class Calendar extends Component {
|
|
|
27
27
|
* @param component A VCALENDAR component.
|
|
28
28
|
*/
|
|
29
29
|
constructor(component: Component)
|
|
30
|
-
constructor(a
|
|
30
|
+
constructor(a: string | Component, b?: string) {
|
|
31
31
|
let component: Component
|
|
32
32
|
if (a instanceof Component) {
|
|
33
|
-
component = a
|
|
33
|
+
component = a
|
|
34
34
|
Calendar.prototype.validate.call(component)
|
|
35
35
|
} else {
|
|
36
|
-
const prodid = a
|
|
36
|
+
const prodid = a
|
|
37
37
|
const version = (b as string) ?? '2.0'
|
|
38
38
|
component = new Component('VCALENDAR')
|
|
39
39
|
component.setProperty('PRODID', prodid)
|
|
@@ -61,10 +61,9 @@ export class Calendar extends Component {
|
|
|
61
61
|
removeEvent(uid: string): boolean
|
|
62
62
|
removeEvent(a: CalendarEvent | string): boolean {
|
|
63
63
|
if (a instanceof CalendarEvent) {
|
|
64
|
-
|
|
65
|
-
return this.removeComponent(event)
|
|
64
|
+
return this.removeComponent(a)
|
|
66
65
|
} else {
|
|
67
|
-
const uid = a
|
|
66
|
+
const uid = a
|
|
68
67
|
for (const event of this.getEvents()) {
|
|
69
68
|
if (event.getUid() !== uid) continue
|
|
70
69
|
return this.removeComponent(event)
|
|
@@ -136,27 +135,4 @@ export class Calendar extends Component {
|
|
|
136
135
|
removeCalendarDescription() {
|
|
137
136
|
this.removePropertiesWithName('X-WR-CALDESC')
|
|
138
137
|
}
|
|
139
|
-
|
|
140
|
-
/* eslint-disable */
|
|
141
|
-
|
|
142
|
-
/** @deprecated use {@link getEvents} instead */
|
|
143
|
-
events = this.getEvents
|
|
144
|
-
/** @deprecated use {@link getProductId} instead */
|
|
145
|
-
prodId = this.getProductId
|
|
146
|
-
/** @deprecated use {@link setProductId} instead */
|
|
147
|
-
setProdId = this.setProductId
|
|
148
|
-
/** @deprecated use {@link getVersion} instead */
|
|
149
|
-
version = this.getVersion
|
|
150
|
-
/** @deprecated use {@link getCalendarScale} instead */
|
|
151
|
-
calScale = this.getCalendarScale
|
|
152
|
-
/** @deprecated use {@link setCalendarScale} instead */
|
|
153
|
-
setCalScale = this.setCalendarScale
|
|
154
|
-
/** @deprecated use {@link removeCalendarScale} instead */
|
|
155
|
-
removeCalScale = this.removeCalendarScale
|
|
156
|
-
/** @deprecated use {@link getMethod} instead */
|
|
157
|
-
method = this.getMethod
|
|
158
|
-
/** @deprecated use {@link getCalendarName} instead */
|
|
159
|
-
calendarName = this.getCalendarName
|
|
160
|
-
/** @deprecated use {@link getCalendarDescription} instead */
|
|
161
|
-
calendarDescription = this.getCalendarDescription
|
|
162
138
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentValidationError, Component } from '../component'
|
|
1
|
+
import { Component, ComponentValidationError } from '../component'
|
|
3
2
|
import {
|
|
3
|
+
CalendarDateOrTime,
|
|
4
4
|
CalendarDateTime,
|
|
5
5
|
convertDate,
|
|
6
|
-
CalendarDateOrTime,
|
|
7
6
|
parseDateProperty,
|
|
8
7
|
toDateTimeString,
|
|
9
8
|
} from '../date'
|
|
9
|
+
import { KnownPropertyName } from '../property/names'
|
|
10
|
+
import { PropertyValidationError } from '../property/validate'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Represents a VEVENT component, representing an event in a calendar.
|
|
@@ -27,10 +28,10 @@ export class CalendarEvent extends Component {
|
|
|
27
28
|
) {
|
|
28
29
|
let component: Component
|
|
29
30
|
if (a instanceof Component) {
|
|
30
|
-
component = a
|
|
31
|
+
component = a
|
|
31
32
|
CalendarEvent.prototype.validate.call(component)
|
|
32
33
|
} else {
|
|
33
|
-
const uid = a
|
|
34
|
+
const uid = a
|
|
34
35
|
const dtstamp = convertDate(b!, false)
|
|
35
36
|
const dtstart = convertDate(c!)
|
|
36
37
|
component = new Component('VEVENT')
|
|
@@ -42,7 +43,7 @@ export class CalendarEvent extends Component {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
serialize(): string {
|
|
45
|
-
if (!this.getEnd() && !this.
|
|
46
|
+
if (!this.getEnd() && !this.getDuration()) {
|
|
46
47
|
throw new Error(
|
|
47
48
|
'Failed to serialize calendar event, end or duration must be set'
|
|
48
49
|
)
|
|
@@ -240,31 +241,4 @@ export class CalendarEvent extends Component {
|
|
|
240
241
|
removeGeographicLocation() {
|
|
241
242
|
this.removePropertiesWithName('GEO')
|
|
242
243
|
}
|
|
243
|
-
|
|
244
|
-
/* eslint-disable */
|
|
245
|
-
|
|
246
|
-
/** @deprecated use {@link getStamp} instead */
|
|
247
|
-
stamp = this.getStamp
|
|
248
|
-
/** @deprecated use {@link getUid} instead */
|
|
249
|
-
uid = this.getUid
|
|
250
|
-
/** @deprecated use {@link getSummary} instead */
|
|
251
|
-
summary = this.getSummary
|
|
252
|
-
/** @deprecated use {@link getDescription} instead */
|
|
253
|
-
description = this.getDescription
|
|
254
|
-
/** @deprecated use {@link getLocation} instead */
|
|
255
|
-
location = this.getLocation
|
|
256
|
-
/** @deprecated use {@link getStart} instead */
|
|
257
|
-
start = this.getStart
|
|
258
|
-
/** @deprecated use {@link getEnd} instead */
|
|
259
|
-
end = this.getEnd
|
|
260
|
-
/** @deprecated use {@link getDuration} instead */
|
|
261
|
-
duration = this.getDuration
|
|
262
|
-
/** @deprecated use {@link getCreated} instead */
|
|
263
|
-
created = this.getCreated
|
|
264
|
-
/** @deprecated use {@link getGeographicPosition} instead */
|
|
265
|
-
geo = this.getGeographicPosition
|
|
266
|
-
/** @deprecated use {@link setGeographicPosition} instead */
|
|
267
|
-
setGeo = this.setGeographicPosition
|
|
268
|
-
/** @deprecated use {@link removeGeographicLocation} instead */
|
|
269
|
-
removeGeo = this.removeGeographicLocation
|
|
270
244
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component, ComponentValidationError } from '../component'
|
|
2
2
|
import { CalendarDateOrTime, parseDateProperty } from '../date'
|
|
3
|
-
import { KnownPropertyName } from '../property'
|
|
3
|
+
import { KnownPropertyName } from '../property/names'
|
|
4
4
|
import { TimeZoneOffset } from './TimeZoneOffset'
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -14,10 +14,10 @@ export class TimeZone extends Component {
|
|
|
14
14
|
constructor(a: string | Component) {
|
|
15
15
|
let component: Component
|
|
16
16
|
if (a instanceof Component) {
|
|
17
|
-
component = a
|
|
17
|
+
component = a
|
|
18
18
|
TimeZone.prototype.validate.call(component)
|
|
19
19
|
} else {
|
|
20
|
-
const tzid = a
|
|
20
|
+
const tzid = a
|
|
21
21
|
component = new Component('VTIMEZONE')
|
|
22
22
|
component.setProperty('TZID', tzid)
|
|
23
23
|
}
|
|
@@ -101,52 +101,4 @@ export class TimeZone extends Component {
|
|
|
101
101
|
c => new TimeZoneOffset(c)
|
|
102
102
|
)
|
|
103
103
|
}
|
|
104
|
-
|
|
105
|
-
/* eslint-disable */
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* @deprecated Use {@link getId} instead.
|
|
109
|
-
*/
|
|
110
|
-
id = this.getId
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* @deprecated Use {@link getLastModified} instead.
|
|
114
|
-
*/
|
|
115
|
-
lastMod = this.getLastModified
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* @deprecated Use {@link setLastModified} instead.
|
|
119
|
-
*/
|
|
120
|
-
setLastMod = this.setLastModified
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @deprecated Use {@link removeLastModified} instead.
|
|
124
|
-
*/
|
|
125
|
-
removeLastMod = this.removeLastModified
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* @deprecated Use {@link getUrl} instead.
|
|
129
|
-
*/
|
|
130
|
-
url = this.getUrl
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Get all time offsets.
|
|
134
|
-
* @returns An array of time zone offsets defined in this time zone.
|
|
135
|
-
* @deprecated Use {@link getOffsets} instead.
|
|
136
|
-
*/
|
|
137
|
-
offsets = this.getOffsets
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Get standard/winter time offsets.
|
|
141
|
-
* @returns An array of time zone offsets defined in this time zone that are of type STANDARD.
|
|
142
|
-
* @deprecated Use {@link getStandardOffsets} instead.
|
|
143
|
-
*/
|
|
144
|
-
standardOffsets = this.getStandardOffsets
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Get daylight savings time offsets.
|
|
148
|
-
* @returns An array of time zone offsets defined in this time zone that are of type DAYLIGHT.
|
|
149
|
-
* @deprecated Use {@link getDaylightOffsets} instead.
|
|
150
|
-
*/
|
|
151
|
-
daylightOffsets = this.getDaylightOffsets
|
|
152
104
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Component, ComponentValidationError } from '../component'
|
|
2
2
|
import { CalendarDateOrTime, convertDate, parseDateProperty } from '../date'
|
|
3
|
-
import { AllowedPropertyName } from '../property'
|
|
3
|
+
import { AllowedPropertyName } from '../property/names'
|
|
4
4
|
|
|
5
5
|
export const knownOffsetTypes = ['DAYLIGHT', 'STANDARD']
|
|
6
6
|
export type OffsetType = (typeof knownOffsetTypes)[number]
|
|
@@ -32,13 +32,13 @@ export class TimeZoneOffset extends Component {
|
|
|
32
32
|
) {
|
|
33
33
|
let component: Component
|
|
34
34
|
if (a instanceof Component) {
|
|
35
|
-
component = a
|
|
35
|
+
component = a
|
|
36
36
|
TimeZoneOffset.prototype.validate.call(component)
|
|
37
37
|
} else {
|
|
38
|
-
const name = a
|
|
38
|
+
const name: OffsetType = a
|
|
39
39
|
const start = convertDate(b!)
|
|
40
|
-
const offsetFrom = c
|
|
41
|
-
const offsetTo = d
|
|
40
|
+
const offsetFrom = c!
|
|
41
|
+
const offsetTo = d!
|
|
42
42
|
component = new Component(name)
|
|
43
43
|
component.setProperty('DTSTART', start)
|
|
44
44
|
component.setProperty('TZOFFSETFROM', offsetFrom)
|
|
@@ -149,39 +149,4 @@ export class TimeZoneOffset extends Component {
|
|
|
149
149
|
removeTimeZoneName() {
|
|
150
150
|
this.removePropertiesWithName('TZNAME')
|
|
151
151
|
}
|
|
152
|
-
|
|
153
|
-
/* eslint-disable */
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get the date or time when this time zone offset starts.
|
|
157
|
-
* @returns The start date or time of this time zone offset.
|
|
158
|
-
* @deprecated Use {@link getStart} instead.
|
|
159
|
-
*/
|
|
160
|
-
start = this.getStart
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Get the offset which is offset from during this time zone offset.
|
|
164
|
-
* @returns The offset in a format such as "+0100" or "-0230".
|
|
165
|
-
* @deprecated Use {@link getOffsetFrom} instead.
|
|
166
|
-
*/
|
|
167
|
-
offsetFrom = this.getOffsetFrom
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Get the offset which is offset to during this time zone offset.
|
|
171
|
-
* @returns The offset in a format such as "+0100" or "-0230".
|
|
172
|
-
* @deprecated Use {@link getOffsetTo} instead.
|
|
173
|
-
*/
|
|
174
|
-
offsetTo = this.getOffsetTo
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @deprecated Use {@link getComment} instead.
|
|
178
|
-
*/
|
|
179
|
-
comment = this.getComment
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Get the name of this time zone offset.
|
|
183
|
-
* @returns The time zone offset name if it exists.
|
|
184
|
-
* @deprecated Use {@link getTimeZoneName} instead.
|
|
185
|
-
*/
|
|
186
|
-
timeZoneName = this.getTimeZoneName
|
|
187
152
|
}
|
package/src/date.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as patterns from './patterns'
|
|
2
|
-
import {
|
|
2
|
+
import { Property } from './property/Property'
|
|
3
3
|
|
|
4
4
|
export const ONE_SECOND_MS = 1000
|
|
5
5
|
export const ONE_MINUTE_MS = 60 * ONE_SECOND_MS
|
|
@@ -7,12 +7,6 @@ export const ONE_HOUR_MS = 60 * ONE_MINUTE_MS
|
|
|
7
7
|
export const ONE_DAY_MS = 24 * ONE_HOUR_MS
|
|
8
8
|
|
|
9
9
|
export interface CalendarDateOrTime {
|
|
10
|
-
/**
|
|
11
|
-
* Create a property from this date.
|
|
12
|
-
* @param name The name of the property.
|
|
13
|
-
*/
|
|
14
|
-
toProperty(name: string): Property
|
|
15
|
-
|
|
16
10
|
/**
|
|
17
11
|
* Get the string value of this date.
|
|
18
12
|
* @returns An iCalendar date or date-time string.
|
|
@@ -62,14 +56,6 @@ export class CalendarDate implements CalendarDateOrTime {
|
|
|
62
56
|
this.date.setHours(0, 0, 0, 0)
|
|
63
57
|
}
|
|
64
58
|
|
|
65
|
-
toProperty(name: string): Property {
|
|
66
|
-
return {
|
|
67
|
-
name,
|
|
68
|
-
params: ['VALUE=DATE'],
|
|
69
|
-
value: this.getValue(),
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
59
|
getValue(): string {
|
|
74
60
|
return toDateString(this.date)
|
|
75
61
|
}
|
|
@@ -106,14 +92,6 @@ export class CalendarDateTime implements CalendarDateOrTime {
|
|
|
106
92
|
}
|
|
107
93
|
}
|
|
108
94
|
|
|
109
|
-
toProperty(name: string): Property {
|
|
110
|
-
return {
|
|
111
|
-
name,
|
|
112
|
-
params: [],
|
|
113
|
-
value: this.getValue(),
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
95
|
getValue(): string {
|
|
118
96
|
return toDateTimeString(this.date)
|
|
119
97
|
}
|
|
@@ -208,24 +186,30 @@ export function padSeconds(seconds: number): string {
|
|
|
208
186
|
/**
|
|
209
187
|
* Parse a date property into a {@link CalendarDateOrTime}.
|
|
210
188
|
* @param dateProperty The property to parse.
|
|
211
|
-
* @param defaultType The default value type to be used if the property does not have an explicit value type.
|
|
212
189
|
* @returns The parsed date as a {@link CalendarDateOrTime}.
|
|
213
190
|
* @throws If the value is invalid for the value type.
|
|
214
191
|
* @throws If the value type is not `DATE-TIME` or `DATE`.
|
|
215
192
|
*/
|
|
216
|
-
export function parseDateProperty(
|
|
217
|
-
dateProperty: Property,
|
|
218
|
-
defaultType: 'DATE-TIME' | 'DATE' = 'DATE-TIME'
|
|
219
|
-
): CalendarDateOrTime {
|
|
193
|
+
export function parseDateProperty(dateProperty: Property): CalendarDateOrTime {
|
|
220
194
|
const value = dateProperty.value
|
|
221
|
-
const valueType =
|
|
195
|
+
const valueType = dateProperty.getValueType()
|
|
222
196
|
|
|
223
197
|
if (valueType === 'DATE-TIME') {
|
|
224
198
|
return new CalendarDateTime(value)
|
|
225
199
|
} else if (valueType === 'DATE') {
|
|
226
200
|
return new CalendarDate(value)
|
|
227
201
|
} else {
|
|
228
|
-
|
|
202
|
+
const explicitValueType = dateProperty.hasValueType()
|
|
203
|
+
if (explicitValueType)
|
|
204
|
+
throw new Error(`Illegal value type for date '${valueType}'`)
|
|
205
|
+
else {
|
|
206
|
+
// Infer type based on shape
|
|
207
|
+
try {
|
|
208
|
+
return new CalendarDateTime(value)
|
|
209
|
+
} catch {
|
|
210
|
+
return new CalendarDate(value)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
229
213
|
}
|
|
230
214
|
}
|
|
231
215
|
|