Skip to content

Commit

Permalink
Merge pull request #28 from add2cal/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jekuer committed Oct 1, 2022
2 parents f25d01d + a6aea68 commit 816601c
Show file tree
Hide file tree
Showing 667 changed files with 9,987 additions and 34,837 deletions.
39 changes: 39 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"root": true,
"env": {
"browser": true,
"es2021": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:security/recommended",
"prettier"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module",
"xss/no-mixed-html": [
2,
{
"functions": {
".encodeURIComponent": {
"passthrough": { "obj": true, "args": true }
}
}
}
]
},
"plugins": ["@typescript-eslint"],
"ignorePatterns": [
"*.min.*",
"Gruntfile.js",
"zonesdb.js",
"generator.js",
"set-release.js",
"npm_dist/",
"dist/"
],
"rules": {}
}
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Tests

on:
on:
pull_request:
branches: [main, dev]

Expand Down
7 changes: 6 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@ set-release.js
test/
package-lock.json
sitemap.xml
*.min.css
*.min.js
*.map

# plus all the maker stuff, which is not already ignored for Git

tzdata/
zoneinfo/
api/*.ics
api/*/
Makefile
*.c
*.tab
*.h
*.sh
*.pl
8 changes: 8 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Ignore html files
*.html

# Ignore css files
*.css

# Ignore minified files
*.min.*
8 changes: 8 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"proseWrap": "preserve",
"printWidth": 110,
"embeddedLanguageFormatting": "off",
"useTabs": false,
"singleQuote": true,
"arrowParens": "always"
}
8 changes: 8 additions & 0 deletions .stylelintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": ["stylelint-config-standard", "stylelint-config-prettier"],
"ignoreFiles": ["**/*.min.css"],
"rules": {
"selector-class-pattern": null,
"property-no-vendor-prefix": null
}
}
22 changes: 18 additions & 4 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const fs = require('fs');
const tzDbPlaceholder = /\/\/ PLACE ZONES DB HERE/g;
const tzDbPlaceholder = /let tzlibZonesDB,(\s)*tzlibZonesDetailsDB = {};/gm;
const exportCodePlaceholder = /\/\/ PLACE EXPORT HERE/g;
const zoneNamesPlaceholder = /\['%%PLACE ZONE NAMES HERE%%'\]/g;
const tzDbContent = fs.readFileSync('./src/zonesdb.js', 'utf-8');
const tzNamesList = fs.readFileSync('./api/zones.json', 'utf-8');

function prepareFinalFile(content, exportPhrase = '') {
let newContent = content.replace(tzDbPlaceholder, tzDbContent);
let newContent = content.replace(tzDbPlaceholder, tzDbContent).replace(zoneNamesPlaceholder, tzNamesList);
if (exportPhrase != '') {
newContent = newContent.replace(exportCodePlaceholder, `${exportPhrase} { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones };`);
newContent = newContent.replace(
exportCodePlaceholder,
`${exportPhrase} { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones };`
);
} else {
newContent = newContent.replace(exportCodePlaceholder, '');
}
Expand Down Expand Up @@ -99,6 +104,15 @@ module.exports = function (grunt) {
done();
},
},
'.eslintrc.json commonJS': {
'npm_dist/cjs/.eslintrc.json': function (fs, fd, done) {
fs.writeSync(
fd,
'{ "extends": "../../.eslintrc.json", "env": { "node": true }, "plugins": ["commonjs"] }'
);
done();
},
},
},
// minifies the main js file
uglify: {
Expand All @@ -124,7 +138,7 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-file-creator');
grunt.loadNpmTasks('grunt-version');

// Register task(s).
// Register task(s)
grunt.registerTask('default', ['clean', 'cssmin', 'copy:plain_dist', 'uglify']);
grunt.registerTask('npm', ['clean', 'cssmin', 'copy', 'file-creator', 'uglify']);
};
19 changes: 18 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,31 @@ OLSON_DIR ?= tzdata
# changed, it bumps the version number on the end of this prefix. */
TZID_PREFIX ?= /timezones-ical-library/

# This is used to indicate how timezone aliases (indicated by a Link line
# in Olson files) should be generated: The default is to symbolically link
# the Link zone file to its authorative zone. Alternatively, if set to 0,
# a VTIMEZONE file is generated for each Link.
CREATE_SYMLINK ?= 1

# This indicates if top-level timezone aliases (a timezone name without
# any '/' such as "EST5EDT") should be ignored. If 0, a VTIMEZONE is
# generated also for top-level aliases. This option only has
# an effect if CREATE_SYMLINK is 0, and mainly is useful for backward
# compatibility with previous vzic versions.
IGNORE_TOP_LEVEL_LINK ?= 1

#
# You shouldn't need to change the rest of the file.
#

GLIB_CFLAGS = `pkg-config --cflags glib-2.0`
GLIB_LDADD = `pkg-config --libs glib-2.0`

CFLAGS = -g -DOLSON_DIR=\"$(OLSON_DIR)\" -DTZID_PREFIX='"$(TZID_PREFIX)"' $(GLIB_CFLAGS) $(LIBICAL_CFLAGS)
CFLAGS = -g -DOLSON_DIR=\"$(OLSON_DIR)\" -DPRODUCT_ID='"$(PRODUCT_ID)"'
CFLAGS += -DTZID_PREFIX='"$(TZID_PREFIX)"'
CFLAGS += -DCREATE_SYMLINK=$(CREATE_SYMLINK)
CFLAGS += -DIGNORE_TOP_LEVEL_LINK=$(IGNORE_TOP_LEVEL_LINK)
CFLAGS += $(GLIB_CFLAGS) $(LIBICAL_CFLAGS)

OBJECTS = vzic.o vzic-parse.o vzic-dump.o vzic-output.o

Expand Down
73 changes: 46 additions & 27 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Add to Calendar TimeZones iCal Library

The tool to convert the [IANA (formerly Olson) timezone database files](http://www.iana.org/time-zones) into VTIMEZONE blocks, compatible with the iCalendar specification (RFC2445).
The tool to convert the [IANA (formerly Olson) time zone database files](http://www.iana.org/time-zones) into VTIMEZONE blocks, compatible with the iCalendar specification (RFC2445).

It is based on the awesome tool by Damon Chaplin ([github.com/libical/vzic](https://github.com/libical/vzic)), but only provides the VTIMEZONE part to easily put this into any other iCal generator (like the [add-to-calendar-button](https://github.com/add2cal/add-to-calendar-button)). It is built to be used standalone or as JavaScript module, hosted as npm package.

Expand All @@ -18,51 +18,42 @@ It is based on the awesome tool by Damon Chaplin ([github.com/libical/vzic](http

### 0. Update it (not required)

**This step is only relevant if you want to build the package and data from source!**
*(Requires Node.js as well as Linux as operating system.)*
**This step is only relevant if you want to build the package and data on your own and from source!**
_(Requires Node.js as well as Linux as operating system.)_
Run ...

```
sudo sh update-tzdata.sh tzVersionNumber
```

... with *tzVersionNumber* being the version of the IANA timezone database you want to use (e.g. sudo sh update-tzdata.sh 2022c).
... with _tzVersionNumber_ being the version of the IANA time zone database you want to use (e.g. sudo sh update-tzdata.sh 2022d).

<br />

### 1. Load it

#### A. VanillaJS

You can use the pure and simple version directly from the dist folder or the jsDelivr CDN and include in your application:

```
<script src="https://cdn.jsdelivr.net/npm/timezones-ical-library"></script>
```

#### B. npm package

Alternatively, you can install the package via npm with:
Install the package via npm with:

```
npm install timezones-ical-library
```

After the installation:

- require the package (commonJS) or ...
- import the module (ES) via `import { tzlib_get_ical_block, tzlib_get_offset, tzlib_get_timezones } from 'timezones-ical-library';`.

<br />

### 2. Use it

#### A. Get timezones
#### A. Get time zones

Use `tzlib_get_timezones()` to retrieve a list of all available timezone strings. You can pass `true` to retrieve a JSON formatted string instead of an array.
Use `tzlib_get_timezones()` to retrieve a list of all available time zone strings. You can pass `true` to retrieve a JSON formatted string instead of an array.

#### B. Get the iCal timezone block
#### B. Get the iCal time zone block

Use the `tzlib_get_ical_block(tzName)` function to return the proper iCal VTIMEZONE block for a given timezone string (tzName). Again, pass `true` to retrieve a JSON formatted string instead of an array (not recommended).
Use the `tzlib_get_ical_block(tzName)` function to return the proper iCal VTIMEZONE block for a given time zone string (tzName). Again, pass `true` to retrieve a JSON formatted string instead of an array (not recommended).

You will receive an array, holding the VTIMEZONE block first, and the TZID line (additionally) second. The latter one is needed for any further time statement.

Expand All @@ -79,7 +70,7 @@ CALSCALE:GREGORIAN

```
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/20220824/America/New_York
TZID:America/New_York
LAST-MODIFIED:20220824T133813Z
X-LIC-LOCATION:America/New_York
BEGIN:DAYLIGHT
Expand All @@ -103,8 +94,8 @@ END:VTIMEZONE
BEGIN:VEVENT
UID:2022-08-30T19:29:38.618Z@add-to-calendar-button
DTSTAMP:20230214T091500Z
DTSTART;TZID=/timezones-ical-library/20220824/America/New_York:20230214T091500
DTEND;TZID=/timezones-ical-library/20220824/America/New_York:20230218T223000
DTSTART;TZID=America/New_York:20230214T091500
DTEND;TZID=America/New_York:20230218T223000
SUMMARY:A sample event
DESCRIPTION:Just some descriptive text...
LOCATION:World Wide Web
Expand All @@ -119,7 +110,34 @@ END:VCALENDAR

Use `tzlib_get_offset(tzName, isoDate, isoTime)` to get specific offset (relative to UTC), based on a provided date and time.

For example, you can provide *tzName* `'Europe/Berlin'`, *isoDate* `'2023-05-23'`, and *isoTime* `'15:45'` in order to retrieve the offset, which applies for this timezone at the 23rd of May in 2023 at exactly 15:45.
For example, you can provide _tzName_ `'Europe/Berlin'`, _isoDate_ `'2023-05-23'`, and _isoTime_ `'15:45'` in order to retrieve the offset, which applies for this time zone at the 23rd of May in 2023 at exactly 15:45.

<br /><br />

---

<br />

## ⚙️ API

Instead of using this code or the npm package, you could also make use of the free and open API.

### Getting a list of all zone names

```
https://tz.add-to-calendar-technology.com/api/zones.json
```

### Getting the ics part of a respective zone

```
https://tz.add-to-calendar-technology.com/api/%zoneName%.ics
```

With %zoneName% being your time zone. So, for New York, this would be [https://tz.add-to-calendar-technology.com/api/America/New_York.ics](https://tz.add-to-calendar-technology.com/api/America/New_York.ics).
**This is case sensitive!**

(Mind that this does not deliver a fully valid ics file, since it only contains the VTIMEZONE part. You will need to combine this with your other event information.)

<br /><br />

Expand All @@ -145,6 +163,7 @@ Licensed under [Apache-2.0](LICENSE).

## ⚡ Changelog (without minor changes and fixes)

- v1.3 : bundle size optimization and API
- v1.2 : providing tzblock as array with separate tzid
- v1.1 : get-offset function
- v1.0 : initial release
Expand All @@ -155,7 +174,7 @@ Licensed under [Apache-2.0](LICENSE).

## 💜 Kudos go to

* The ["Time Zone King"](https://samueli.ucla.edu/time-zone-king-how-one-ucla-computer-scientist-keeps-digital-clocks-ticking/) [Paul Eggert](https://github.com/eggert) for optimizing timezones for the web, ...
* as well as all the contributors at [the official tz repository](https://github.com/eggert/tz).
* The awesome authors of zic and [vzic](https://github.com/libical/vzic/graphs/contributors); mainly Damon Chaplin, [Allen Winter](https://github.com/winterz), and [Ken Murchison](https://github.com/ksmurchison).
* [Trevor Eyre](https://github.com/trevoreyre) for his smooth and beautiful [autocomplete script](https://github.com/trevoreyre/autocomplete).
- The ["Time Zone King"](https://samueli.ucla.edu/time-zone-king-how-one-ucla-computer-scientist-keeps-digital-clocks-ticking/) [Paul Eggert](https://github.com/eggert) for optimizing time zones for the web, ...
- as well as all the contributors at [the official tz repository](https://github.com/eggert/tz).
- The awesome authors of zic and [vzic](https://github.com/libical/vzic/graphs/contributors); mainly Damon Chaplin, [Allen Winter](https://github.com/winterz), and [Ken Murchison](https://github.com/ksmurchison).
- [Trevor Eyre](https://github.com/trevoreyre) for his smooth and beautiful [autocomplete script](https://github.com/trevoreyre/autocomplete).
4 changes: 3 additions & 1 deletion zoneinfo/Africa/Abidjan.ics → api/Africa/Abidjan.ics
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/Africa/Abidjan
LAST-MODIFIED:20220831T191120Z
X-LIC-LOCATION:Africa/Abidjan
LAST-MODIFIED:20220929T150625Z
BEGIN:STANDARD
TZNAME:GMT
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
4 changes: 3 additions & 1 deletion zoneinfo/Africa/Algiers.ics → api/Africa/Algiers.ics
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/Africa/Algiers
LAST-MODIFIED:20220831T191120Z
X-LIC-LOCATION:Africa/Algiers
LAST-MODIFIED:20220929T150625Z
BEGIN:STANDARD
TZNAME:CET
TZOFFSETFROM:+0100
TZOFFSETTO:+0100
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
4 changes: 3 additions & 1 deletion zoneinfo/Africa/Bissau.ics → api/Africa/Bissau.ics
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/Africa/Bissau
LAST-MODIFIED:20220831T191120Z
X-LIC-LOCATION:Africa/Bissau
LAST-MODIFIED:20220929T150625Z
BEGIN:STANDARD
TZNAME:GMT
TZOFFSETFROM:+0000
TZOFFSETTO:+0000
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
4 changes: 3 additions & 1 deletion zoneinfo/Africa/Cairo.ics → api/Africa/Cairo.ics
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/Africa/Cairo
LAST-MODIFIED:20220831T191120Z
X-LIC-LOCATION:Africa/Cairo
LAST-MODIFIED:20220929T150625Z
BEGIN:STANDARD
TZNAME:EET
TZOFFSETFROM:+0200
TZOFFSETTO:+0200
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
4 changes: 3 additions & 1 deletion zoneinfo/Africa/Casablanca.ics → api/Africa/Casablanca.ics
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
BEGIN:VTIMEZONE
TZID:/timezones-ical-library/Africa/Casablanca
TZUNTIL:20870511T020001Z
LAST-MODIFIED:20220831T191120Z
X-LIC-LOCATION:Africa/Casablanca
LAST-MODIFIED:20220929T150625Z
BEGIN:STANDARD
TZNAME:+01
TZOFFSETFROM:+0100
TZOFFSETTO:+0100
DTSTART:19700101T000000
END:STANDARD
END:VTIMEZONE
Loading

0 comments on commit 816601c

Please sign in to comment.