Comments (3)
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.
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.
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)
- Spec & Getting Started HOT 2
- New "Popup" Version HOT 1
- Create Icon with Dalle HOT 2
- Use Manifest v3 HOT 1
- Persistent Modal HOT 6
- Add visit time to listing HOT 2
- add favicon next to title HOT 2
- Add Readme HOT 1
- Linger Time? HOT 2
- Add more details to modal homepage HOT 2
- Date Sorting Issue HOT 10
- Limit Duplicated Entries HOT 3
- Start and End Time Display at Top HOT 3
- List of Enhancements HOT 2
- Update Readme
- refactor large filterHistoryEntriesByDate() HOT 5
- Date off-by-one HOT 6
- Earliest and Latest Time Switched HOT 5
- Revise Time Treatment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from history-extension.