Skip to content

Commit

Permalink
Make date parsing available to other extensions (for Mail Merge in pa…
Browse files Browse the repository at this point in the history
…rticular)
  • Loading branch information
jperryhouts committed Nov 28, 2020
1 parent 89e416f commit 1dbaa04
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,29 @@ browser.runtime.onMessageExternal.addListener(
});
return true;
}
else if (message["action"] === "parseDate") {
let relativeTo = new Date();
const rSec = relativeTo.getSeconds(),
pSec = SLStatic.previousLoop.getSeconds();
if (rSec > pSec) {
const tdiff = rSec-pSec;
relativeTo = new Date(relativeTo.getTime() + 60000 - tdiff*1000);
}
try {
const localeCode = browser.i18n.getUILanguage();
const date = Sugar.Date.get(
relativeTo,
message["value"],
{locale: localeCode, future: true}
);
const dateStr = SLStatic.parseableDateTimeFormat(date);
sendResponse(dateStr);
return;
} catch (ex) {
SLStatic.debug("Unable to parse date/time",ex);
}
sendResponse(null);
}
});

browser.runtime.onMessage.addListener(async (message) => {
Expand Down

0 comments on commit 1dbaa04

Please sign in to comment.