Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor system timezone changes #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jeroenvollenbrock
Copy link

@jeroenvollenbrock jeroenvollenbrock commented Apr 15, 2018

As discussed in #2 and nodejs/node#20026, It is possible to listen for system timezone changes and automatically reset the cache upon these events (although the lack of standard api's make it a bit cumbersome). This PR adds listeners for timezone change events on windows, osx and unix, as well as a method to register a hook. I'm really not sure if this should be a separate node module, a new version of your module (since node might start resetting the cache on its own in the future), a Node.js feature or maybe even a libuv handle (libuv/libuv#1176).

The following code can be used to test the response to system events:

var resetCache = require('reset-date-cache');

resetCache.registerHook(() => console.log(new Date().toString()));
console.log(new Date().toString());

//The timezone notifier is not referenced, set a dummy interval to keep running
setInterval(()=>{},1000); 

On unix the /etc/localtime, /etc/timezone and /etc/TZ files are monitored (this apparently has the broadest support), and on windows the HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation registry key is monitored. The monitoring happens using inotify, fsevents and RegNotifyChangeKeyValue, so there are no active or resource-intensive tasks continuously running.

Tested on windows, osx and linux :)

Base automatically changed from master to main March 8, 2021 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant