• Resolved fwoit

    (@fwoit)


    In Poll Options > Settings > General Options where you can set a Start Date and End Date for the poll these values actually get calculated to be one day less than what is selected. There is no mention of this being the case but this is how it actually gets calculated. For example if you select the start date for the poll to be tomorrow it will actually be active today, at least this is true for my time zone of EST (GMT -5). You currently store these date values in the table “totalsoft_poll_setting” in the format yyyy-mm-dd. There is a well documented issue with the javascript new Date() function when the date is stored in this format where the day gets calculated to one day less than what is actually entered. Example of another forum topic on the issue “https://stackoverflow.com/questions/7556591/is-the-javascript-date-object-always-one-day-off”. In your “Total-Soft-Poll-Widget.js” the function “Total_Soft_Poll_Upcoming” is where the start date is calculated and in the function “Total_Soft_Poll_End_Poll” is where the end date is calculated. With the dates being stored in the yyyy-mm-dd format they will always be calculated as one day less than what the user has selected on the poll settings page. To fix this issue you can simply store the start and end dates in mm-dd-yyyy format and then the javascript new Date() function will calculate it to be the actual date that the user entered in the poll settings page rather than minus one day from what the user entered.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter fwoit

    (@fwoit)

    For others having the same issue with the start and end poll dates being calculated incorrectly I’ve added 4 lines of code into the “Total-Soft-Poll-Widget.js” file to fix the issue. If you’d like to update the file yourselves here are the two updated functions that you would need to replace in the original file.

    function Total_Soft_Poll_Upcoming(Poll_ID) {
      var datereal=new Date(), currentMonth=datereal.getMonth() + 1, currentYear=datereal.getFullYear(),
        currentDay=datereal.getDate();
    
      var TotalSoft_Poll_Set_02=jQuery('#TotalSoft_Poll_Set_02_' + Poll_ID).val();
      var thisDate = TotalSoft_Poll_Set_02.split('-'); //added by fwoit 12-01-2020 to fix the issue with the poll start date being calculated as one day behind the actual selected user date in the poll settings. Splits yyyy-mm-dd into its various parts
      var TotalSoft_Poll_Set_02 = [thisDate[1],thisDate[2],thisDate[0] ].join("-"); //added by fwoit 12-01-2020 to fix the issue with the poll start date being calculated as one day behind the actual selected user date in the poll settings.  Reorganizes date as mm-dd-yyyy
      var datestart=new Date(TotalSoft_Poll_Set_02), startMonth=datestart.getMonth() + 1, startYear=datestart.getFullYear(),
        startDay=datestart.getDate();
    
      var Total_Soft_Poll_Upcoming_Bool=false;
      if(currentYear < startYear) {
        Total_Soft_Poll_Upcoming_Bool=true;
      }
      else if(currentYear==startYear) {
        if(currentMonth < startMonth) {
          Total_Soft_Poll_Upcoming_Bool=true;
        }
        else if(currentMonth==startMonth) {
          if(currentDay < startDay) {
            Total_Soft_Poll_Upcoming_Bool=true;
          }
        }
      }
    
      if(Total_Soft_Poll_Upcoming_Bool===true) {
        jQuery('.TotalSoftPoll_Ans_ComingSoon_' + Poll_ID).css('display', 'block');
      }
      else {
        jQuery('.TotalSoftPoll_Ans_ComingSoon_' + Poll_ID).css('display', 'none');
      }
    }
    
    function Total_Soft_Poll_End_Poll(Poll_ID, Poll_Type) {
      var datereal=new Date(), currentMonth=datereal.getMonth() + 1, currentYear=datereal.getFullYear(),
        currentDay=datereal.getDate();
    
      var TotalSoft_Poll_Set_03=jQuery('#TotalSoft_Poll_Set_03_' + Poll_ID).val();
      var thisDate = TotalSoft_Poll_Set_03.split('-'); //added by fwoit 12-01-2020 to fix the issue with the poll end date being calculated as one day behind the actual selected user date in the poll settings. Splits yyyy-mm-dd into its various parts
      var TotalSoft_Poll_Set_03 = [thisDate[1],thisDate[2],thisDate[0] ].join("-"); //added by fwoit 12-01-2020 to fix the issue with the poll end date being calculated as one day behind the actual selected user date in the poll settings.  Reorganizes date as mm-dd-yyyy
      var dateend=new Date(TotalSoft_Poll_Set_03), endMonth=dateend.getMonth() + 1, endYear=dateend.getFullYear(),
        endDay=dateend.getDate();
    
      var Total_Soft_Poll_End_Bool=false;
      if(currentYear > endYear) {
        Total_Soft_Poll_End_Bool=true;
      }
      else if(currentYear==endYear) {
        if(currentMonth > endMonth) {
          Total_Soft_Poll_End_Bool=true;
        }
        else if(currentMonth==endMonth) {
          if(currentDay > endDay) {
            Total_Soft_Poll_End_Bool=true;
          }
        }
      }
    
      if(Total_Soft_Poll_End_Bool===true) {
        if(Poll_Type=='Standart') {
          Total_Soft_Poll_Ans_Div1(Poll_ID);
        }
        else if(Poll_Type=='Image/Video') {
          Total_Soft_Poll_Ans_DivIm1(Poll_ID);
        }
        else if(Poll_Type=='StandartWB') {
          Total_Soft_Poll_Ans_DivSt1(Poll_ID);
        }
        else if(Poll_Type=='ImageWB/VideoWB') {
          Total_Soft_Poll_Ans_DivIV1(Poll_ID);
        }
        else if(Poll_Type=='ImageIQ/VideoIQ') {
          Total_Soft_Poll_Ans_DivSt1(Poll_ID);
        }
      }
    }

    I hope this helps others out there.

    Plugin Author totalsoft

    (@totalsoft)

    Hello, dear fwoit.

    Thank you for talking about the problem. In The next version the whole problem will be fixed. We are glad that you liked our plugin.

    Thank You.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Poll Start and End Dates Incorrect’ is closed to new replies.