iamcal 1.1.1 → 2.1.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/README.md +47 -11
- package/lib/component.d.ts +62 -0
- package/lib/component.d.ts.map +1 -0
- package/lib/component.js +208 -0
- package/lib/components/Calendar.d.ts +66 -0
- package/lib/components/Calendar.d.ts.map +1 -0
- package/lib/components/Calendar.js +121 -0
- package/lib/components/CalendarEvent.d.ts +109 -0
- package/lib/components/CalendarEvent.d.ts.map +1 -0
- package/lib/components/CalendarEvent.js +223 -0
- package/lib/components/TimeZone.d.ts +74 -0
- package/lib/components/TimeZone.d.ts.map +1 -0
- package/lib/components/TimeZone.js +127 -0
- package/lib/components/TimeZoneOffset.d.ts +103 -0
- package/lib/components/TimeZoneOffset.d.ts.map +1 -0
- package/lib/components/TimeZoneOffset.js +148 -0
- package/lib/components/index.d.ts +5 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +21 -0
- package/lib/date.d.ts +165 -0
- package/lib/date.d.ts.map +1 -0
- package/lib/date.js +373 -0
- package/lib/index.d.ts +6 -153
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +21 -469
- package/lib/io.d.ts +10 -8
- package/lib/io.d.ts.map +1 -1
- package/lib/io.js +18 -13
- package/lib/parse.d.ts +33 -16
- package/lib/parse.d.ts.map +1 -1
- package/lib/parse.js +59 -56
- package/lib/patterns.d.ts +36 -0
- package/lib/patterns.d.ts.map +1 -0
- package/lib/patterns.js +50 -0
- package/lib/property.d.ts +149 -0
- package/lib/property.d.ts.map +1 -0
- package/lib/property.js +450 -0
- package/package.json +48 -43
- package/src/component.ts +248 -0
- package/src/components/Calendar.ts +162 -0
- package/src/components/CalendarEvent.ts +270 -0
- package/src/components/TimeZone.ts +152 -0
- package/src/components/TimeZoneOffset.ts +187 -0
- package/src/components/index.ts +4 -0
- package/src/date.ts +395 -0
- package/src/index.ts +6 -576
- package/src/io.ts +17 -13
- package/src/parse.ts +72 -52
- package/src/patterns.ts +69 -0
- package/src/property.ts +492 -0
- package/lib/types.d.ts +0 -6
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js +0 -3
- package/src/types.ts +0 -5
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { Component, ComponentValidationError } from '../component'
|
|
2
|
+
import { CalendarDateOrTime, parseDateProperty } from '../date'
|
|
3
|
+
import { KnownPropertyName } from '../property'
|
|
4
|
+
import { TimeZoneOffset } from './TimeZoneOffset'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a VTIMEZONE component, containing time zone definitions.
|
|
8
|
+
*/
|
|
9
|
+
export class TimeZone extends Component {
|
|
10
|
+
name = 'VTIMEZONE'
|
|
11
|
+
|
|
12
|
+
constructor(id: string)
|
|
13
|
+
constructor(component: Component)
|
|
14
|
+
constructor(a: string | Component) {
|
|
15
|
+
let component: Component
|
|
16
|
+
if (a instanceof Component) {
|
|
17
|
+
component = a as Component
|
|
18
|
+
TimeZone.prototype.validate.call(component)
|
|
19
|
+
} else {
|
|
20
|
+
const tzid = a as string
|
|
21
|
+
component = new Component('VTIMEZONE')
|
|
22
|
+
component.setProperty('TZID', tzid)
|
|
23
|
+
}
|
|
24
|
+
super(component.name, component.properties, component.components)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
validate() {
|
|
28
|
+
if (this.name !== 'VTIMEZONE')
|
|
29
|
+
throw new ComponentValidationError('Component name must be VEVENT')
|
|
30
|
+
const requiredProperties: KnownPropertyName[] = ['TZID']
|
|
31
|
+
this.validateAllProperties(requiredProperties)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
getId(): string {
|
|
35
|
+
return this.getProperty('TZID')!.value
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
setId(value: string): this {
|
|
39
|
+
return this.setProperty('TZID', value)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
getLastModified(): CalendarDateOrTime | undefined {
|
|
43
|
+
const text = this.getProperty('LAST-MODIFIED')
|
|
44
|
+
if (!text) return
|
|
45
|
+
return parseDateProperty(text)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setLastModified(value: Date): this {
|
|
49
|
+
return this.setProperty('LAST-MODIFIED', value.toISOString())
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
removeLastModified() {
|
|
53
|
+
this.removePropertiesWithName('LAST-MOD')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
getUrl(): string | undefined {
|
|
57
|
+
return this.getProperty('TZURL')?.value
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
setUrl(value: string): this {
|
|
61
|
+
return this.setProperty('TZURL', value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
removeUrl() {
|
|
65
|
+
this.removePropertiesWithName('TZURL')
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Get all time offsets.
|
|
70
|
+
* @returns An array of time zone offsets defined in this time zone.
|
|
71
|
+
*/
|
|
72
|
+
getOffsets(): TimeZoneOffset[] {
|
|
73
|
+
const offsets: TimeZoneOffset[] = []
|
|
74
|
+
this.components.forEach(component => {
|
|
75
|
+
if (
|
|
76
|
+
component.name === 'STANDARD' ||
|
|
77
|
+
component.name === 'DAYLIGHT'
|
|
78
|
+
) {
|
|
79
|
+
offsets.push(new TimeZoneOffset(component))
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
return offsets
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get standard/winter time offsets.
|
|
87
|
+
* @returns An array of time zone offsets defined in this time zone that are of type STANDARD.
|
|
88
|
+
*/
|
|
89
|
+
getStandardOffsets(): TimeZoneOffset[] {
|
|
90
|
+
return this.getComponentsWithName('STANDARD').map(
|
|
91
|
+
c => new TimeZoneOffset(c)
|
|
92
|
+
)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Get daylight savings time offsets.
|
|
97
|
+
* @returns An array of time zone offsets defined in this time zone that are of type DAYLIGHT.
|
|
98
|
+
*/
|
|
99
|
+
getDaylightOffsets(): TimeZoneOffset[] {
|
|
100
|
+
return this.getComponentsWithName('DAYLIGHT').map(
|
|
101
|
+
c => new TimeZoneOffset(c)
|
|
102
|
+
)
|
|
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
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Component, ComponentValidationError } from '../component'
|
|
2
|
+
import { CalendarDateOrTime, convertDate, parseDateProperty } from '../date'
|
|
3
|
+
import { AllowedPropertyName } from '../property'
|
|
4
|
+
|
|
5
|
+
export const knownOffsetTypes = ['DAYLIGHT', 'STANDARD']
|
|
6
|
+
export type OffsetType = (typeof knownOffsetTypes)[number]
|
|
7
|
+
type Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'
|
|
8
|
+
export type Offset = `${'-' | '+'}${Digit}${Digit}${Digit}${Digit}`
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Represents a STANDARD or DAYLIGHT subcomponent, defining a time zone offset.
|
|
12
|
+
*/
|
|
13
|
+
export class TimeZoneOffset extends Component {
|
|
14
|
+
/**
|
|
15
|
+
* @param type If this is a STANDARD or DAYLIGHT component.
|
|
16
|
+
* @param start From when this offset is active.
|
|
17
|
+
* @param offsetFrom The offset that is in use prior to this time zone observance.
|
|
18
|
+
* @param offsetTo The offset that is in use during this time zone observance.
|
|
19
|
+
*/
|
|
20
|
+
constructor(
|
|
21
|
+
type: OffsetType,
|
|
22
|
+
start: CalendarDateOrTime | Date,
|
|
23
|
+
offsetFrom: Offset,
|
|
24
|
+
offsetTo: Offset
|
|
25
|
+
)
|
|
26
|
+
constructor(component: Component)
|
|
27
|
+
constructor(
|
|
28
|
+
a: OffsetType | Component,
|
|
29
|
+
b?: CalendarDateOrTime | Date,
|
|
30
|
+
c?: Offset,
|
|
31
|
+
d?: Offset
|
|
32
|
+
) {
|
|
33
|
+
let component: Component
|
|
34
|
+
if (a instanceof Component) {
|
|
35
|
+
component = a as Component
|
|
36
|
+
TimeZoneOffset.prototype.validate.call(component)
|
|
37
|
+
} else {
|
|
38
|
+
const name = a as OffsetType
|
|
39
|
+
const start = convertDate(b!)
|
|
40
|
+
const offsetFrom = c as Offset
|
|
41
|
+
const offsetTo = d as Offset
|
|
42
|
+
component = new Component(name)
|
|
43
|
+
component.setProperty('DTSTART', start)
|
|
44
|
+
component.setProperty('TZOFFSETFROM', offsetFrom)
|
|
45
|
+
component.setProperty('TZOFFSETTO', offsetTo)
|
|
46
|
+
}
|
|
47
|
+
super(component.name, component.properties, component.components)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
validate(): void {
|
|
51
|
+
if (!knownOffsetTypes.includes(this.name)) {
|
|
52
|
+
throw new ComponentValidationError(
|
|
53
|
+
'Component name must be STANDARD or DAYLIGHT'
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
const requiredProperties: AllowedPropertyName[] = [
|
|
57
|
+
'DTSTART',
|
|
58
|
+
'TZOFFSETFROM',
|
|
59
|
+
'TZOFFSETTO',
|
|
60
|
+
]
|
|
61
|
+
this.validateAllProperties(requiredProperties)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Get the date or time when this time zone offset starts.
|
|
66
|
+
* @returns The start date or time of this time zone offset.
|
|
67
|
+
*/
|
|
68
|
+
getStart(): CalendarDateOrTime {
|
|
69
|
+
return parseDateProperty(this.getProperty('DTSTART')!)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Set the date or time when this time zone offset starts.
|
|
74
|
+
* @param value The start date or time.
|
|
75
|
+
* @returns The TimeZoneOffset instance for chaining.
|
|
76
|
+
*/
|
|
77
|
+
setStart(value: CalendarDateOrTime | Date): this {
|
|
78
|
+
return this.setProperty('DTSTART', convertDate(value))
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get the offset which is offset from during this time zone offset.
|
|
83
|
+
* @returns The offset in a format such as "+0100" or "-0230".
|
|
84
|
+
*/
|
|
85
|
+
getOffsetFrom(): Offset {
|
|
86
|
+
return this.getProperty('TZOFFSETFROM')!.value as Offset
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Set the offset to offset from during this time zone offset.
|
|
91
|
+
* @param value An offset such as "+0100" or "-0230".
|
|
92
|
+
* @returns The TimeZoneOffset instance for chaining.
|
|
93
|
+
*/
|
|
94
|
+
setOffsetFrom(value: Offset): this {
|
|
95
|
+
return this.setProperty('TZOFFSETFROM', value)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Get the offset which is offset to during this time zone offset.
|
|
100
|
+
* @returns The offset in a format such as "+0100" or "-0230".
|
|
101
|
+
*/
|
|
102
|
+
getOffsetTo(): Offset {
|
|
103
|
+
return this.getProperty('TZOFFSETTO')!.value as Offset
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Set the offset to offset to during this time zone offset.
|
|
108
|
+
* @param value An offset such as "+0100" or "-0230".
|
|
109
|
+
* @returns The TimeZoneOffset instance for chaining.
|
|
110
|
+
*/
|
|
111
|
+
setOffsetTo(value: Offset): this {
|
|
112
|
+
return this.setProperty('TZOFFSETTO', value)
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
getComment(): string | undefined {
|
|
116
|
+
return this.getProperty('COMMENT')?.value
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setComment(value: string): this {
|
|
120
|
+
return this.setProperty('COMMENT', value)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
removeComment() {
|
|
124
|
+
this.removePropertiesWithName('COMMENT')
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Get the name of this time zone offset.
|
|
129
|
+
* @returns The time zone offset name if it exists.
|
|
130
|
+
*/
|
|
131
|
+
getTimeZoneName(): string | undefined {
|
|
132
|
+
return this.getProperty('TZNAME')?.value
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the name of this time zone offset.
|
|
137
|
+
* @param value The new name.
|
|
138
|
+
* @returns The TimeZoneOffset instance for chaining.
|
|
139
|
+
* @example
|
|
140
|
+
* timeZoneOffset.setTimeZoneName('EST')
|
|
141
|
+
*/
|
|
142
|
+
setTimeZoneName(value: string): this {
|
|
143
|
+
return this.setProperty('TZNAME', value)
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Remove the name of this time zone offset.
|
|
148
|
+
*/
|
|
149
|
+
removeTimeZoneName() {
|
|
150
|
+
this.removePropertiesWithName('TZNAME')
|
|
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
|
+
}
|