Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: xxchan/logseq-deadline-countdown
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.0.5
Choose a base ref
...
head repository: xxchan/logseq-deadline-countdown
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 4 commits
  • 2 files changed
  • 1 contributor

Commits on Aug 28, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    Girgias Gina Peter Banyard
    Copy the full SHA
    7195bef View commit details
  2. bump to 0.0.6

    xxchan committed Aug 28, 2022
    Copy the full SHA
    4b8f006 View commit details
  3. fix datediff

    xxchan committed Aug 28, 2022
    Copy the full SHA
    085e7ad View commit details

Commits on Aug 29, 2022

  1. 0d -> today

    xxchan committed Aug 29, 2022
    Copy the full SHA
    9a63f96 View commit details
Showing with 17 additions and 11 deletions.
  1. +16 −10 index.js
  2. +1 −1 package.json
26 changes: 16 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
@@ -64,16 +64,18 @@ function prettyDiff(then, now, minInterval) {
if (then < now && !cfgShowPast) return;
if (then > now && !cfgShowFuture) return;

// When "Minimum Interval" option is set to "days",
// diff should be calculated by date difference,
// ignoring hours.
let diff;
if (minInterval == INTERVALS_LOOKUP['d']) {
now.setHours(12, 0, 0)
then.setHours(12, 0, 0)
// When "Minimum Interval" option is set to "days",
// diff should be calculated by date difference,
// ignoring hours.
const diffDays = Math.round(Math.abs(then.setHours(12) - now.setHours(12)) / 8.64e7);
diff = `${diffDays}d`;
} else {
diff = prettyTimeDifference(Math.floor(Math.abs(then - now) / 1000), minInterval);
}

const diff = Math.floor(Math.abs(then - now) / 1000);
return prettyTimeDifference(diff, minInterval);
return diff;
}

function renderCountdown(el) {
@@ -85,9 +87,13 @@ function renderCountdown(el) {
const timePart = timeTextParts[2] && !isNaN(timeTextParts[2][0]) ? timeTextParts[2] : '';
const then = new Date(timeTextParts[0].concat(' ', timePart));

const prettyDiff = prettyDiff(then, now, cfgMinInterval);
if (prettyDiff === '') return;
time.textContent = `${timeText} (${then >= now ? 'in' : 'past'} ${prettyDiff})`;
const diff = prettyDiff(then, now, cfgMinInterval);
if (diff === '') return;
if (diff === '0d') {
time.textContent = `${timeText} (today)`;
} else {
time.textContent = `${timeText} (${then >= now ? 'in' : 'past'} ${diff})`;
}
}

function tests() {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "logseq-deadline-countdown",
"version": "0.0.3",
"version": "0.0.7",
"author": "xxchan",
"main": "index.html",
"description": "Counts how many days left until the deadline.",