Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@touch4it/ical-timezones

Package Overview
Dependencies
Maintainers
3
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@touch4it/ical-timezones - npm Package Compare versions

Comparing version 1.6.1 to 1.7.0

6

CHANGELOG.md
# ical-timezone Changelog
## 1.7.0 (2021-05-25)
- Added async versions of functions
- Updated dependencies
- Refactored function to be more efficient
## 1.6.1 (2021-05-11)

@@ -4,0 +10,0 @@

2

index.d.ts
export function getVtimezone(timezone: string): string|null;
export function getVtimezoneComponent(timezone: string): string|null;
export function getVtimezoneAsync(timezone: string): Promise<string>;
export function getVtimezoneComponentAsync(timezone: string): Promise<string>;

52

index.js

@@ -6,24 +6,44 @@ const fs = require('fs');

function getVtimezone(timezone) {
const tzPath = path.join(__dirname, 'zones', zones[timezone] || '');
if (timezone in zones && fs.existsSync(tzPath)) {
const file = fs.readFileSync(tzPath);
return file.toString();
const zoneFile = zones[timezone];
if (zoneFile) {
const tzPath = path.join(__dirname, 'zones', zoneFile);
try {
return fs.readFileSync(tzPath, 'utf8');
} catch (_) {}
}
return null;
}
function extractVTZ(content) {
return content.substring(
content.indexOf('BEGIN:VTIMEZONE'),
content.indexOf('END:VCALENDAR')
);
}
function getVtimezoneComponent(timezone) {
const tzPath = path.join(__dirname, 'zones', zones[timezone] || '');
if (timezone in zones && fs.existsSync(tzPath)) {
const file = fs.readFileSync(tzPath);
let content = file.toString();
const ics = getVtimezone(timezone);
return ics && extractVTZ(ics);
}
content = content.slice(content.indexOf('BEGIN:VTIMEZONE'));
content = content.slice(0, content.indexOf('END:VCALENDAR'));
return content;
function getVtimezoneAsync(timezone) {
const zoneFile = zones[timezone];
if (zoneFile) {
const tzPath = path.join(__dirname, 'zones', zoneFile);
return new Promise((resolve, reject) => {
fs.readFile(tzPath, 'utf8', (error, content) => {
if (error) {
reject(error);
} else {
resolve(content);
}
});
});
}
return Promise.reject(new Error('Time zone does not exist'));
}
return null;
async function getVtimezoneComponentAsync(timezone) {
const ics = await getVtimezoneAsync(timezone);
return extractVTZ(ics);
}

@@ -33,3 +53,5 @@

getVtimezone,
getVtimezoneComponent
getVtimezoneComponent,
getVtimezoneAsync,
getVtimezoneComponentAsync,
};
{
"name": "@touch4it/ical-timezones",
"version": "1.6.1",
"version": "1.7.0",
"description": "iCal timezone component generator",
"homepage": "https://github.com/touch4it/ical-timezones",
"bugs": {
"url": "https://github.com/touch4it/ical-timezones/issues"
},
"main": "index.js",
"license": "ISC",
"engines": {
"node": ">=8.0.0"
},
"scripts": {
"test": "jest && npm run lint",
"lint": "eslint *.js",
"lint:fix": "eslint --fix *.js",
"format-package": "npx format-package -w"
"bugs": {
"url": "https://github.com/touch4it/ical-timezones/issues"
},
"homepage": "https://github.com/touch4it/ical-timezones",
"author": "Touch4IT, s.r.o. <hi@touch4it.com> (https://touch4it.com/)",
"contributors": [
"Viktor Sulak <viktor.sulak@touch4it.com>",
"Nick Singleton"
],
"keywords": [

@@ -31,16 +30,20 @@ "ical",

],
"author": "Touch4IT, s.r.o. <hi@touch4it.com> (https://touch4it.com/)",
"contributors": [
"Viktor Sulak <viktor.sulak@touch4it.com>"
],
"main": "index.js",
"scripts": {
"format-package": "npx format-package -w",
"lint": "eslint *.js",
"lint:fix": "eslint --fix *.js",
"pjv": "npx package-json-validator .",
"test": "jest && npm run lint",
"test-only": "jest --forceExit"
},
"maintainers": [
"Viktor Sulak <viktor.sulak@touch4it.com>"
],
"license": "ISC",
"dependencies": {},
"devDependencies": {
"eslint": "^7.16.0",
"eslint": "^7.27.0",
"eslint-config-touch4it": "^6.2.0",
"jest": "^26.6.3"
},
"dependencies": {}
"jest": "^27.0.1"
}
}

@@ -28,2 +28,6 @@ # VTIMEZONE iCalendar component generator

```
or
```javascript
const vtimezone = await tz.getVtimezoneAsync('Europe/Bratislava');
```

@@ -63,2 +67,6 @@ Generated output

```
or
```javascript
const vtimezone = await tz.getVtimezoneComponentAsync('Europe/Bratislava');
```

@@ -96,2 +104,1 @@ Generated output

http://www.healthstream.com/hlchelp/Administrator/Classes/HLC_Time_Zone_Abbreviations.htm
const app = require('../index');
const expectedTimezoneObject = `BEGIN:VCALENDAR\r
PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN\r
VERSION:2.0\r
BEGIN:VTIMEZONE\r
TZID:Australian Central Standard Time\r
X-LIC-LOCATION:Australian Central Standard Time\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0930\r
TZOFFSETTO:+0930\r
TZNAME:ACST\r
DTSTART:19700101T000000\r
END:STANDARD\r
END:VTIMEZONE\r
END:VCALENDAR\r
`;
const expectedTimezoneObject = [
'BEGIN:VCALENDAR',
'PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN',
'VERSION:2.0',
'BEGIN:VTIMEZONE',
'TZID:Australian Central Standard Time',
'X-LIC-LOCATION:Australian Central Standard Time',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0930',
'TZOFFSETTO:+0930',
'TZNAME:ACST',
'DTSTART:19700101T000000',
'END:STANDARD',
'END:VTIMEZONE',
'END:VCALENDAR',
'',
].join('\n');
const expectedTimezoneComponent = `BEGIN:VTIMEZONE\r
TZID:Australian Central Standard Time\r
X-LIC-LOCATION:Australian Central Standard Time\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0930\r
TZOFFSETTO:+0930\r
TZNAME:ACST\r
DTSTART:19700101T000000\r
END:STANDARD\r
END:VTIMEZONE\r
`;
const expectedTimezoneComponent = [
'BEGIN:VTIMEZONE',
'TZID:Australian Central Standard Time',
'X-LIC-LOCATION:Australian Central Standard Time',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0930',
'TZOFFSETTO:+0930',
'TZNAME:ACST',
'DTSTART:19700101T000000',
'END:STANDARD',
'END:VTIMEZONE',
'',
].join('\n');

@@ -31,0 +35,0 @@ test('Correct timezone object for "Australian Central Standard Time" timezone', () => {

const app = require('../index');
const expectedTimezoneObject = `BEGIN:VCALENDAR\r
PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN\r
VERSION:2.0\r
BEGIN:VTIMEZONE\r
TZID:Europe/Bratislava\r
TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Bratislava\r
X-LIC-LOCATION:Europe/Bratislava\r
BEGIN:DAYLIGHT\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
TZNAME:CEST\r
DTSTART:19700329T020000\r
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
TZNAME:CET\r
DTSTART:19701025T030000\r
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r
END:STANDARD\r
END:VTIMEZONE\r
END:VCALENDAR\r
`;
const expectedTimezoneComponent = `BEGIN:VTIMEZONE\r
TZID:Europe/Bratislava\r
TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Bratislava\r
X-LIC-LOCATION:Europe/Bratislava\r
BEGIN:DAYLIGHT\r
TZOFFSETFROM:+0100\r
TZOFFSETTO:+0200\r
TZNAME:CEST\r
DTSTART:19700329T020000\r
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0200\r
TZOFFSETTO:+0100\r
TZNAME:CET\r
DTSTART:19701025T030000\r
RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU\r
END:STANDARD\r
END:VTIMEZONE\r
`;
const expectedTimezoneObject = [
'BEGIN:VCALENDAR',
'PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN',
'VERSION:2.0',
'BEGIN:VTIMEZONE',
'TZID:Europe/Bratislava',
'TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Bratislava',
'X-LIC-LOCATION:Europe/Bratislava',
'BEGIN:DAYLIGHT',
'TZOFFSETFROM:+0100',
'TZOFFSETTO:+0200',
'TZNAME:CEST',
'DTSTART:19700329T020000',
'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU',
'END:DAYLIGHT',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0200',
'TZOFFSETTO:+0100',
'TZNAME:CET',
'DTSTART:19701025T030000',
'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU',
'END:STANDARD',
'END:VTIMEZONE',
'END:VCALENDAR',
'',
].join('\n');
test('Correct timezone object for "Europe/Bratislava" timezone', () => {
expect(app.getVtimezone('Europe/Bratislava')).toBe(expectedTimezoneObject);
const expectedTimezoneComponent = [
'BEGIN:VTIMEZONE',
'TZID:Europe/Bratislava',
'TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Bratislava',
'X-LIC-LOCATION:Europe/Bratislava',
'BEGIN:DAYLIGHT',
'TZOFFSETFROM:+0100',
'TZOFFSETTO:+0200',
'TZNAME:CEST',
'DTSTART:19700329T020000',
'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU',
'END:DAYLIGHT',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0200',
'TZOFFSETTO:+0100',
'TZNAME:CET',
'DTSTART:19701025T030000',
'RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU',
'END:STANDARD',
'END:VTIMEZONE',
'',
].join('\n');
describe('Sync', () => {
test('Correct timezone object for "Europe/Bratislava" timezone', () => {
expect(app.getVtimezone('Europe/Bratislava')).toBe(expectedTimezoneObject);
});
test('Correct timezone component for "Europe/Bratislava" timezone', () => {
expect(app.getVtimezoneComponent('Europe/Bratislava')).toBe(expectedTimezoneComponent);
});
});
test('Correct timezone component for "Europe/Bratislava" timezone', () => {
expect(app.getVtimezoneComponent('Europe/Bratislava')).toBe(expectedTimezoneComponent);
describe('Async', () => {
test('Correct timezone object for "Europe/Bratislava" timezone', async () => {
const result = await app.getVtimezoneAsync('Europe/Bratislava');
expect(result).toBe(expectedTimezoneObject);
});
test('Correct timezone component for "Europe/Bratislava" timezone', async () => {
const result = await app.getVtimezoneComponentAsync('Europe/Bratislava');
expect(result).toBe(expectedTimezoneComponent);
});
});
const app = require('../index');
const expectedTimezoneObject = `BEGIN:VCALENDAR\r
PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN\r
VERSION:2.0\r
BEGIN:VTIMEZONE\r
TZID:Etc/GMT\r
TZURL:http://tzurl.org/zoneinfo-outlook/Etc/GMT\r
X-LIC-LOCATION:Etc/GMT\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0000\r
TZOFFSETTO:+0000\r
TZNAME:GMT\r
DTSTART:19700101T000000\r
END:STANDARD\r
END:VTIMEZONE\r
END:VCALENDAR\r
`;
const expectedTimezoneObject = [
'BEGIN:VCALENDAR',
'PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN',
'VERSION:2.0',
'BEGIN:VTIMEZONE',
'TZID:Etc/GMT',
'TZURL:http://tzurl.org/zoneinfo-outlook/Etc/GMT',
'X-LIC-LOCATION:Etc/GMT',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0000',
'TZOFFSETTO:+0000',
'TZNAME:GMT',
'DTSTART:19700101T000000',
'END:STANDARD',
'END:VTIMEZONE',
'END:VCALENDAR',
'',
].join('\n');
const expectedTimezoneComponent = `BEGIN:VTIMEZONE\r
TZID:Etc/GMT\r
TZURL:http://tzurl.org/zoneinfo-outlook/Etc/GMT\r
X-LIC-LOCATION:Etc/GMT\r
BEGIN:STANDARD\r
TZOFFSETFROM:+0000\r
TZOFFSETTO:+0000\r
TZNAME:GMT\r
DTSTART:19700101T000000\r
END:STANDARD\r
END:VTIMEZONE\r
`;
const expectedTimezoneComponent = [
'BEGIN:VTIMEZONE',
'TZID:Etc/GMT',
'TZURL:http://tzurl.org/zoneinfo-outlook/Etc/GMT',
'X-LIC-LOCATION:Etc/GMT',
'BEGIN:STANDARD',
'TZOFFSETFROM:+0000',
'TZOFFSETTO:+0000',
'TZNAME:GMT',
'DTSTART:19700101T000000',
'END:STANDARD',
'END:VTIMEZONE',
'',
].join('\n');

@@ -33,0 +37,0 @@ test('Correct timezone object for "GMT" timezone', () => {

const app = require('../index');
const expectedTimezoneObject = `BEGIN:VCALENDAR\r
PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN\r
VERSION:2.0\r
BEGIN:VTIMEZONE\r
TZID:America/North_Dakota/New_Salem\r
TZURL:http://tzurl.org/zoneinfo-outlook/America/North_Dakota/New_Salem\r
X-LIC-LOCATION:America/North_Dakota/New_Salem\r
BEGIN:DAYLIGHT\r
TZOFFSETFROM:-0600\r
TZOFFSETTO:-0500\r
TZNAME:CDT\r
DTSTART:19700308T020000\r
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0600\r
TZNAME:CST\r
DTSTART:19701101T020000\r
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\r
END:STANDARD\r
END:VTIMEZONE\r
END:VCALENDAR\r
`;
const expectedTimezoneObject = [
'BEGIN:VCALENDAR',
'PRODID:-//tzurl.org//NONSGML Olson 2018g-rearguard//EN',
'VERSION:2.0',
'BEGIN:VTIMEZONE',
'TZID:America/North_Dakota/New_Salem',
'TZURL:http://tzurl.org/zoneinfo-outlook/America/North_Dakota/New_Salem',
'X-LIC-LOCATION:America/North_Dakota/New_Salem',
'BEGIN:DAYLIGHT',
'TZOFFSETFROM:-0600',
'TZOFFSETTO:-0500',
'TZNAME:CDT',
'DTSTART:19700308T020000',
'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU',
'END:DAYLIGHT',
'BEGIN:STANDARD',
'TZOFFSETFROM:-0500',
'TZOFFSETTO:-0600',
'TZNAME:CST',
'DTSTART:19701101T020000',
'RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU',
'END:STANDARD',
'END:VTIMEZONE',
'END:VCALENDAR',
'',
].join('\n');
const expectedTimezoneComponent = `BEGIN:VTIMEZONE\r
TZID:America/North_Dakota/New_Salem\r
TZURL:http://tzurl.org/zoneinfo-outlook/America/North_Dakota/New_Salem\r
X-LIC-LOCATION:America/North_Dakota/New_Salem\r
BEGIN:DAYLIGHT\r
TZOFFSETFROM:-0600\r
TZOFFSETTO:-0500\r
TZNAME:CDT\r
DTSTART:19700308T020000\r
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU\r
END:DAYLIGHT\r
BEGIN:STANDARD\r
TZOFFSETFROM:-0500\r
TZOFFSETTO:-0600\r
TZNAME:CST\r
DTSTART:19701101T020000\r
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU\r
END:STANDARD\r
END:VTIMEZONE\r
`;
const expectedTimezoneComponent = [
'BEGIN:VTIMEZONE',
'TZID:America/North_Dakota/New_Salem',
'TZURL:http://tzurl.org/zoneinfo-outlook/America/North_Dakota/New_Salem',
'X-LIC-LOCATION:America/North_Dakota/New_Salem',
'BEGIN:DAYLIGHT',
'TZOFFSETFROM:-0600',
'TZOFFSETTO:-0500',
'TZNAME:CDT',
'DTSTART:19700308T020000',
'RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU',
'END:DAYLIGHT',
'BEGIN:STANDARD',
'TZOFFSETFROM:-0500',
'TZOFFSETTO:-0600',
'TZNAME:CST',
'DTSTART:19701101T020000',
'RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU',
'END:STANDARD',
'END:VTIMEZONE',
'',
].join('\n');

@@ -49,0 +53,0 @@ test('Correct timezone object for "America/North_Dakota/New_Salem" timezone', () => {

const app = require('../index');
test('Correct timezone object for nonexistent timezone', () => {
expect(app.getVtimezone('nonexistent')).toBe(null);
describe('Sync', () => {
test('Correct timezone object for nonexistent timezone', () => {
expect(app.getVtimezone('nonexistent')).toBe(null);
});
});
describe('Async', () => {
test('Reject for nonexistent timezone', async () => {
expect.assertions(1);
await expect(app.getVtimezoneAsync('nonexistent')).rejects.toThrowError(Error);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc