Skip to content

Commit bcec850

Browse files
authored
Merge pull request #22 from jekuer/timezone_tweak
support dynamic user timezone
2 parents e78c980 + 379e2d1 commit bcec850

File tree

9 files changed

+19
-12
lines changed

9 files changed

+19
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ const AddToCalendar = () => {
198198
* If the timeZoneOffset is set, it will always override the timeZone. It is recommended to only use 1 of them at a time.
199199
* The timeZone might not work in very old browsers, but also considers dynamic changes like summer/winter time.
200200
* timeZoneOffset works with older browsers, but is quite static.
201+
* Use "currentBrowser" as value for timeZone to dynamically use the time of the user's browser. Use this with caution, since it would mean that the date and time will differ per user, which should not be the usual case! (Requires all times to be set.)
201202
* You can set the trigger to "click". This makes the button open on click at desktop. Otherwise, the default would be to open on hover. On touch devices, this makes no difference.
202203
* If you want to define a specific name for any generated ics file (iCal), you can specify it via the "iCalFileName" option. The default would be "event-to-save-in-my-calendar".
203204
* You can use the option "inline":true in order to make the button appear with inline-block instead of block style.

assets/css/atcb.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Add-to-Calendar Button
44
* ++++++++++++++++++++++
55
*
6-
* Version: 1.4.2
6+
* Version: 1.4.3
77
* Creator: Jens Kuerschner (https://jenskuerschner.de)
88
* Project: https://github.com/jekuer/add-to-calendar-button
99
* License: MIT with “Commons Clause” License Condition v1.0

assets/js/atcb.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Add-to-Calendar Button
44
* ++++++++++++++++++++++
55
*/
6-
const atcbVersion = '1.4.2';
6+
const atcbVersion = '1.4.3';
77
/* Creator: Jens Kuerschner (https://jenskuerschner.de)
88
* Project: https://github.com/jekuer/add-to-calendar-button
99
* License: MIT with “Commons Clause” License Condition v1.0
@@ -536,6 +536,9 @@ function atcb_generate_time(data, style = 'delimiters', targetCal = 'general') {
536536
if (data['timeZone'] != null && data['timeZone'] != '') {
537537
// if a timezone is given, we adjust dynamically with the modern toLocaleString function
538538
let utcDate = new Date(start.toLocaleString('en-US', { timeZone: "UTC" }));
539+
if (data['timeZone'] == 'currentBrowser') {
540+
data['timeZone'] = Intl.DateTimeFormat().resolvedOptions().timeZone;
541+
}
539542
let tzDate = new Date(start.toLocaleString('en-US', { timeZone: data['timeZone'] }));
540543
let offset = utcDate.getTime() - tzDate.getTime();
541544
start.setTime( start.getTime() + offset );

assets/js/atcb.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/js/atcb.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,13 @@
115115
</style>
116116

117117
<!-- load the general button css -->
118-
<link rel="stylesheet" href="./assets/css/atcb.min.css?v=1.4.2">
118+
<link rel="stylesheet" href="./assets/css/atcb.min.css?v=1.4.3">
119119

120120
</head>
121121
<body>
122122
<div class="container">
123123

124-
<h1>Add-to-Calendar Button <span id="tinyVersion">v1.4.2</span></h1>
124+
<h1>Add-to-Calendar Button <span id="tinyVersion">v1.4.3</span></h1>
125125
<h2>A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.</h2>
126126
<p class="github">
127127
<a target="_blank" href="https://github.com/jekuer/add-to-calendar-button">
@@ -513,8 +513,8 @@ <h3>Example 7: Schema.org Event Markup</h3>
513513

514514

515515
<!-- load the button js -->
516-
<script type="application/javascript" src="./assets/js/atcb.min.js?v=1.4.2" defer></script>
516+
<script type="application/javascript" src="./assets/js/atcb.min.js?v=1.4.3" defer></script>
517517

518518

519519
</body>
520-
</html>
520+
</html>

npm_dist/atcb_npm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Add-to-Calendar Button
44
* ++++++++++++++++++++++
55
*/
6-
const atcbVersion = '1.4.2';
6+
const atcbVersion = '1.4.3';
77
/* Creator: Jens Kuerschner (https://jenskuerschner.de)
88
* Project: https://github.com/jekuer/add-to-calendar-button
99
* License: MIT with “Commons Clause” License Condition v1.0
@@ -536,6 +536,9 @@ function atcb_generate_time(data, style = 'delimiters', targetCal = 'general') {
536536
if (data['timeZone'] != null && data['timeZone'] != '') {
537537
// if a timezone is given, we adjust dynamically with the modern toLocaleString function
538538
let utcDate = new Date(start.toLocaleString('en-US', { timeZone: "UTC" }));
539+
if (data['timeZone'] == 'currentBrowser') {
540+
data['timeZone'] = Intl.DateTimeFormat().resolvedOptions().timeZone;
541+
}
539542
let tzDate = new Date(start.toLocaleString('en-US', { timeZone: data['timeZone'] }));
540543
let offset = utcDate.getTime() - tzDate.getTime();
541544
start.setTime( start.getTime() + offset );

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "add-to-calendar-button",
3-
"version": "1.4.2",
3+
"version": "1.4.3",
44
"description": "A convenient JavaScript snippet, which lets you create beautiful buttons, where people can add events to their calendars.",
55
"main": "npm_dist/atcb_npm.js",
66
"types": "index.d.ts",

0 commit comments

Comments
 (0)