Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 0f7f942

Browse files
jablkoelibarzilay
authored andcommitted
Call Day.js directly
- Day.js/Moment.js `.diff()` already truncates the result (since Moment.js 2.0.0), no need for `Math.floor()` - `.diff()` accepts a `Date`
1 parent 467952e commit 0f7f942

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

src/compute-pr-actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Comments from "./comments";
22
import * as urls from "./urls";
33
import { PrInfo, BotResult, FileInfo } from "./pr-info";
44
import { ReviewInfo } from "./pr-info";
5-
import { noNullish, flatten, unique, sameUser, daysSince, min, sha256, abbrOid } from "./util/util";
5+
import { noNullish, flatten, unique, sameUser, min, sha256, abbrOid } from "./util/util";
66
import * as dayjs from "dayjs";
77
import * as advancedFormat from "dayjs/plugin/advancedFormat";
88
dayjs.extend(advancedFormat);
@@ -373,7 +373,7 @@ function makeStaleness(now: string, author: string, otherOwners: string[]) { //
373373
return (kind: StalenessKind, since: Date,
374374
freshDays: number, attnDays: number, nearDays: number,
375375
doneColumn: ColumnName | "CLOSE") => {
376-
const days = daysSince(since, now);
376+
const days = dayjs(now).diff(since, "days");
377377
const state = days <= freshDays ? "fresh" : days <= attnDays ? "attention" : days <= nearDays ? "nearly" : "done";
378378
const kindAndState = `${kind}:${state}`;
379379
const explanation = Comments.StalenessExplanations[kindAndState];

src/util/util.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as crypto from "crypto";
2-
import * as dayjs from "dayjs";
32

43
export function noNullish<T>(arr: ReadonlyArray<T | null | undefined> | null | undefined): T[] {
54
if (arr == null) return [];
@@ -47,10 +46,6 @@ export function max<T>(arr: readonly T[], compare?: (a: T, b: T) => number) {
4746
(compare ? compare(x, res) > 0 : x > res) ? x : res);
4847
}
4948

50-
export function daysSince(date: Date, now: Date | string): number {
51-
return Math.floor(dayjs(now).diff(dayjs(date), "days"));
52-
}
53-
5449
export function sameUser(u1: string, u2: string) {
5550
return u1.toLowerCase() === u2.toLowerCase();
5651
}

0 commit comments

Comments
 (0)