-
Run JS with a different TZ
From
Charles Blackburn@VERT/THEFBO to
nelgin on Sat Oct 14 10:58:43 2023
Re: Run JS with a different TZ
By: nelgin to Digital Man on Fri Oct 13 2023 18:57:42
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)
if you know it's in UTC format then something like this should work (first result from google)
https://stackoverflow.com/questions/10087819/convert-date-to-another-timezone-in-javascript
##### code from the above url
function convertTZ(date, tzString) {
return new Date((typeof date === "string" ? new Date(date) : date).toLocaleString("en-US", {timeZone: tzString}));
}
// usage: Asia/Jakarta is GMT+7
convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta") // Tue Apr 20 2012 17:10:30 GMT+0700 (Western Indonesia Time)
// Resulting value is regular Date() object
const convertedDate = convertTZ("2012/04/20 10:10:30 +0000", "Asia/Jakarta") convertedDate.getHours(); // 17
// Bonus: You can also put Date object to first arg
const date = new Date()
convertTZ(date, "Asia/Jakarta") // current date-time in jakarta.
charlie
---
þ Synchronet þ My Brand-New BBS
-
From
nelgin@VERT/EOTLBBS to
Charles Blackburn on Sat Oct 14 22:09:23 2023
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?
---
þ Synchronet þ End Of The Line BBS - endofthelinebbs.com
-
From
Charles Blackburn@VERT/THEFBO to
nelgin on Sun Oct 15 17:55:26 2023
Re: Run JS with a different TZ
By: nelgin to Charles Blackburn on Sat Oct 14 2023 22:09:23
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.
Charlie
---
þ Synchronet þ My Brand-New BBS
-
From
MRO@VERT/BBSESINF to
nelgin on Sun Oct 15 22:03:18 2023
Re: Run JS with a different TZ
By: nelgin to Charles Blackburn on Sat Oct 14 2023 10:09 pm
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?
this looks like a job for Chad Jipiti
---
þ Synchronet þ ::: BBSES.info - free BBS services :::
-
From
nelgin@VERT/EOTLBBS to
Charles Blackburn on Mon Oct 16 02:06:42 2023
Re: Run JS with a different TZ
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
in a similar way. if the string is in UTC you should be able to internally convert it to whatever TZ you want.
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.
---
þ Synchronet þ End Of The Line BBS - endofthelinebbs.com
-
From
Charles Blackburn@VERT/THEFBO to
nelgin on Mon Oct 16 13:09:06 2023
Re: Run JS with a different TZ
By: nelgin to Charles Blackburn on Mon Oct 16 2023 02:06:42
Re: Run JS with a different TZ
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
<CUT>
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.
well that sucks... maybe sbbs (unless there's a specific reason for it) should use the system-wide version maybe? I know it may be more work for the devs, but just my tuppence :D
as for the latter, maybe you should fork it and take it over lol
Charlie
---
þ Synchronet þ My Brand-New BBS
-
From
nelgin@VERT/EOTLBBS to
All on Thu Oct 12 13:29:08 2023
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? :)ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã
-
From
Digital Man@VERT to
nelgin on Thu Oct 12 12:03:23 2023
Re: Run JS with a different TZã By: nelgin to All on Thu Oct 12 2023 01:29 pmãã > 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)?ã-- ã digital man (rob)ããSynchronet "Real Fact" #59:ãSynchronet swag used to be available for purchase at cafepress.com/synchronetãNorco, CA WX: 79.0øF, 24.0% humidity, 4 mph NW wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
nelgin@VERT/EOTLBBS to
Digital Man on Fri Oct 13 12:11:31 2023
Re: Run JS with a different TZã By: Digital Man to nelgin on Thu Oct 12 2023 12:03:23ãã > 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)?ããThe only way I can find to get it the script to use a different timezone is to set the TZ variable before it is executed, at least while testing with jsexec.ããSince I will have to call it using ?script.js to make use of the bbs and console functions and properties, I'm not exactly sure how that would work.ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã
-
From
Digital Man@VERT to
nelgin on Fri Oct 13 10:51:43 2023
Re: Run JS with a different TZã By: nelgin to Digital Man on Fri Oct 13 2023 12:11 pmãã > Re: Run JS with a different TZã > By: Digital Man to nelgin on Thu Oct 12 2023 12:03:23ã >ã > > 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)?ã >ã > The only way I can find to get it the script to use a different timezone isã > to set the TZ variable before it is executed, at least while testing withã > jsexec.ã >ã > Since I will have to call it using ?script.js to make use of the bbs andã > console functions and properties, I'm not exactly sure how that would work.ããThat didn't really answer my question: How is your script using the timezone currently?ã-- ã digital man (rob)ããSynchronet/BBS Terminology Definition #88:ãUDP = User Datagram ProtocolãNorco, CA WX: 70.1øF, 59.0% humidity, 0 mph SE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
nelgin@VERT/EOTLBBS to
Digital Man on Fri Oct 13 13:47:36 2023
Re: Run JS with a different TZã By: Digital Man to nelgin on Fri Oct 13 2023 10:51:43ãã > That didn't really answer my question: How is your script using the timezoneã > currently?ããOh, I'm reading a JSON file which has an ISO 8601 format date, then I'm passing that to something like d = new Date(isoDate); to create a date object so I can extract the time easier, I think I use strftime to get HH:MMa/p but, of course, the time I get is in central and not eastern. I can't just subtract an hour because that's not going to work during DST changes.ããI hate to use something like moment-timezone for something like that, but it might be my only option unless you can think of something, I'm at a loss.ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã
-
From
Digital Man@VERT to
nelgin on Fri Oct 13 12:11:13 2023
Re: Run JS with a different TZã By: nelgin to Digital Man on Fri Oct 13 2023 01:47 pmãã > Re: Run JS with a different TZã > By: Digital Man to nelgin on Fri Oct 13 2023 10:51:43ã >ã > > That didn't really answer my question: How is your script using theã > > timezone currently?ã >ã > Oh, I'm reading a JSON file which has an ISO 8601 format date, then I'mã > passing that to something like d = new Date(isoDate); to create a dateã > object so I can extract the time easier, I think I use strftime to getã > HH:MMa/p but, of course, the time I get is in central and not eastern. Iã > can't just subtract an hour because that's not going to work during DSTã > changes.ã >ã > I hate to use something like moment-timezone for something like that, but itã > might be my only option unless you can think of something, I'm at a loss.ããDoes the ISO 8601 formatted date include the UTC offset?ã-- ã digital man (rob)ããSynchronet/BBS Terminology Definition #9:ãBPS = Bits Per SecondãNorco, CA WX: 75.9øF, 45.0% humidity, 0 mph SE wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
nelgin@VERT/EOTLBBS to
Digital Man on Fri Oct 13 14:42:52 2023
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ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã
-
From
Digital Man@VERT to
nelgin on Fri Oct 13 13:33:06 2023
Re: Run JS with a different TZã By: nelgin to Digital Man on Fri Oct 13 2023 02:42 pmãã > 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")'ããwhen run on my system (in PDT), produces:ãResult (string): Fri Oct 13 2023 13:30:31 GMT-0700 (PDT)ã-- ã digital man (rob)ããRush quote #75:ãThough his mind is not for rent, don't put him down as arrogant .. Tom SawyerãNorco, CA WX: 80.5øF, 28.0% humidity, 0 mph E wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
nelgin@VERT/EOTLBBS to
Digital Man on Fri Oct 13 18:57:42 2023
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.ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã
-
From
Digital Man@VERT to
nelgin on Fri Oct 13 21:06:05 2023
Re: Run JS with a different TZã By: nelgin to Digital Man on Fri Oct 13 2023 06:57 pmãã > 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.ã-- ã digital man (rob)ããRush quote #87:ãShifting shafts of shining weave the fabric of their dreams .. Jacob's LadderãNorco, CA WX: 66.1øF, 75.0% humidity, 0 mph SSW wind, 0.00 inches rain/24hrsã---ã þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.netã
-
From
nelgin@VERT/EOTLBBS to
Digital Man on Sat Oct 14 01:39:34 2023
Re: Run JS with a different TZã By: Digital Man to nelgin on Fri Oct 13 2023 21:06:05ãã > 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.ããDefinitely not what I 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.ããI'll probably stick with using the moment-timezone library then. I use it in my weather script so I'm not unfamiliar with it, but I was trying to see if there was a more native way to handle timezone conversions.ããThanks,ã---ã þ Synchronet þ End Of The Line BBS - endofthelinebbs.comã