@@ -56,49 +56,49 @@ export class IcalEvent {
56
56
* @param {HebrewCalendar.Options } options
57
57
*/
58
58
constructor ( ev , options = { } ) {
59
- const dtstamp = options . dtstamp || IcalEvent . makeDtstamp ( new Date ( ) ) ;
60
- const timed = Boolean ( ev . eventTime ) ;
59
+ this . ev = ev ;
60
+ this . options = options ;
61
+ this . dtstamp = options . dtstamp || IcalEvent . makeDtstamp ( new Date ( ) ) ;
62
+ const timed = this . timed = Boolean ( ev . eventTime ) ;
61
63
let subj = timed || ( ev . getFlags ( ) & flags . DAF_YOMI ) ? ev . renderBrief ( ) : ev . render ( ) ;
62
- const desc = ev . getDesc ( ) ; // original untranslated
63
- const mask = ev . getFlags ( ) ;
64
- let location ;
65
64
if ( timed && options . location && options . location . name ) {
66
65
const comma = options . location . name . indexOf ( ',' ) ;
67
- location = ( comma == - 1 ) ? options . location . name : options . location . name . substring ( 0 , comma ) ;
66
+ this . locationName = ( comma == - 1 ) ? options . location . name : options . location . name . substring ( 0 , comma ) ;
68
67
}
68
+ const mask = ev . getFlags ( ) ;
69
69
if ( mask & flags . DAF_YOMI ) {
70
- location = Locale . gettext ( 'Daf Yomi' ) ;
70
+ this . locationName = Locale . gettext ( 'Daf Yomi' ) ;
71
71
}
72
72
73
73
const date = IcalEvent . formatYYYYMMDD ( ev . getDate ( ) . greg ( ) ) ;
74
- let startDate = date ;
75
- let dtargs = '' ;
76
- let endDate ;
77
- let transp = 'TRANSPARENT' ; let busyStatus = 'FREE' ;
74
+ this . startDate = date ;
75
+ this . dtargs = '' ;
76
+ this . transp = 'TRANSPARENT' ;
77
+ this . busyStatus = 'FREE' ;
78
78
if ( timed ) {
79
79
let [ hour , minute ] = ev . eventTimeStr . split ( ':' ) ;
80
80
hour = + hour ;
81
81
minute = + minute ;
82
- startDate += 'T' + pad2 ( hour ) + pad2 ( minute ) + '00' ;
83
- endDate = startDate ;
82
+ this . startDate += 'T' + pad2 ( hour ) + pad2 ( minute ) + '00' ;
83
+ this . endDate = this . startDate ;
84
84
if ( options . location && options . location . tzid ) {
85
- dtargs = `;TZID=${ options . location . tzid } ` ;
85
+ this . dtargs = `;TZID=${ options . location . tzid } ` ;
86
86
}
87
87
} else {
88
- endDate = IcalEvent . formatYYYYMMDD ( ev . getDate ( ) . next ( ) . greg ( ) ) ;
88
+ this . endDate = IcalEvent . formatYYYYMMDD ( ev . getDate ( ) . next ( ) . greg ( ) ) ;
89
89
// for all-day untimed, use DTEND;VALUE=DATE intsead of DURATION:P1D.
90
90
// It's more compatible with everthing except ancient versions of
91
91
// Lotus Notes circa 2004
92
- dtargs = ';VALUE=DATE' ;
92
+ this . dtargs = ';VALUE=DATE' ;
93
93
if ( mask & flags . CHAG ) {
94
- transp = 'OPAQUE' ;
95
- busyStatus = 'OOF' ;
94
+ this . transp = 'OPAQUE' ;
95
+ this . busyStatus = 'OOF' ;
96
96
}
97
97
}
98
98
99
99
let uid = ev . uid ;
100
100
if ( ! uid ) {
101
- const digest = murmur3 ( desc ) . toString ( 16 ) ;
101
+ const digest = murmur3 ( ev . getDesc ( ) ) . toString ( 16 ) ;
102
102
uid = `hebcal-${ date } -${ digest } ` ;
103
103
if ( timed && options . location ) {
104
104
if ( options . location . geoid ) {
@@ -108,6 +108,7 @@ export class IcalEvent {
108
108
}
109
109
}
110
110
}
111
+ this . uid = uid ;
111
112
112
113
// make subject safe for iCalendar
113
114
subj = IcalEvent . escape ( subj ) ;
@@ -118,57 +119,67 @@ export class IcalEvent {
118
119
subj += ` / ${ hebrew } ` ;
119
120
}
120
121
}
122
+ this . subj = subj ;
121
123
122
124
const isUserEvent = Boolean ( mask & flags . USER_EVENT ) ;
123
- const category = CATEGORY [ getEventCategories ( ev ) [ 0 ] ] ;
124
- const categoryLine = category ? `CATEGORIES:${ category } ` : [ ] ;
125
+ if ( mask & flags . OMER_COUNT ) {
126
+ this . alarm = '0DT3H30M0S' ; // 8:30pm Omer alarm evening before
127
+ } else if ( isUserEvent ) {
128
+ this . alarm = '0DT12H0M0S' ; // noon the day before
129
+ } else if ( timed && ev . getDesc ( ) . startsWith ( 'Candle lighting' ) ) {
130
+ this . alarm = '0DT0H10M0S' ; // ten minutes
131
+ }
132
+
133
+ this . category = CATEGORY [ getEventCategories ( ev ) [ 0 ] ] ;
134
+ }
135
+
136
+ /**
137
+ * @return {string[] }
138
+ */
139
+ getLongLines ( ) {
140
+ const categoryLine = this . category ? `CATEGORIES:${ this . category } ` : [ ] ;
125
141
const arr = [
126
142
'BEGIN:VEVENT' ,
127
- `DTSTAMP:${ dtstamp } ` ,
143
+ `DTSTAMP:${ this . dtstamp } ` ,
128
144
] . concat ( categoryLine ) . concat ( [
129
- `SUMMARY:${ subj } ` ,
130
- `DTSTART${ dtargs } :${ startDate } ` ,
131
- `DTEND${ dtargs } :${ endDate } ` ,
132
- `TRANSP:${ transp } ` ,
133
- `X-MICROSOFT-CDO-BUSYSTATUS:${ busyStatus } ` ,
134
- `UID:${ uid } ` ,
145
+ `SUMMARY:${ this . subj } ` ,
146
+ `DTSTART${ this . dtargs } :${ this . startDate } ` ,
147
+ `DTEND${ this . dtargs } :${ this . endDate } ` ,
148
+ `TRANSP:${ this . transp } ` ,
149
+ `X-MICROSOFT-CDO-BUSYSTATUS:${ this . busyStatus } ` ,
150
+ `UID:${ this . uid } ` ,
135
151
] ) ;
136
152
153
+ const ev = this . ev ;
154
+ const mask = ev . getFlags ( ) ;
155
+ const isUserEvent = Boolean ( mask & flags . USER_EVENT ) ;
137
156
if ( ! isUserEvent ) {
138
157
arr . push ( 'CLASS:PUBLIC' ) ;
139
158
}
140
159
160
+ const options = this . options ;
141
161
// create memo (holiday descr, Torah, etc)
142
162
const memo = createMemo ( ev , options . il ) ;
143
163
addOptional ( arr , 'DESCRIPTION' , memo ) ;
144
- addOptional ( arr , 'LOCATION' , location ) ;
145
- if ( timed && options . location ) {
164
+ addOptional ( arr , 'LOCATION' , this . locationName ) ;
165
+ if ( this . timed && options . location ) {
146
166
arr . push ( 'GEO:' + options . location . latitude + ';' + options . location . longitude ) ;
147
167
}
148
168
149
- let alarm ;
150
- if ( mask & flags . OMER_COUNT ) {
151
- alarm = '0DT3H30M0S' ; // 8:30pm Omer alarm evening before
152
- } else if ( isUserEvent ) {
153
- alarm = '0DT12H0M0S' ; // noon the day before
154
- } else if ( timed && desc . startsWith ( 'Candle lighting' ) ) {
155
- alarm = '0DT0H10M0S' ; // ten minutes
156
- }
157
- if ( alarm ) {
169
+ if ( this . alarm ) {
158
170
arr . push (
159
171
'BEGIN:VALARM' ,
160
172
'ACTION:DISPLAY' ,
161
173
'DESCRIPTION:This is an event reminder' ,
162
- `TRIGGER:-P${ alarm } ` ,
174
+ `TRIGGER:-P${ this . alarm } ` ,
163
175
'END:VALARM' ,
164
176
) ;
165
177
}
166
178
167
179
arr . push ( 'END:VEVENT' ) ;
168
180
169
181
this . lines = arr ;
170
- this . options = options ;
171
- this . ev = ev ;
182
+ return this . lines ;
172
183
}
173
184
174
185
/**
@@ -186,13 +197,6 @@ export class IcalEvent {
186
197
return this . getLongLines ( ) . map ( IcalEvent . fold ) ;
187
198
}
188
199
189
- /**
190
- * @return {string[] }
191
- */
192
- getLongLines ( ) {
193
- return this . lines ;
194
- }
195
-
196
200
/**
197
201
* fold line to 75 characters
198
202
* @param {string } line
0 commit comments