diff --git a/app/contributors/[slug]/page.tsx b/app/contributors/[slug]/page.tsx index ad4b45ba..cc48b641 100644 --- a/app/contributors/[slug]/page.tsx +++ b/app/contributors/[slug]/page.tsx @@ -352,7 +352,7 @@ export default async function Contributor({ params }: Params) { Last contribution{" "} {contributor.activityData.last_updated ? ( ) : ( "unknown" diff --git a/components/contributors/GithubActivity.tsx b/components/contributors/GithubActivity.tsx index 41d90018..ef121617 100644 --- a/components/contributors/GithubActivity.tsx +++ b/components/contributors/GithubActivity.tsx @@ -22,7 +22,7 @@ let commentTypes = (activityEvent: string[]) => { }; let renderText = (activity: Activity) => { - const timestamp = getActivityTime(activity.time).toString(); + const timestamp = new Date(activity.time).toString(); switch (activity["type"]) { case "eod_update": return ( @@ -265,22 +265,18 @@ let showContribution = (activity: Activity) => { ); }; -const getActivityTime = (time: Activity["time"]) => { - return typeof time === "number" ? new Date(time * 1e3) : new Date(time); -}; - const activitiesBetween = (range: { from: Date; to: Date }) => { const from = range.from.getTime(); const to = range.to.getTime(); return (activity: Activity) => { - const time = getActivityTime(activity.time).getTime(); + const time = new Date(activity.time).getTime(); return from < time && time < to; }; }; const compareByActivityTime = (a: Activity, b: Activity) => { - return getActivityTime(b.time).getTime() - getActivityTime(a.time).getTime(); + return new Date(b.time).getTime() - new Date(a.time).getTime(); }; const activitiesOfType = (types: Activity["type"][]) => { @@ -292,11 +288,11 @@ const activitiesOfType = (types: Activity["type"][]) => { const getRangeFilterPresets = (activities: Activity[]) => { if (!activities.length) return []; - const latest = getActivityTime(activities[0].time); + const latest = new Date(activities[0].time); let oldest = new Date(latest); activities.forEach((activity) => { - const time = getActivityTime(activity.time); + const time = new Date(activity.time); if (time < oldest) { oldest = time; } diff --git a/lib/api.ts b/lib/api.ts index 37288e3f..4a33d9d3 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -183,10 +183,6 @@ export async function getContributorBySlug(file: string, detail = false) { } as Contributor & { summarize: typeof summarize }; } -const getActivityTime = (time: Activity["time"]) => { - return typeof time === "number" ? new Date(time * 1e3) : new Date(time); -}; - export async function getContributors(detail = false) { const slugs = await getContributorsSlugs(); return Promise.all( @@ -197,8 +193,7 @@ export async function getContributors(detail = false) { function getCalendarData(activity: Activity[]) { const calendarData = activity.reduce( (acc, activity) => { - // Github activity.time ignores milliseconds (*1000) - const date = getActivityTime(activity.time).toISOString().split("T")[0]; + const date = new Date(activity.time).toISOString().split("T")[0]; if (!acc[date]) { acc[date] = { count: 0, diff --git a/lib/types.ts b/lib/types.ts index e573ed1f..2681530d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -25,7 +25,7 @@ export interface Contributor { } export interface ActivityData { - last_updated?: number; + last_updated?: string; activity: Activity[]; open_prs: OpenPr[]; pr_stale: number; @@ -71,7 +71,7 @@ export const ACTIVITY_TYPES = [ export interface Activity { type: (typeof ACTIVITY_TYPES)[number]; title: string; - time: number | string; // TODO: github events are in seconds since epoch, slack events are in timestamp strings. Unify it to one. + time: string; link: string; text: string; collaborated_with?: string[];