Skip to content

Commit

Permalink
display past-due tasks due today
Browse files Browse the repository at this point in the history
  • Loading branch information
narthur committed Nov 8, 2022
1 parent 1d7473e commit 274c1fc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/components/pages/Tasks.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -611,4 +611,16 @@ describe('tasks page', () => {
);
});
});

it('displays task that is due in past but on same date', async () => {
vi.setSystemTime(new Date('1/1/2020, 2:00 PM'));

loadTasksApiData({
tasks: [makeTask({ task: 'the_task', due: '1/1/2020, 1:00 PM' })],
});

renderTasksPage();

await screen.findByText('the_task');
});
});
6 changes: 6 additions & 0 deletions src/lib/Browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ export class Browser {
getScrollPercentage(el: Element): number {
return el.scrollTop / (el.scrollHeight - el.clientHeight);
}

getLastMidnight(date: Date): Date {
const d = new Date(date);
d.setHours(0, 0, 0, 0);
return d;
}
}

const browser = new Browser();
Expand Down
3 changes: 2 additions & 1 deletion src/lib/createListItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ export default function createListItems(
newTaskIndex: number | undefined;
} {
const now = browser.getNowDate();
const lastMidnight = browser.getLastMidnight(now);

let lastTitle: string;
let newTaskIndex: number | undefined = undefined;

const entries = sortedTasks.reduce((acc: Entries, t: TaskType): Entries => {
if (new Date(t.due) < now) return acc;
if (new Date(t.due) < lastMidnight) return acc;

const title = makeTitle(t);
const shouldAddHeading = title !== lastTitle || !acc.length;
Expand Down

1 comment on commit 274c1fc

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.