I have a script that I want to run using a different timezone. My system is America/Chicago and I want users to run it from the xtrn section as America/New_York.
My original ideas was to create a bash wrapper script to set TZ and call jsexec but wont work since it requires various bbs and console functions to work properly.
Also, javascript doesn't appear to let you set an environment variable like you can with other languages such as perl.
Since I don't want to run my server or BBS in eastern time, does anyone have any suggestons on a workaround, other than to rewrtite it in perl? :)
How does your script use the timezone currently? Could that usage be updated to allow you to control the timezone used at run time (e.g. with a command-line option)?
Re: Run JS with a different TZ
By: Digital Man to nelgin on Fri Oct 13 2023 12:11:13
Does the ISO 8601 formatted date include the UTC offset?
This is an example of what I get, so the time is in UTC.
2023-10-13T23:30:00Z
Okay, so if it's in UTC, it's in central *or* eastern US. It's UTC.
Example:
jsexec '-r Date("2023-10-13T23:30:00Z")'
Re: Run JS with a different TZ
By: Digital Man to nelgin on Fri Oct 13 2023 13:33:06
Okay, so if it's in UTC, it's in central *or* eastern US. It's UTC.
Example:
jsexec '-r Date("2023-10-13T23:30:00Z")'
jsexec '-r Date("2023-10-13T23:30:00Z")'
Result (string): Fri Oct 13 2023 18:54:33 GMT-0500 (CDT)
Right, which gives a result in central time. I want the result in eastern time, as per:
TZ="America/New_York" jsexec '-r Date("2023-10-13T23:30:00Z")'
Result (string): Fri Oct 13 2023 19:55:42 GMT-0400 (EDT)
However, there's no way to set TZ before executing the script from the xtrn section since I'm not calling jsexec.
Right. And environment variables are shared among on threads (e.g. nodes) of the sbbs instance, so even if you could set the TZ environment variable, you'd be changing for all threads. Likely not what you want.
There's a whole new JS Date thing in the works for some future version of JavaScript, but that'll be aways away from being integrated with sbbs.
I think the easiest thing to do would be to adjust the UTC value based on the UTC offset for central time (yeah, it'll change with DST) and then use Date.toUTCString() to convert it to a string.
Re: Run JS with a different TZ
By: Digital Man to nelgin on Fri Oct 13 2023 13:33:06
Okay, so if it's in UTC, it's in central *or* eastern US. It's UTC.
Example:
jsexec '-r Date("2023-10-13T23:30:00Z")'
jsexec '-r Date("2023-10-13T23:30:00Z")'
Result (string): Fri Oct 13 2023 18:54:33 GMT-0500 (CDT)
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
Re: Run JS with a different TZ
By: Charles Blackburn to nelgin on Sat Oct 14 2023 10:58:43
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
You did actually try this and discovred it doesn't actually work, right?
Re: Run JS with a different TZ
By: Charles Blackburn to nelgin on Sat Oct 14 2023 10:58:43
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
You did actually try this and discovred it doesn't actually work, right?
can't say i did, i'm not a jS programmer, but was just throwing an idea out. but there should be a way to do it. In C/Python you can do it
in a similar way. if the string is in UTC you should be able to internally convert it to whatever TZ you want.
Re: Run JS with a different TZ<CUT>
By: Charles Blackburn to nelgin on Sun Oct 15 2023 17:55:26
can't say i did, i'm not a jS programmer, but was just throwing an idea out. but there should be a way to do it. In C/Python you can do it
Unforuntately, there isn't. That's why there's moment-timezone and Luxon. Unfortunately Luxon is too modern to work with the sbbs version of js. moment-timezone is no longer developed or supported but at least it works.
Sysop: | Rempala |
---|---|
Location: | Richlands, NC |
Users: | 106 |
Nodes: | 10 (0 / 10) |
Uptime: | 173:43:19 |
Calls: | 249 |
Files: | 6 |
Messages: | 110,854 |