You are reading a single comment by @asez73 and its replies. Click here to read the full conversation.
  • Hi @Gordon,
    I am playing with time zones vs UTC & GMT those days and found this to be a problem:

    new Date().getTimezoneOffset()
    =-60
    >new Date(2019,1,7,10,34-60,19,0)
    =Date: Thu Feb 7 2019 09:34:19 GMT+0100
    >new Date(2019,1,7,9,34+60,19,0)
    =Date: Thu Feb 7 2019 09:34:19 GMT+0100
    >new Date(2019,1,7,8,49+60,19,0)
    =Date: Thu Feb 7 2019 08:49:19 GMT+0100
    >new Date(2019,1,7,0,34-60,19,0)
    =Date: Wed Feb 6 2019 23:34:19 GMT+0100
    >new Date(2019,1,7,0,34+60,19,0)
    =Date: Thu Feb 7 2019 00:34:19 GMT+0100
    

    So, if I use a negative minute, the hour will be correctly handled while using an over 60 minutes minute parameter will not increment the hour....

    This all about gps providing UTC time while I have to handle local day time and winter / summer changes. Beeing in continental Europe, I have an approximative approach (not world wide) which gave me the following functions to get summer / winter day light savings:

    // https://www.calendrier-365.fr/heure-d-et­e-heure-d-hiver.html
    
    function jourFinHiver(annee) { // last sunday of march
      return Math.floor(31.8 - ((((5 * annee) / 4) + 4) % 7));
    }
    
    function jourFinEte(annee) { // last sunday of october
      return Math.floor(31.8 - ((((5 * annee) / 4) + 1) % 7));
    }
    
    function hiver() {
      today= new Date();
      month=1+today.getMonth(); // so 1 based
      if ([1,2,11,12].indexOf(month)>=0) return true;
      if (month===3) return today.getDay() < jourFinHiver(today.getFullYear()); // TDB take care of first hours of day which is still in winter
      if (month===10) return today.getDay() >= jourFinEte(today.getFullYear()); // TDB take care of first hours of day which is still in summer
      return true;
    }
    
    // Set the system time zone in agreement with Uk & Europe day ligth savings (aka winter / summer time) UTCwinterToGMT = 0 for UK, 1 for France/Benelux/Germany...
    function setTimeZone(UTCwinterToGMT) {
      E.setTimeZone(UTCwinterToGMT + (hiver() ? 0 : 1));
    }
    
    // Only valid in Europe (UTC winter to GMT=+1) and UK (UTC winter to GMT = 0)
    function localDayTimeHour(UTCwinterToGMT) { // valid for UTC+1-UTC+2 in continental Europe
      setTimeZone(UTCwinterToGMT); // Handle time zone at system level
      return (new Date().getHours() ) % 24;
    }
    
    

    So references above are in french... Which is fine for me :)

About

Avatar for asez73 @asez73 started