Skip to content

Commit ff671ed

Browse files
committed
Fixes relative date formatting threshold
1 parent 593da8c commit ff671ed

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

src/env/node/gk/localSharedGkStorageLocationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class LocalSharedGkStorageLocationProvider implements SharedGkStorageLoca
7878
break;
7979
}
8080

81-
const currentTime = new Date().getTime();
81+
const currentTime = Date.now();
8282
if (currentTime - stat.ctime > 30000) {
8383
// File exists, but the timestamp is older than 30 seconds, so we can safely remove it
8484
break;

src/features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export function getFeaturePreviewStatus(preview: FeaturePreview): FeaturePreview
160160
const usages = preview?.usages;
161161
if (!usages?.length) return 'eligible';
162162

163-
const remainingHours = (new Date(usages[usages.length - 1].expiresOn).getTime() - new Date().getTime()) / hoursInMs;
163+
const remainingHours = (new Date(usages[usages.length - 1].expiresOn).getTime() - Date.now()) / hoursInMs;
164164

165165
if (
166166
usages.length <= proFeaturePreviewUsages &&

src/system/date.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function createFromDateDelta(
7979
}
8080

8181
export function fromNow(date: Date | number, short?: boolean): string {
82-
const elapsed = (typeof date === 'number' ? date : date.getTime()) - new Date().getTime();
82+
const elapsed = (typeof date === 'number' ? date : date.getTime()) - Date.now();
8383

8484
for (const [unit, threshold, divisor, shortUnit] of relativeUnitThresholds) {
8585
const elapsedABS = Math.abs(elapsed);
@@ -101,7 +101,7 @@ export function fromNow(date: Date | number, short?: boolean): string {
101101
}
102102

103103
if (locale === 'en' || locale?.startsWith('en-')) {
104-
const value = Math.round(elapsedABS / divisor);
104+
const value = Math.floor(elapsedABS / divisor);
105105
return `${value}${shortUnit}`;
106106
}
107107

@@ -113,7 +113,7 @@ export function fromNow(date: Date | number, short?: boolean): string {
113113
});
114114
}
115115

116-
return defaultShortRelativeTimeFormat.format(Math.round(elapsed / divisor), unit);
116+
return defaultShortRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);
117117
}
118118

119119
if (defaultRelativeTimeFormat == null) {
@@ -123,7 +123,7 @@ export function fromNow(date: Date | number, short?: boolean): string {
123123
style: 'long',
124124
});
125125
}
126-
return defaultRelativeTimeFormat.format(Math.round(elapsed / divisor), unit);
126+
return defaultRelativeTimeFormat.format(Math.trunc(elapsed / divisor), unit);
127127
}
128128
}
129129

src/webviews/plus/timeline/timelineWebview.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ function generateRandomTimelineDataset(itemType: TimelineScopeType): TimelineDat
11381138
const count = 10;
11391139
for (let i = 0; i < count; i++) {
11401140
// Generate a random date between now and 3 months ago
1141-
const date = new Date(new Date().getTime() - Math.floor(Math.random() * (3 * 30 * 24 * 60 * 60 * 1000)));
1141+
const date = new Date(Date.now() - Math.floor(Math.random() * (3 * 30 * 24 * 60 * 60 * 1000)));
11421142
const author = authors[Math.floor(Math.random() * authors.length)];
11431143

11441144
// Generate random additions/deletions between 1 and 20, but ensure we have a tiny and large commit

0 commit comments

Comments
 (0)