My computer's timezone is set correctly, but the Pico seems to be set to GMT no matter what.
Here is the code I am using to find out my local sunrise & sunset -- it relies on a variable containing my timezone offset, which I must keep up-to-date based on DST here...
The trick for me is to just do everything as GMT and then only change for the display
// myWhere and TZ offset
var myLatitude = 41.0;
var myLongitude = -72.0;
var myTZDeltaMins = -300;
var gmtDateNow = Date.now();
var suncalc = require("https://raw.githubusercontent.com/mourner/suncalc/master/suncalc.js");
function dateLocalTZ( gmtDate, tzMins ) {
return new Date(gmtDate.getTime() + (tzMins*60000));
}
function dateStrMinusTZ ( anyDate ) {
return anyDate.toString().replace(' GMT+0000','');
}
var gmtTimes = suncalc.getTimes( gmtDateNow, myLatitude, myLongitude );
var mySunrise = dateLocalTZ(gmtTimes.sunrise,myTZDeltaMins);
var mySunset = dateLocalTZ(gmtTimes.sunset,myTZDeltaMins);
console.log('mySunrise',dateStrMinusTZ(mySunrise));
console.log('mySunset',dateStrMinusTZ(mySunset));
if ( (gmtDateNow > gmtTimes.sunrise) && (gmtDateNow < gmtTimes.sunset) ) {
console.log('it should be light outside');
} else {
console.log('it should be dark outside');
}
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
My computer's timezone is set correctly, but the Pico seems to be set to GMT no matter what.
Here is the code I am using to find out my local sunrise & sunset -- it relies on a variable containing my timezone offset, which I must keep up-to-date based on DST here...
The trick for me is to just do everything as GMT and then only change for the display