Skip to content

Commit 1eea205

Browse files
committed
fix: calc relative ms for sidebar categories correctly
1 parent fb7428f commit 1eea205

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

apps/desktop/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@lezer/common": "^1.2.1",
3939
"@lezer/highlight": "^1.2.0",
4040
"@octokit/rest": "^20.1.1",
41+
"@reduxjs/toolkit": "catalog:redux",
4142
"@replit/codemirror-lang-svelte": "^6.0.0",
4243
"@sentry/sveltekit": "^8.9.2",
4344
"@sveltejs/adapter-static": "catalog:svelte",
@@ -90,10 +91,10 @@
9091
"tinykeys": "^2.1.0",
9192
"ts-node": "^10.9.2",
9293
"vite": "catalog:",
93-
"vitest": "^2.0.5",
94-
"@reduxjs/toolkit": "catalog:redux"
94+
"vitest": "^2.0.5"
9595
},
9696
"dependencies": {
97+
"dayjs": "^1.11.13",
9798
"openai": "^4.47.3"
9899
}
99100
}

apps/desktop/src/lib/branches/branchListing.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
type SidebarEntrySubject
1010
} from '$lib/navigation/types';
1111
import { debouncedDerive } from '$lib/utils/debounce';
12+
import { msSinceDaysAgo } from '$lib/utils/time';
1213
import { persisted, type Persisted } from '@gitbutler/shared/persisted';
1314
import { Transform, Type, plainToInstance } from 'class-transformer';
1415
import Fuse from 'fuse.js';
@@ -121,7 +122,6 @@ export class BranchListingService {
121122
}
122123
}
123124

124-
const oneDay = 1000 * 60 * 60 * 24;
125125
export type GroupedSidebarEntries = Record<
126126
'applied' | 'today' | 'yesterday' | 'lastWeek' | 'older',
127127
SidebarEntrySubject[]
@@ -283,11 +283,11 @@ export class CombinedBranchListingService {
283283

284284
if (getEntryWorkspaceStatus(b)) {
285285
grouped.applied.push(b);
286-
} else if (msSinceLastCommit < oneDay) {
286+
} else if (msSinceLastCommit < msSinceDaysAgo(1)) {
287287
grouped.today.push(b);
288-
} else if (msSinceLastCommit < 2 * oneDay) {
288+
} else if (msSinceLastCommit < msSinceDaysAgo(2)) {
289289
grouped.yesterday.push(b);
290-
} else if (msSinceLastCommit < 7 * oneDay) {
290+
} else if (msSinceLastCommit < msSinceDaysAgo(7)) {
291291
grouped.lastWeek.push(b);
292292
} else {
293293
grouped.older.push(b);

apps/desktop/src/lib/utils/time.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import dayjs from 'dayjs';
2+
13
export function toHumanReadableTime(d: Date) {
24
return d.toLocaleTimeString('en-US', {
35
hour: 'numeric',
@@ -11,3 +13,7 @@ export function toHumanReadableDate(d: Date) {
1113
hour12: false
1214
});
1315
}
16+
17+
export function msSinceDaysAgo(days: number) {
18+
return Math.abs(dayjs().subtract(days, 'day').endOf('day').diff(dayjs(), 'millisecond'));
19+
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)