Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/capaj/set-tz
sets the timezone for your node.js process across all OSes
https://github.com/capaj/set-tz
cli oses timezone windows
Last synced: 2 days ago
JSON representation
sets the timezone for your node.js process across all OSes
- Host: GitHub
- URL: https://github.com/capaj/set-tz
- Owner: capaj
- License: mit
- Created: 2017-01-10T00:34:36.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-10T02:38:25.000Z (over 1 year ago)
- Last Synced: 2024-04-09T21:10:36.090Z (6 months ago)
- Topics: cli, oses, timezone, windows
- Language: JavaScript
- Size: 531 KB
- Stars: 42
- Watchers: 3
- Forks: 5
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# set-tz DEPRECATED
You may need this for nodejs 16 and lower. Nodejs 17 behaves the same in regards to the timezone as in other OSes. See https://github.com/nodejs/node/issues/4230#issuecomment-955776233
sets the timezone for your node.js process across all OSes
## sample usage
```javascript
const setTZ = require('set-tz')
setTZ('UTC')
// that's it
```It will even convert between operating systems
```javascript
const setTZ = require('set-tz')
setTZ('America/New_York')
```This will set timezone to `America/New_York` in non-Windows environments.
In Windows environments, it will set the timezone to Eastern Standard Time (because Windows doesn't respect IANA timezones).## Jest usage
It is common to run all your tests in UTC no matter which timezone your computer is in. This ensures your snapshots will run fine on you CI and on your local machine no matter where you are located. If you need that, then you can use a shortcut:
```json
"jest": {
"globalSetup": ['set-tz/utc']
}
```## Windows caveat
On Windows, when you call `setTZ()` it effectively changes your whole OS timezone so beware-if you kill the process, you'll need to manually revert back after you're done - I am assuming your process is short-lived. If you don't kill your process, it will revert your original timezone back for you.
On all other OSes, it just sets `process.env.TZ`, so beware that the current process won't have the timezome set. Only its children.