timezones-ical-library 1.1.5 → 1.2.0

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/Readme.md CHANGED
@@ -62,7 +62,9 @@ Use `tzlib_get_timezones()` to retrieve a list of all available timezone strings
62
62
 
63
63
  #### B. Get the iCal timezone block
64
64
 
65
- Use the `tzlib_get_ical_block(tzName)` function to return the proper iCal VTIMEZONE block for a given timezone string (tzName).
65
+ 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).
66
+
67
+ 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.
66
68
 
67
69
  Include this into your further iCal data to come up with a complete ics file.
68
70
 
@@ -71,7 +73,7 @@ A final constellation could look like this:
71
73
  ```
72
74
  BEGIN:VCALENDAR
73
75
  VERSION:2.0
74
- PRODID:-// github.com/add2cal/add-to-calendar-button // atcb v1.14.6 //EN
76
+ PRODID:-// github.com/add2cal/add-to-calendar-button //EN
75
77
  CALSCALE:GREGORIAN
76
78
  ```
77
79
 
package/dist/tzlib.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Add to Calendar TimeZones iCal Library
4
4
  * ++++++++++++++++++++++++++++++++++++++
5
5
  */
6
- const tzlibVersion = '1.1.5';
6
+ const tzlibVersion = '1.2.0';
7
7
  /* Creator: Jens Kuerschner (https://jenskuerschner.de)
8
8
  * Project: https://github.com/add2cal/timezones-ical-library
9
9
  * License: Apache-2.0
@@ -610,14 +610,21 @@ const tzlibZonesDB = {
610
610
 
611
611
 
612
612
  // LOADING THE RIGHT CODE BLOCK
613
- function tzlib_get_ical_block(tzName) {
613
+ function tzlib_get_ical_block(tzName, jsonType = false) {
614
614
  // validate timezone
615
615
  if (!tzlibZonesDB[`${tzName}`]) {
616
616
  console.error('Given timezone not valid.');
617
617
  return '';
618
618
  }
619
619
  // otherwise, create the output
620
- return 'BEGIN:VTIMEZONE\r\n' + tzlibZonesDB[`${tzName}`].replace(/[^\w_\-:,;=\+\/<br>]/g,'').replace(/<br>/g, '\r\n') + '\r\nEND:VTIMEZONE';
620
+ const tzBlock = tzlibZonesDB[`${tzName}`].replace(/[^\w_\-:,;=\+\/<br>]/g,'').replace(/<br>/g, '\r\n');
621
+ const tzidLine = tzBlock.split('\r\n')[0];
622
+ const output = ['BEGIN:VTIMEZONE\r\n' + tzBlock + '\r\nEND:VTIMEZONE', tzidLine];
623
+ // return
624
+ if (jsonType) {
625
+ return JSON.stringify(output);
626
+ }
627
+ return output;
621
628
  }
622
629
 
623
630
  // PROVIDING THE OFFSET BASED ON A GIVEN DATE AND TIME (YYYY-MM-DD and hh:mm as per ISO-8601).