Skip to content

Commit

Permalink
Fixes #2 where matcher on lastEditedTime contains a narrow no-space b…
Browse files Browse the repository at this point in the history
…reak instead of a space. Also, fixes issue with timestamp being wrong for cards that are edited the previous day.
  • Loading branch information
jamesmortensen committed Jun 20, 2023
1 parent 5e326e2 commit ea8f4db
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion keep.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async function scrapeCardsFromBrowser(browser) {
}
const timeElem = await browser.$('body > div.VIpgJd-TUo6Hb.XKSfm-L9AdLc.eo9XGd > div > div.IZ65Hb-TBnied > div.IZ65Hb-s2gQvd > div.IZ65Hb-jfdpUb > div.IZ65Hb-jfdpUb-fmcmS');
const createdTime = await timeElem.getAttribute('data-tooltip-text');
const lastEditedTime = await timeElem.getText();
const lastEditedTime = (await timeElem.getText()).replace(/\u202f/, ' ');
const color = await browser.execute(() => {
return window.getComputedStyle(document.querySelector("body > div.VIpgJd-TUo6Hb.XKSfm-L9AdLc.eo9XGd > div > div.IZ65Hb-TBnied"), null).backgroundColor;
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "archiver-for-google-keep",
"version": "0.0.3",
"version": "0.0.4",
"description": "Scrapes notes and checklists from Google Keep™ and writes them out as JSON and markdown archive/backup files. This tool is not affiliated or endorsed by Google™. Google Keep™ is a trademark of Google.",
"main": "keep.js",
"bin": {
Expand Down
7 changes: 7 additions & 0 deletions src/card-date-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function convertToMonthDateCommaYear(dateStr, dateTimeNow = new Date()) {
else if (isMonthDateAndYear(response))
return response[0];

else if(isYesterday(response))
return getMonthDateAndYear(new Date(new Date().setDate(dateTimeNow.getDate() - 1)));

else if (isATime(response))
return getMonthDateAndYear(dateTimeNow);
}
Expand All @@ -25,6 +28,10 @@ function isMonthDateAndYear(response) {
return response[3] && response[4] && response[5];
}

function isYesterday(response) {
return response.input.split(', ')[0].toLowerCase() === 'yesterday';
}

function isATime(response) {
return response[6];
}
Expand Down
10 changes: 10 additions & 0 deletions test/card-date-parser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ describe('Time Parser Tests', () => {
expect(lastEditedDateStr).to.equal('Jul 6, 2022');
});

it('should handle if the last edited time is yesterday', () => {
const lastEditedDateStr = convertToMonthDateCommaYear('yesterday, 3:03 PM', new Date('June 20, 2023'));
expect(lastEditedDateStr).to.equal('Jun 19, 2023');
});

it('should handle if the last edited time is the day before yesterday', () => {
const lastEditedDateStr = convertToMonthDateCommaYear('Jun 19', new Date('June 21, 2023'));
expect(lastEditedDateStr).to.equal('Jun 19, 2023');
});

it('should throw Error if minute is invalid', () => {
expect(
() => convertToMonthDateCommaYear('10:2 AM', new Date('Jul 6, 2022'))
Expand Down

0 comments on commit ea8f4db

Please sign in to comment.