• 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.c­om/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,myTZDeltaMi­ns);
    var mySunset = dateLocalTZ(gmtTimes.sunset,myTZDeltaMin­s);
    
    console.log('mySunrise',dateStrMinusTZ(m­ySunrise));
    console.log('mySunset',dateStrMinusTZ(my­Sunset));
    
    if ( (gmtDateNow > gmtTimes.sunrise) && (gmtDateNow < gmtTimes.sunset) ) {
      console.log('it should be light outside');
    } else {
        console.log('it should be dark outside');
    }
    
About

Avatar for user58511 @user58511 started