Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/electron-info/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"dependencies": {
"chalk": "5.6.2",
"commander": "15.0.0",
"date-fns": "4.4.0",
"logdown": "3.3.1",
"semver": "7.8.1",
"table": "6.9.0"
Expand Down
28 changes: 28 additions & 0 deletions packages/electron-info/src/FileService.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {describe, expect, test} from 'vitest';

import {isWithinLastDay} from './FileService.js';

describe('isWithinLastDay', () => {
test('returns true when date is just after the same time yesterday', () => {
const now = new Date('2026-01-15T12:00:00.000Z');
const justAfter = new Date('2026-01-14T12:00:00.001Z');
expect(isWithinLastDay(justAfter, now)).toBe(true);
});

test('returns false when date is exactly the same time yesterday', () => {
const now = new Date('2026-01-15T12:00:00.000Z');
const exactlyYesterday = new Date('2026-01-14T12:00:00.000Z');
expect(isWithinLastDay(exactlyYesterday, now)).toBe(false);
});

test('returns false when date is before yesterday', () => {
const now = new Date('2026-01-15T12:00:00.000Z');
const twoDaysAgo = new Date('2026-01-13T12:00:00.000Z');
expect(isWithinLastDay(twoDaysAgo, now)).toBe(false);
});

test('returns true when date equals now', () => {
const now = new Date('2026-01-15T12:00:00.000Z');
expect(isWithinLastDay(now, now)).toBe(true);
});
});
10 changes: 7 additions & 3 deletions packages/electron-info/src/FileService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import {isAfter as isAfterDate, sub as subtractDate} from 'date-fns';
import logdown from 'logdown';
import {promises as fs, constants as fsConstants} from 'node:fs';
import os from 'node:os';
Expand Down Expand Up @@ -89,8 +88,7 @@ export class FileService {
const {mtime: fileModifiedDate} = await fs.stat(fileName);
this.logger.log(`File "${fileName}" is from "${fileModifiedDate.toString()}"`);

const yesterday = subtractDate(new Date(), {days: 1});
return isAfterDate(fileModifiedDate, yesterday);
return isWithinLastDay(fileModifiedDate);
}

private async isPathReadable(filePath: string): Promise<boolean> {
Expand All @@ -115,3 +113,9 @@ export class FileService {
return releases;
}
}

export function isWithinLastDay(date: Date, now = new Date()): boolean {
const yesterday = new Date(now);
yesterday.setUTCDate(yesterday.getUTCDate() - 1);
return date > yesterday;
}
8 changes: 0 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4656,13 +4656,6 @@ __metadata:
languageName: node
linkType: hard

"date-fns@npm:4.4.0":
version: 4.4.0
resolution: "date-fns@npm:4.4.0"
checksum: 10c0/988f0a13db183f5dfc85c36bbb6847a9c135a9225888bbea4005876ec15539a8613c21a07370a4e7ea543918d5a1cafb423c528b42cdbbde5fdfddb178126b21
languageName: node
linkType: hard

"debug@npm:4, debug@npm:^4.3.4":
version: 4.3.4
resolution: "debug@npm:4.3.4"
Expand Down Expand Up @@ -4924,7 +4917,6 @@ __metadata:
"@types/semver": "npm:7.7.1"
chalk: "npm:5.6.2"
commander: "npm:15.0.0"
date-fns: "npm:4.4.0"
http-status-codes: "npm:2.3.0"
logdown: "npm:3.3.1"
nock: "npm:14.0.15"
Expand Down