Skip to content

Commit

Permalink
Update types and existing usages
Browse files Browse the repository at this point in the history
  • Loading branch information
rithviknishad committed Mar 6, 2024
1 parent 8f02edc commit e81ea55
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/contributors/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ export default async function Contributor({ params }: Params) {
Last contribution{" "}
{contributor.activityData.last_updated ? (
<RelativeTime
time={contributor.activityData.last_updated * 1e3}
time={contributor.activityData.last_updated}
/>
) : (
"unknown"
Expand Down
14 changes: 5 additions & 9 deletions components/contributors/GithubActivity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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"][]) => {
Expand All @@ -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;
}
Expand Down
7 changes: 1 addition & 6 deletions lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand 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,
Expand Down
4 changes: 2 additions & 2 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface Contributor {
}

export interface ActivityData {
last_updated?: number;
last_updated?: string;
activity: Activity[];
open_prs: OpenPr[];
pr_stale: number;
Expand Down Expand Up @@ -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[];
Expand Down

0 comments on commit e81ea55

Please sign in to comment.