@hebcal/icalendar 7.0.3 → 7.0.5

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/dist/icalendar.js CHANGED
@@ -1,4 +1,3 @@
1
- import { flags } from '@hebcal/core/dist/esm/event';
2
1
  import { Locale } from '@hebcal/core/dist/esm/locale';
3
2
  import { murmur32HexSync } from '@hebcal/murmurhash3';
4
3
  import { pad2, pad4, isDate } from '@hebcal/hdate';
@@ -54,11 +53,37 @@ function appendTrackingToUrl(url, options) {
54
53
  const utmCampaign = options.utmCampaign;
55
54
  return appendIsraelAndTracking(url, options.il, utmSource, utmMedium, utmCampaign);
56
55
  }
57
- const DAILY_LEARNING = flags.DAILY_LEARNING |
58
- flags.DAF_YOMI |
59
- flags.MISHNA_YOMI |
60
- flags.YERUSHALMI_YOMI |
61
- flags.NACH_YOMI;
56
+ /** Formats a date-time string as `YYYYMMDDTHHMMSS` */
57
+ function rfc5545DateTime(dt, hour, minute) {
58
+ return IcalEvent.formatYYYYMMDD(dt) + 'T' + pad2(hour) + pad2(minute) + '00';
59
+ }
60
+ /**
61
+ * Computes the DTSTART/DTEND date-time strings (in `YYYYMMDDTHHMMSS`
62
+ * format) for a timed event, adding `duration` minutes (if any) to the
63
+ * wall-clock start time. Adding to the wall clock (rather than to the
64
+ * underlying instant) keeps the result in the same timezone as DTSTART
65
+ * regardless of the host machine's own local timezone.
66
+ * @private
67
+ */
68
+ function formatTimedStartEnd(ev) {
69
+ const [hourStr, minuteStr] = ev.eventTimeStr.split(':');
70
+ const hour = +hourStr;
71
+ const minute = +minuteStr;
72
+ const dt = ev.greg();
73
+ const startDate = rfc5545DateTime(dt, hour, minute);
74
+ if (!ev.duration) {
75
+ return { startDate, endDate: startDate };
76
+ }
77
+ const totalMinutes = hour * 60 + minute + ev.duration;
78
+ const endHour = Math.floor(totalMinutes / 60) % 24;
79
+ const endMinute = totalMinutes % 60;
80
+ const dayOffset = Math.floor(totalMinutes / 1440);
81
+ if (dayOffset) {
82
+ dt.setDate(dt.getDate() + dayOffset);
83
+ }
84
+ const endDate = rfc5545DateTime(dt, endHour, endMinute);
85
+ return { startDate, endDate };
86
+ }
62
87
  /**
63
88
  * Represents an RFC 2445 iCalendar VEVENT
64
89
  */
@@ -100,14 +125,14 @@ export class IcalEvent {
100
125
  let subj = shouldRenderBrief(ev)
101
126
  ? ev.renderBrief(locale)
102
127
  : ev.render(locale);
103
- const mask = ev.getFlags();
104
128
  if (ev0.locationName) {
105
129
  this.locationName = ev0.locationName;
106
130
  }
107
131
  else if (timed && location) {
108
132
  this.locationName = location.getShortName();
109
133
  }
110
- else if (mask & DAILY_LEARNING && ev0.category) {
134
+ else if (ev.hasAnyFlag('DAILY_LEARNING', 'DAF_YOMI', 'MISHNA_YOMI', 'YERUSHALMI_YOMI', 'NACH_YOMI') &&
135
+ ev0.category) {
111
136
  this.locationName = Locale.gettext(ev0.category, locale);
112
137
  }
113
138
  const hd = ev.getDate();
@@ -117,11 +142,9 @@ export class IcalEvent {
117
142
  this.transp = 'TRANSPARENT';
118
143
  this.busyStatus = 'FREE';
119
144
  if (timed) {
120
- let [hour, minute] = ev0.eventTimeStr.split(':');
121
- hour = +hour;
122
- minute = +minute;
123
- this.startDate += 'T' + pad2(hour) + pad2(minute) + '00';
124
- this.endDate = this.startDate;
145
+ const { startDate, endDate } = formatTimedStartEnd(ev);
146
+ this.startDate = startDate;
147
+ this.endDate = endDate;
125
148
  if (location?.getTzid()) {
126
149
  this.dtargs = `;TZID=${location.getTzid()}`;
127
150
  }
@@ -132,7 +155,7 @@ export class IcalEvent {
132
155
  // It's more compatible with everthing except ancient versions of
133
156
  // Lotus Notes circa 2004
134
157
  this.dtargs = ';VALUE=DATE';
135
- if (mask & flags.CHAG) {
158
+ if (ev.hasFlag('CHAG')) {
136
159
  this.transp = 'OPAQUE';
137
160
  this.busyStatus = 'OOF';
138
161
  }
@@ -140,7 +163,7 @@ export class IcalEvent {
140
163
  if (opts.emoji) {
141
164
  const prefix = ev.getEmoji();
142
165
  if (prefix) {
143
- if (mask & flags.OMER_COUNT) {
166
+ if (ev.hasFlag('OMER_COUNT')) {
144
167
  subj = subj + ' ' + prefix;
145
168
  }
146
169
  else {
@@ -163,7 +186,6 @@ export class IcalEvent {
163
186
  }
164
187
  getAlarm() {
165
188
  const ev = this.ev;
166
- const mask = ev.getFlags();
167
189
  const evAlarm = ev.alarm;
168
190
  if (typeof evAlarm === 'string') {
169
191
  return 'TRIGGER:' + evAlarm;
@@ -176,10 +198,10 @@ export class IcalEvent {
176
198
  alarmDt.setSeconds(0);
177
199
  return 'TRIGGER;VALUE=DATE-TIME:' + IcalEvent.makeDtstamp(alarmDt);
178
200
  }
179
- else if (mask & flags.OMER_COUNT) {
201
+ else if (ev.hasFlag('OMER_COUNT')) {
180
202
  return 'TRIGGER:-P0DT3H30M0S'; // 8:30pm Omer alarm evening before
181
203
  }
182
- else if (mask & flags.USER_EVENT) {
204
+ else if (ev.hasFlag('USER_EVENT')) {
183
205
  return 'TRIGGER:-P0DT12H0M0S'; // noon the day before
184
206
  }
185
207
  else if (this.timed && ev.getDesc().startsWith('Candle lighting')) {
@@ -228,8 +250,7 @@ export class IcalEvent {
228
250
  arr.push('X-MICROSOFT-CDO-ALLDAYEVENT:TRUE');
229
251
  }
230
252
  const ev = this.ev;
231
- const mask = ev.getFlags();
232
- const isUserEvent = Boolean(mask & flags.USER_EVENT);
253
+ const isUserEvent = ev.hasFlag('USER_EVENT');
233
254
  if (!isUserEvent) {
234
255
  arr.push('CLASS:PUBLIC');
235
256
  }
@@ -1 +1 @@
1
- export declare const version = "7.0.3";
1
+ export declare const version = "7.0.5";
@@ -1,2 +1,2 @@
1
1
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
2
- export const version = '7.0.3';
2
+ export const version = '7.0.5';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hebcal/icalendar",
3
- "version": "7.0.3",
3
+ "version": "7.0.5",
4
4
  "author": "Michael J. Radwin (https://github.com/mjradwin)",
5
5
  "keywords": [
6
6
  "ical",
@@ -30,8 +30,8 @@
30
30
  },
31
31
  "homepage": "https://hebcal.github.io/api/icalendar/",
32
32
  "dependencies": {
33
- "@hebcal/core": "^6.9.1",
34
- "@hebcal/hdate": "^0.22.7",
33
+ "@hebcal/core": "^6.10.0",
34
+ "@hebcal/hdate": "^0.22.8",
35
35
  "@hebcal/murmurhash3": "^1.0.0",
36
36
  "@hebcal/rest-api": "^7.1.3"
37
37
  },
@@ -40,7 +40,8 @@
40
40
  "build": "npm run build:version && tsc",
41
41
  "pretest": "npm run build",
42
42
  "docs": "npx -y typedoc",
43
- "test": "vitest",
43
+ "test": "vitest run",
44
+ "test:watch": "vitest",
44
45
  "lint": "oxlint && prettier --check .",
45
46
  "clean": "rm -rf dist",
46
47
  "compile": "tsc",
@@ -48,11 +49,11 @@
48
49
  },
49
50
  "license": "BSD-2-Clause",
50
51
  "devDependencies": {
51
- "@hebcal/learning": "^6.9.7",
52
- "@types/node": "26.2.0",
53
- "oxlint": "^1.77.0",
54
- "prettier": "^3.9.6",
52
+ "@hebcal/learning": "^6.11.3",
53
+ "@types/node": "26.6.3",
54
+ "oxlint": "^1.86.0",
55
+ "prettier": "^3.9.9",
55
56
  "typescript": "^7.0.2",
56
- "vitest": "^4.1.10"
57
+ "vitest": "^5.0.2"
57
58
  }
58
59
  }