diff --git a/src/lib/ContestTile/ContestTile.stories.tsx b/src/lib/ContestTile/ContestTile.stories.tsx
index 14eccada..b964b93c 100644
--- a/src/lib/ContestTile/ContestTile.stories.tsx
+++ b/src/lib/ContestTile/ContestTile.stories.tsx
@@ -66,14 +66,14 @@ export const ContestTileUpcoming: Story = (args) => {
};
@@ -85,14 +85,14 @@ export const ContestTileUpcomingRollingTriage: Story = (args) => {
};
@@ -104,14 +104,14 @@ export const ContestTileLive: Story = (args) => {
};
@@ -123,14 +123,14 @@ export const ContestTileLiveCohort1: Story = (args) => {
};
@@ -141,14 +141,14 @@ export const ContestTileLivePreCohort2: Story = (args) => {
};
@@ -159,14 +159,14 @@ export const ContestTileLiveAwaitingCohort3: Story = (args) => {
};
@@ -178,14 +178,14 @@ export const ContestTileEnded: Story = (args) => {
};
@@ -196,10 +196,10 @@ export const BountyTile: Story = (args) => {
return
+ startDate={new Date(args.bountyData.startDate)} />
+ startDate={new Date(args.bountyData.startDate)} />
}
@@ -216,8 +216,8 @@ ContestTileUpcoming.args = {
...defaultArgs,
contestData: {
...defaultArgs.contestData,
- startDate: "2030-07-12T18:00:00Z",
- endDate: "2030-07-21T18:00:00.000Z",
+ startDate: new Date("2030-07-12T18:00:00Z"),
+ endDate: new Date("2030-07-21T18:00:00.000Z"),
status: AuditStatus.PreAudit,
}
};
@@ -227,19 +227,19 @@ ContestTileUpcomingRollingTriage.args = {
...defaultArgs.contestData,
cohorts: [{
name: "cohort-1",
- pauseTime: addDays(Date.now(), 6).toISOString(),
+ pauseTime: addDays(Date.now(), 6),
resumeTime: null
}, {
name: "cohort-2",
- pauseTime: addDays(Date.now(), 13).toISOString(),
- resumeTime: addDays(Date.now(), 9).toISOString(),
+ pauseTime: addDays(Date.now(), 13),
+ resumeTime: addDays(Date.now(), 9),
}, {
name: "cohort-3",
pauseTime: null,
- resumeTime: addDays(Date.now(), 16).toISOString(),
+ resumeTime: addDays(Date.now(), 16),
}],
- startDate: addDays(Date.now(), 3).toISOString(),
- endDate: addDays(Date.now(), 20).toISOString(),
+ startDate: addDays(Date.now(), 3),
+ endDate: addDays(Date.now(), 20),
status: AuditStatus.PreAudit,
}
};
@@ -249,8 +249,8 @@ ContestTileLive.args = {
...defaultArgs,
contestData: {
...defaultArgs.contestData,
- startDate: "2023-07-12T18:00:00Z",
- endDate: "2030-07-21T18:00:00.000Z",
+ startDate: new Date("2023-07-12T18:00:00Z"),
+ endDate: new Date("2030-07-21T18:00:00.000Z"),
status: AuditStatus.Active,
}
};
@@ -260,19 +260,19 @@ ContestTileLiveCohort1.args = {
...defaultArgs.contestData,
cohorts: [{
name: "cohort-1",
- pauseTime: addDays(Date.now(), 4).toISOString(),
+ pauseTime: addDays(Date.now(), 4),
resumeTime: null
}, {
name: "cohort-2",
- pauseTime: addDays(Date.now(), 11).toISOString(),
- resumeTime: addDays(Date.now(), 7).toISOString(),
+ pauseTime: addDays(Date.now(), 11),
+ resumeTime: addDays(Date.now(), 7),
}, {
name: "cohort-3",
pauseTime: null,
- resumeTime: addDays(Date.now(), 14).toISOString(),
+ resumeTime: addDays(Date.now(), 14),
}],
- startDate: subDays(Date.now(), 1).toISOString(),
- endDate: addDays(Date.now(), 18).toISOString(),
+ startDate: subDays(Date.now(), 1),
+ endDate: addDays(Date.now(), 18),
status: AuditStatus.Active,
}
};
@@ -282,19 +282,19 @@ ContestTileLivePreCohort2.args = {
...defaultArgs.contestData,
cohorts: [{
name: "cohort-1",
- pauseTime: subDays(Date.now(), 1).toISOString(),
+ pauseTime: subDays(Date.now(), 1),
resumeTime: null
}, {
name: "cohort-2",
- pauseTime: addDays(Date.now(), 6).toISOString(),
- resumeTime: addDays(Date.now(), 2).toISOString(),
+ pauseTime: addDays(Date.now(), 6),
+ resumeTime: addDays(Date.now(), 2),
}, {
name: "cohort-3",
pauseTime: null,
- resumeTime: addDays(Date.now(), 9).toISOString(),
+ resumeTime: addDays(Date.now(), 9),
}],
- startDate: subDays(Date.now(), 6).toISOString(),
- endDate: addDays(Date.now(), 16).toISOString(),
+ startDate: subDays(Date.now(), 6),
+ endDate: addDays(Date.now(), 16),
status: AuditStatus.Paused,
}
};
@@ -304,19 +304,19 @@ ContestTileLiveAwaitingCohort3.args = {
...defaultArgs.contestData,
cohorts: [{
name: "cohort-1",
- pauseTime: subDays(Date.now(), 11).toISOString(),
+ pauseTime: subDays(Date.now(), 11),
resumeTime: null
}, {
name: "cohort-2",
- pauseTime: subDays(Date.now(), 4).toISOString(),
- resumeTime: subDays(Date.now(), 8).toISOString(),
+ pauseTime: subDays(Date.now(), 4),
+ resumeTime: subDays(Date.now(), 8),
}, {
name: "cohort-3",
pauseTime: null,
- resumeTime: subDays(Date.now(), 1).toISOString(),
+ resumeTime: subDays(Date.now(), 1),
}],
- startDate: subDays(Date.now(), 16).toISOString(),
- endDate: addDays(Date.now(), 6).toISOString(),
+ startDate: subDays(Date.now(), 16),
+ endDate: addDays(Date.now(), 6),
status: AuditStatus.Paused,
}
};
@@ -325,8 +325,8 @@ ContestTileEnded.args = {
...defaultArgs,
contestData: {
...defaultArgs.contestData,
- startDate: "2023-07-12T18:00:00Z",
- endDate: "2023-07-21T18:00:00Z",
+ startDate: new Date("2023-07-12T18:00:00Z"),
+ endDate: new Date("2023-07-21T18:00:00Z"),
status: AuditStatus.Review,
}
};
@@ -335,7 +335,7 @@ BountyTile.args = {
htmlId: "",
bountyData: {
amount: "$80,000 USDC",
- startDate: "2023-07-12T18:00:00Z",
+ startDate: new Date("2023-07-12T18:00:00Z"),
repoUrl: "https://github.com/code-423n4/2023-07-axelar",
bountyUrl: "https://code4rena.com/audits/2023-07-axelar-network#top",
ecosystem: "Polkadot" as ContestEcosystem,
diff --git a/src/lib/ContestTile/ContestTile.tsx b/src/lib/ContestTile/ContestTile.tsx
index a5ed2a59..764ef843 100644
--- a/src/lib/ContestTile/ContestTile.tsx
+++ b/src/lib/ContestTile/ContestTile.tsx
@@ -132,14 +132,14 @@ export const ContestCountdown = ({
updateContestStatus: CountdownProps["updateContestStatus"]
}) => {
let text = "Ends in ";
- let start = schedule.start.toISOString();
- let end = schedule.end.toISOString();
+ let start = schedule.start;
+ let end = schedule.end;
if (schedule.contestStatus === Status.UPCOMING) {
text = "Starts in ";
} else if (schedule.contestStatus === Status.LIVE) {
if (schedule.status === AuditStatus.Paused && schedule.resume && +schedule.resume >= Date.now()) {
text = "Next submission phase starts in ";
- start = schedule.resume.toISOString();
+ start = schedule.resume;
} else if (schedule.status === AuditStatus.Paused && schedule.resume && +schedule.resume <= Date.now()) {
// The resume time has elapsed, give a generic time for now
return (
@@ -149,7 +149,7 @@ export const ContestCountdown = ({
);
} else if (schedule.status === AuditStatus.Active && schedule.pause && +schedule.pause >= Date.now()) {
text = "Current submission phase ends in ";
- end = schedule.pause.toISOString();
+ end = schedule.pause;
}
}
return Countdown({
diff --git a/src/lib/ContestTile/ContestTile.types.ts b/src/lib/ContestTile/ContestTile.types.ts
index fe130e4d..823815b7 100644
--- a/src/lib/ContestTile/ContestTile.types.ts
+++ b/src/lib/ContestTile/ContestTile.types.ts
@@ -13,8 +13,8 @@ export type ContestEcosystem = "Algorand" | "Aptos" | "Blast" | "Cosmos" | "EVM"
export type CodingLanguage = "Cairo" | "GO" | "HUFF" | "Ink" | "Move" | "Noir" | "Other" | "Rain" | "Rust" | "Rust evm" | "Solidity" | "Vyper" | "Yul";
export interface ContestCohort {
- resumeTime: string | null;
- pauseTime: string | null;
+ resumeTime: Date | null;
+ pauseTime: Date | null;
name: string;
}
@@ -42,8 +42,8 @@ export interface ContestTileProps {
export interface BountyTileData {
/** Max reward amount for the current bounty. */
amount: string;
- /** Date string for the current bounty's start date. */
- startDate: string;
+ /** Date for the current bounty's start date. */
+ startDate: Date;
/** Absolute url or relative path to the page of the current bounty. */
bountyUrl: string;
/** Absolute url to the bounty's source code. */
@@ -81,13 +81,13 @@ export interface ContestTileData {
amount: string;
/** Callback function to be triggered on contest time/status changes. */
updateContestStatus?: () => void;
- /** Date string for the current contest's start date. */
- startDate: string;
- /** Date string for the current contest's end date. */
- endDate: string;
+ /** Date for the current contest's start date. */
+ startDate: Date;
+ /** Date for the current contest's end date. */
+ endDate: Date;
/** Boolean indicating certification status of logged in user. Required for viewing certain contests. */
isUserCertified: boolean;
- status: AuditStatus;
+ status: AuditStatus | null;
}
export interface BaseContestSchedule {
@@ -104,7 +104,7 @@ export interface BaseContestSchedule {
}
export interface ContestSchedule extends BaseContestSchedule {
- status: AuditStatus;
+ status: AuditStatus | null;
end: Date;
/** The time the current cohort will pause. */
pause: Date | null;
@@ -113,8 +113,8 @@ export interface ContestSchedule extends BaseContestSchedule {
}
export interface CountdownProps {
- start: string;
- end: string;
+ start: Date;
+ end: Date;
text?: string | ReactNode;
updateContestStatus?: () => void;
}
diff --git a/src/lib/ContestTile/DefaultTemplate.tsx b/src/lib/ContestTile/DefaultTemplate.tsx
index 2d44293f..1e97f462 100644
--- a/src/lib/ContestTile/DefaultTemplate.tsx
+++ b/src/lib/ContestTile/DefaultTemplate.tsx
@@ -403,7 +403,7 @@ function IsBounty({
bountyTimelineObject?: BaseContestSchedule | undefined;
}) {
const { bountyUrl, amount, startDate, ecosystem, languages } = bountyData;
- const endDate = "2999-01-01T00:00:00Z"
+ const endDate = new Date("2999-01-01T00:00:00Z");
let ecosystemLogoName: string = "";
if (ecosystem) {
switch (ecosystem) {
diff --git a/src/utils/time.test.ts b/src/utils/time.test.ts
index 59b217fd..3c20e06f 100644
--- a/src/utils/time.test.ts
+++ b/src/utils/time.test.ts
@@ -11,83 +11,83 @@ describe("utils/time", () => {
let cohorts:ContestCohort[] = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() + 1000).toISOString(),
+ pauseTime: new Date(Date.now() + 1000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() + 2000).toISOString(),
- pauseTime: new Date(Date.now() + 3000).toISOString(),
+ resumeTime: new Date(Date.now() + 2000),
+ pauseTime: new Date(Date.now() + 3000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 4000).toISOString(),
+ resumeTime: new Date(Date.now() + 4000),
pauseTime: null,
}];
let dates = getCurrentCohortDates(cohorts);
expect(dates).toStrictEqual({
resumeDate: null,
- pauseDate: new Date(cohorts[0].pauseTime!),
+ pauseDate: cohorts[0].pauseTime,
});
// Upcoming 2nd cohort
cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 2000).toISOString(),
+ pauseTime: new Date(Date.now() - 2000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() + 1000).toISOString(),
- pauseTime: new Date(Date.now() + 2000).toISOString(),
+ resumeTime: new Date(Date.now() + 1000),
+ pauseTime: new Date(Date.now() + 2000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 3000).toISOString(),
+ resumeTime: new Date(Date.now() + 3000),
pauseTime: null,
}];
dates = getCurrentCohortDates(cohorts);
expect(dates).toStrictEqual({
- resumeDate: new Date(cohorts[1].resumeTime!),
- pauseDate: new Date(cohorts[1].pauseTime!),
+ resumeDate: cohorts[1].resumeTime,
+ pauseDate: cohorts[1].pauseTime,
});
// Active 2nd cohort
cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 2000).toISOString(),
+ pauseTime: new Date(Date.now() - 2000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 1000).toISOString(),
- pauseTime: new Date(Date.now() + 2000).toISOString(),
+ resumeTime: new Date(Date.now() - 1000),
+ pauseTime: new Date(Date.now() + 2000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 3000).toISOString(),
+ resumeTime: new Date(Date.now() + 3000),
pauseTime: null,
}];
dates = getCurrentCohortDates(cohorts);
expect(dates).toStrictEqual({
- resumeDate: new Date(cohorts[1].resumeTime!),
- pauseDate: new Date(cohorts[1].pauseTime!)
+ resumeDate: cohorts[1].resumeTime,
+ pauseDate: cohorts[1].pauseTime
});
// Upcoming 3rd
cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 4000).toISOString(),
+ pauseTime: new Date(Date.now() - 4000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 3000).toISOString(),
- pauseTime: new Date(Date.now() - 1000).toISOString(),
+ resumeTime: new Date(Date.now() - 3000),
+ pauseTime: new Date(Date.now() - 1000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 1000).toISOString(),
+ resumeTime: new Date(Date.now() + 1000),
pauseTime: null,
}];
dates = getCurrentCohortDates(cohorts);
expect(dates).toStrictEqual({
- resumeDate: new Date(cohorts[2].resumeTime!),
+ resumeDate: cohorts[2].resumeTime,
pauseDate: null,
});
@@ -95,20 +95,20 @@ describe("utils/time", () => {
cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 4000).toISOString(),
+ pauseTime: new Date(Date.now() - 4000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 3000).toISOString(),
- pauseTime: new Date(Date.now() - 2000).toISOString(),
+ resumeTime: new Date(Date.now() - 3000),
+ pauseTime: new Date(Date.now() - 2000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() - 1000).toISOString(),
+ resumeTime: new Date(Date.now() - 1000),
pauseTime: null,
}];
dates = getCurrentCohortDates(cohorts);
expect(dates).toStrictEqual({
- resumeDate: new Date(cohorts[2].resumeTime!),
+ resumeDate: cohorts[2].resumeTime,
pauseDate: null,
});
});
@@ -118,22 +118,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() + 2000).toISOString(),
+ pauseTime: new Date(Date.now() + 2000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() + 3000).toISOString(),
- pauseTime: new Date(Date.now() + 4000).toISOString(),
+ resumeTime: new Date(Date.now() + 3000),
+ pauseTime: new Date(Date.now() + 4000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 5000).toISOString(),
+ resumeTime: new Date(Date.now() + 5000),
pauseTime: null,
}];
const start = new Date(Date.now() + 1000);
const end = new Date(Date.now() + 6000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.PreAudit
});
@@ -147,7 +147,7 @@ describe("utils/time", () => {
formattedDuration: "less than a minute",
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
- pause: new Date(cohorts[0].pauseTime!),
+ pause: cohorts[0].pauseTime,
resume: null,
start: start,
status: AuditStatus.PreAudit,
@@ -160,8 +160,8 @@ describe("utils/time", () => {
const end = new Date(Date.now() + 6000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.PreAudit
});
@@ -186,22 +186,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() + 1000).toISOString(),
+ pauseTime: new Date(Date.now() + 1000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() + 2000).toISOString(),
- pauseTime: new Date(Date.now() + 3000).toISOString(),
+ resumeTime: new Date(Date.now() + 2000),
+ pauseTime: new Date(Date.now() + 3000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 4000).toISOString(),
+ resumeTime: new Date(Date.now() + 4000),
pauseTime: null,
}];
const start = new Date(Date.now());
const end = new Date(Date.now() + 5000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.Active
});
@@ -215,7 +215,7 @@ describe("utils/time", () => {
formattedDuration: "less than a minute",
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
- pause: new Date(cohorts[0].pauseTime!),
+ pause: cohorts[0].pauseTime,
resume: null,
start: start,
status: AuditStatus.Active,
@@ -226,22 +226,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 1000).toISOString(),
+ pauseTime: new Date(Date.now() - 1000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() + 1000).toISOString(),
- pauseTime: new Date(Date.now() + 2000).toISOString(),
+ resumeTime: new Date(Date.now() + 1000),
+ pauseTime: new Date(Date.now() + 2000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 3000).toISOString(),
+ resumeTime: new Date(Date.now() + 3000),
pauseTime: null,
}];
const start = new Date(Date.now() - 2000);
const end = new Date(Date.now() + 4000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.Paused
});
@@ -255,8 +255,8 @@ describe("utils/time", () => {
formattedDuration: "less than a minute",
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
- pause: new Date(cohorts[1].pauseTime!),
- resume: new Date(cohorts[1].resumeTime!),
+ pause: cohorts[1].pauseTime,
+ resume: cohorts[1].resumeTime,
start: start,
status: AuditStatus.Paused,
timeZone: DateTime.local().toFormat("ZZZZ")
@@ -267,22 +267,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 2000).toISOString(),
+ pauseTime: new Date(Date.now() - 2000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 1000).toISOString(),
- pauseTime: new Date(Date.now() + 1000).toISOString(),
+ resumeTime: new Date(Date.now() - 1000),
+ pauseTime: new Date(Date.now() + 1000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() + 2000).toISOString(),
+ resumeTime: new Date(Date.now() + 2000),
pauseTime: null,
}];
const start = new Date(Date.now() - 3000);
const end = new Date(Date.now() + 3000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.Active
});
@@ -296,8 +296,8 @@ describe("utils/time", () => {
formattedDuration: "less than a minute",
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
- pause: new Date(cohorts[1].pauseTime!),
- resume: new Date(cohorts[1].resumeTime!),
+ pause: cohorts[1].pauseTime,
+ resume: cohorts[1].resumeTime,
start: start,
status: AuditStatus.Active,
timeZone: DateTime.local().toFormat("ZZZZ")
@@ -308,22 +308,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 4000).toISOString(),
+ pauseTime: new Date(Date.now() - 4000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 3000).toISOString(),
- pauseTime: new Date(Date.now() - 2000).toISOString(),
+ resumeTime: new Date(Date.now() - 3000),
+ pauseTime: new Date(Date.now() - 2000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() - 1000).toISOString(),
+ resumeTime: new Date(Date.now() - 1000),
pauseTime: null,
}];
const start = new Date(Date.now() - 5000);
const end = new Date(Date.now() + 1000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.Active
});
@@ -338,7 +338,7 @@ describe("utils/time", () => {
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
pause: null,
- resume: new Date(cohorts[2].resumeTime!),
+ resume: cohorts[2].resumeTime,
start: start,
status: AuditStatus.Active,
timeZone: DateTime.local().toFormat("ZZZZ")
@@ -349,22 +349,22 @@ describe("utils/time", () => {
const cohorts = [{
name: "cohort-1",
resumeTime: null,
- pauseTime: new Date(Date.now() - 5000).toISOString(),
+ pauseTime: new Date(Date.now() - 5000),
}, {
name: "cohort-2",
- resumeTime: new Date(Date.now() - 4000).toISOString(),
- pauseTime: new Date(Date.now() - 3000).toISOString(),
+ resumeTime: new Date(Date.now() - 4000),
+ pauseTime: new Date(Date.now() - 3000),
}, {
name: "cohort-3",
- resumeTime: new Date(Date.now() - 2000).toISOString(),
+ resumeTime: new Date(Date.now() - 2000),
pauseTime: null,
}];
const start = new Date(Date.now() - 6000);
const end = new Date(Date.now() - 1000);
const dates = getContestSchedule({
- startDate: start.toISOString(),
- endDate: end.toISOString(),
+ startDate: start,
+ endDate: end,
cohorts,
status: AuditStatus.Review
});
@@ -379,7 +379,7 @@ describe("utils/time", () => {
formattedEnd: format(end, "d MMM h:mm a"),
formattedStart: format(start, "d MMM h:mm a"),
pause: null,
- resume: new Date(cohorts[2].resumeTime!),
+ resume: cohorts[2].resumeTime,
start: start,
status: AuditStatus.Review,
timeZone: DateTime.local().toFormat("ZZZZ")
diff --git a/src/utils/time.ts b/src/utils/time.ts
index 28f14201..3c9dda03 100644
--- a/src/utils/time.ts
+++ b/src/utils/time.ts
@@ -1,5 +1,16 @@
-import { addHours, format, formatDistance, isAfter, isBefore, isEqual } from "date-fns";
-import { BaseContestSchedule, ContestCohort, ContestSchedule } from "../lib/ContestTile/ContestTile.types";
+import {
+ addHours,
+ format,
+ formatDistance,
+ isAfter,
+ isBefore,
+ isEqual,
+} from "date-fns";
+import {
+ BaseContestSchedule,
+ ContestCohort,
+ ContestSchedule,
+} from "../lib/ContestTile/ContestTile.types";
import { Status } from "../lib/ContestStatus/ContestStatus.types";
import { ContestTileData } from "../lib/ContestTile/ContestTile.types";
import { DateTime } from "luxon";
@@ -22,7 +33,10 @@ function getContestStatuses(
contestStatus: Status.ENDED,
};
}
- if (isBefore(currentTime, botRaceEnd) && (isAfter(currentTime, start) || isEqual(currentTime, start))) {
+ if (
+ isBefore(currentTime, botRaceEnd) &&
+ (isAfter(currentTime, start) || isEqual(currentTime, start))
+ ) {
return {
botRaceStatus: Status.LIVE,
contestStatus: Status.LIVE,
@@ -44,17 +58,28 @@ function getContestStatuses(
const getCurrentCohortDates = (cohorts: ContestCohort[]) => {
const now = Date.now();
- const currentCohort = cohorts.sort((a, b) => {
- if (a.resumeTime === null) return -1;
- return new Date(a.resumeTime).getTime() - (b.resumeTime ? new Date(b.resumeTime)?.getTime() : 0);
- }).find(cohort => {
- return cohort.pauseTime === null || new Date(cohort.pauseTime).getTime() > now;
- });
+ const currentCohort = cohorts
+ .sort((a, b) => {
+ if (a.resumeTime === null) return -1;
+ return (
+ a.resumeTime.getTime() -
+ (b.resumeTime ? b.resumeTime?.getTime() : 0)
+ );
+ })
+ .find((cohort) => {
+ return (
+ cohort.pauseTime === null || cohort.pauseTime.getTime() > now
+ );
+ });
return {
- pauseDate: currentCohort?.pauseTime ? new Date(currentCohort.pauseTime) : null,
- resumeDate: currentCohort?.resumeTime ? new Date(currentCohort.resumeTime) : null,
- }
+ pauseDate: currentCohort?.pauseTime
+ ? currentCohort.pauseTime
+ : null,
+ resumeDate: currentCohort?.resumeTime
+ ? currentCohort.resumeTime
+ : null,
+ };
};
const getContestSchedule = (
@@ -65,21 +90,24 @@ const getContestSchedule = (
return {
...schedule,
- pause: currentCohort.pauseDate && new Date(currentCohort.pauseDate),
- resume: currentCohort.resumeDate && new Date(currentCohort.resumeDate),
+ pause: currentCohort.pauseDate && currentCohort.pauseDate,
+ resume: currentCohort.resumeDate && currentCohort.resumeDate,
status: contest.status,
};
-}
+};
const getDates = (
- start: string,
- end: string
+ start: Date | string,
+ end: Date | string
): BaseContestSchedule => {
- const startDate = new Date(start);
- const endDate = new Date(end);
+ let startDate = start;
+ let endDate = end;
+ if (typeof startDate === "string") startDate = new Date(start);
+ if (typeof endDate === "string") endDate = new Date(end);
+
const timeZone = DateTime.local().toFormat("ZZZZ");
- const botRaceEnd = addHours(new Date(startDate), 1);
+ const botRaceEnd = addHours(startDate, 1);
const { contestStatus, botRaceStatus } = getContestStatuses(
startDate,
endDate,