toutjavascript / Fooocus-Log-Viewer

Fooocus Log Viewer : easy explorer of all your images and prompts from Fooocus UI
Apache License 2.0
42 stars 4 forks source link

Image date selection boxes not working correctly #13

Open autronix opened 7 months ago

autronix commented 7 months ago

Hello,

I noticed that the pink date selection boxes are showing different dates than the dates the pictures were generated.

image

If I select the dates from the date picker manually, the images shows however, when I click on the pink boxes, it shows empty content most of the time, and the dates are incorrect compared to the folder names generated in the output directory.

image

Looking at the directory dates vs the pink boxes, it looks like the pink boxes dates are offset by one day.

After playing a bit with the code, I found out this was due to how JS processes dates, and how it uses UTC time by default, which was not matching my timezone (EST, UTC-5), hence the date discrepancy.

I made it work by adjusting the following two functions:

const goDate = (e) => {
  console.log("goDate("+e.target.value+")");
  // Changed the direct entry into Date with a split version of the date string broken by year, month, day
  let wd_sp = e.target.value.split("-"); // split date into its parts
  const day = new Date(parseInt(wd_sp[0]), parseInt(wd_sp[1])-1, parseInt(wd_sp[2])); // loading parts directly in Date object
  console.log("day="+day);
  day.setDate(day.getDate());
  console.log("day="+day);
  setDate(day);
}

and

function toggleCalendar() {
  if (!promiseAll) {
    new jBox('Notice', {
      content: "All logs and images are not processed. Please wait...",
      theme: 'TooltipDark',
      attributes: {x: "right", y: "bottom"},
      offset: { x: 20, y: 45 }
    });
    return;
  }

  if (workingDates.length>0) {
    let list="";
    for (let i=0; i<workingDates.length; i++) {
      let wd_sp = workingDates[i].split("-"); // Same principle, splitting date into its parts
      let dt=new Date(parseInt(wd_sp[0]), parseInt(wd_sp[1])-1, parseInt(wd_sp[2])); // loading parts directly in Date object
    list+="<div class='workingDate' onclick='loadDay("+i+")'>"+dt.toLocaleDateString()+" <span class='nbImages'>"+detailDates[workingDates[i]]+" <span>&#x1f4f7;</span></span></div>"
    }
    $("div#calendarList").html(list).toggle();
  }

  if (modeSearch) {
    $("div#calendarList").hide();
  }
}
toutjavascript commented 7 months ago

Hi, Thanks for this work. I will test and add it in next release

toutjavascript commented 7 months ago

Hi New release is published with fix Thanks for your help