ical-generator 9.0.0-develop.5 → 9.0.0-develop.6

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/package.json CHANGED
@@ -5,6 +5,7 @@
5
5
  },
6
6
  "description": "ical-generator is a small piece of code which generates ical calendar files",
7
7
  "devDependencies": {
8
+ "@date-fns/tz": "^1.2.0",
8
9
  "@eslint/js": "^9.25.0",
9
10
  "@istanbuljs/nyc-config-typescript": "^1.0.2",
10
11
  "@qiwi/semantic-release-gh-pages-plugin": "^5.4.3",
@@ -118,6 +119,7 @@
118
119
  },
119
120
  "runkitExampleFilename": "examples/example-runkit.js",
120
121
  "scripts": {
122
+ "prepare": "npm run build",
121
123
  "build": "tsup && cp ./dist/index.d.ts ./dist/index.d.cts",
122
124
  "build-all": "./.github/workflows/build.sh",
123
125
  "coverage": "c8 mocha",
@@ -129,5 +131,5 @@
129
131
  "test": "mocha"
130
132
  },
131
133
  "type": "module",
132
- "version": "9.0.0-develop.5"
134
+ "version": "9.0.0-develop.6"
133
135
  }
package/src/tools.ts CHANGED
@@ -9,6 +9,7 @@ import {
9
9
  type ICalMomentTimezoneStub,
10
10
  type ICalOrganizer,
11
11
  type ICalRRuleStub,
12
+ type ICalTZDateStub,
12
13
  } from './types.ts';
13
14
 
14
15
  export function addOrGetCustomAttributes(
@@ -244,7 +245,9 @@ export function formatDate(
244
245
  }
245
246
 
246
247
  if (typeof d === 'string' || d instanceof Date) {
247
- const m = new Date(d);
248
+ // TZDate is an extension of the native Date object.
249
+ // @see https://github.com/date-fns/tz for more information.
250
+ const m = isTZDate(d) ? d.withTimeZone(timezone) : new Date(d);
248
251
 
249
252
  // (!dateonly && !floating) || !timezone => utc
250
253
  let s =
@@ -422,6 +425,18 @@ export function isRRule(value: unknown): value is ICalRRuleStub {
422
425
  );
423
426
  }
424
427
 
428
+ export function isTZDate(value: ICalDateTimeValue): value is ICalTZDateStub {
429
+ return (
430
+ value instanceof Date &&
431
+ 'internal' in value &&
432
+ value.internal instanceof Date &&
433
+ 'withTimeZone' in value &&
434
+ typeof value.withTimeZone === 'function' &&
435
+ 'tzComponents' in value &&
436
+ typeof value.tzComponents === 'function'
437
+ );
438
+ }
439
+
425
440
  export function toDate(value: ICalDateTimeValue): Date {
426
441
  if (typeof value === 'string' || value instanceof Date) {
427
442
  return new Date(value);
package/src/types.ts CHANGED
@@ -127,3 +127,9 @@ export interface ICalTimezone {
127
127
  generator?: (timezone: string) => null | string;
128
128
  name: null | string;
129
129
  }
130
+
131
+ export interface ICalTZDateStub extends Date {
132
+ timeZone?: string;
133
+ tzComponents(): string[];
134
+ withTimeZone(timezone?: null | string): ICalTZDateStub;
135
+ }