Giter Club home page Giter Club logo

Comments (3)

TheMapSmith avatar TheMapSmith commented on August 18, 2024

I apologize for the inconvenience. It seems like there might be an issue with the time zones. Let's adjust the filterHistoryEntriesByDate function to account for the time zone offset:

function filterHistoryEntriesByDate(selectedDate) {
  const selectedDateObj = new Date(selectedDate);
  const timezoneOffset = selectedDateObj.getTimezoneOffset() * 60000;
  const startTime = selectedDateObj.getTime() - timezoneOffset;
  const endTime = startTime + 86400000;

  chrome.history.search({
    text: '',
    startTime: startTime,
    endTime: endTime,
    maxResults: 1000
  }, (results) => {
    historyList.innerHTML = '';

    const processedResults = [];

    const processEntry = (entry) => {
      return new Promise((resolve) => {
        chrome.history.getVisits({ url: entry.url }, (visits) => {
          visits.forEach((visit) => {
            if (visit.visitTime >= startTime && visit.visitTime <= endTime) {
              const newEntry = Object.assign({}, entry);
              newEntry.visitTime = visit.visitTime;
              processedResults.push(newEntry);
            }
          });
          resolve();
        });
      });
    };

    const promises = results.map(processEntry);

    Promise.all(promises).then(() => {
      // Sort the history items by visitTime (in descending order)
      processedResults.sort((a, b) => b.visitTime - a.visitTime);

      for (const entry of processedResults) {
        const entryElement = document.createElement('div');
        entryElement.classList.add('entry');

        // Format the visited time for display purposes
        const visitedTime = new Date(entry.visitTime);
        const timeString = visitedTime.toLocaleTimeString('en-US', { hour12: true, hour: '2-digit', minute: '2-digit' });

        // Create a span element to display the visited time
        const visitedTimeElement = document.createElement('span');
        visitedTimeElement.textContent = `${timeString} - `;
        entryElement.appendChild(visitedTimeElement);

        // Create an img element for the favicon
        const faviconElement = document.createElement('img');
        faviconElement.src = `https://s2.googleusercontent.com/s2/favicons?domain=${entry.url}`;
        faviconElement.alt = '';
        faviconElement.classList.add('favicon');
        entryElement.appendChild(faviconElement);

        const entryTitle = document.createElement('a');
        entryTitle.href = entry.url;
        entryTitle.target = '_blank';
        entryTitle.textContent = entry.title || entry.url;
        entryElement.appendChild(entryTitle);

        historyList.appendChild(entryElement);
      }
    });
  });
}

In this updated function, we calculate the timezoneOffset and adjust the startTime and endTime accordingly. This should ensure the correct time range is used to filter and sort the history entries.

Please test this function and let me know if the issue is resolved.

from history-extension.

TheMapSmith avatar TheMapSmith commented on August 18, 2024

now the top of the list is 3:59 PM, and the very bottom of the list is 4:00 PM. I think the time zone is not correct

from history-extension.

TheMapSmith avatar TheMapSmith commented on August 18, 2024

I apologize for the confusion. The issue might be related to the way we're handling the time zone offset. Let's try a different approach to create the startTime and endTime by using the setHours method, which should account for the time zone properly:

function filterHistoryEntriesByDate(selectedDate) {
  const selectedDateObj = new Date(selectedDate);
  const startTime = selectedDateObj.setHours(0, 0, 0, 0);
  const endTime = selectedDateObj.setHours(23, 59, 59, 999);

  chrome.history.search({
    text: '',
    startTime: startTime,
    endTime: endTime,
    maxResults: 1000
  }, (results) => {
    historyList.innerHTML = '';

    const processedResults = [];

    const processEntry = (entry) => {
      return new Promise((resolve) => {
        chrome.history.getVisits({ url: entry.url }, (visits) => {
          visits.forEach((visit) => {
            if (visit.visitTime >= startTime && visit.visitTime <= endTime) {
              const newEntry = Object.assign({}, entry);
              newEntry.visitTime = visit.visitTime;
              processedResults.push(newEntry);
            }
          });
          resolve();
        });
      });
    };

    const promises = results.map(processEntry);

    Promise.all(promises).then(() => {
      // Sort the history items by visitTime (in descending order)
      processedResults.sort((a, b) => b.visitTime - a.visitTime);

      for (const entry of processedResults) {
        const entryElement = document.createElement('div');
        entryElement.classList.add('entry');

        // Format the visited time for display purposes
        const visitedTime = new Date(entry.visitTime);
        const timeString = visitedTime.toLocaleTimeString('en-US', { hour12: true, hour: '2-digit', minute: '2-digit' });

        // Create a span element to display the visited time
        const visitedTimeElement = document.createElement('span');
        visitedTimeElement.textContent = `${timeString} - `;
        entryElement.appendChild(visitedTimeElement);

        // Create an img element for the favicon
        const faviconElement = document.createElement('img');
        faviconElement.src = `https://s2.googleusercontent.com/s2/favicons?domain=${entry.url}`;
        faviconElement.alt = '';
        faviconElement.classList.add('favicon');
        entryElement.appendChild(faviconElement);

        const entryTitle = document.createElement('a');
        entryTitle.href = entry.url;
        entryTitle.target = '_blank';
        entryTitle.textContent = entry.title || entry.url;
        entryElement.appendChild(entryTitle);

        historyList.appendChild(entryElement);
      }
    });
  });
}

In this updated function, we use setHours to set the hours, minutes, seconds, and milliseconds of the selectedDateObj to create the startTime and endTime. This should properly account for the time zone and ensure the correct time range is used to filter and sort the history entries.

Please test this function and let me know if the issue is resolved.



from history-extension.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.