Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use date-fns for relative time functions #4583

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 61 additions & 11 deletions dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"cron-validator": "^1.3.1",
"d3-array": "^2.11.0",
"d3-time-format": "^3.0.0",
"date-fns": "^3.6.0",
"dayjs": "^1.11.5",
"deep-diff": "^1.0.2",
"dotenv": "^8.2.0",
Expand Down
12 changes: 3 additions & 9 deletions dashboard/src/main/home/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { fakeGuardedRoute } from "shared/auth/RouteGuard";
import { Context } from "shared/Context";
import DeploymentTargetProvider from "shared/DeploymentTargetContext";
import { pushFiltered, pushQueryParams, type PorterUrl } from "shared/routing";
import { relativeDate, timeFrom } from "shared/string_utils";
import { intlFormatDistance, isPast } from "date-fns";
import midnight from "shared/themes/midnight";
import standard from "shared/themes/standard";
import {
Expand Down Expand Up @@ -377,13 +377,7 @@ const Home: React.FC<Props> = (props) => {
if (timestamp === "") {
return true;
}

const diff = timeFrom(timestamp);
if (diff.when === "future") {
return false;
}

return true;
return isPast(new Date(timestamp)) ? true : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return isPast(new Date(timestamp))

};

const showCardBanner = !hasPaymentEnabled;
Expand Down Expand Up @@ -424,7 +418,7 @@ const Home: React.FC<Props> = (props) => {
connect a valid payment method
</Link>
. Your free trial is ending {" "}
{relativeDate(plan.trial_info.ending_before, true)}.
{intlFormatDistance(Date.parse(plan.trial_info.ending_before), new Date())}.
</GlobalBanner>
)}
{!trialExpired && showBillingModal && (
Expand Down
8 changes: 3 additions & 5 deletions dashboard/src/main/home/project-settings/BillingPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
usePorterCredits,
useSetDefaultPaymentMethod,
} from "lib/hooks/useStripe";
import { relativeDate } from "shared/string_utils";
import { intlFormat, intlFormatDistance } from "date-fns";

import { Context } from "shared/Context";
import cardIcon from "assets/credit-card.svg";
Expand Down Expand Up @@ -82,8 +82,6 @@ function BillingPage(): JSX.Element {
return (credits / 100).toFixed(2);
};

const readableDate = (s: string): string => new Date(s).toLocaleDateString();

const onCreate = async (): Promise<void> => {
await refetchPaymentMethods({ throwOnError: false, cancelRefetch: false });
setShouldCreate(false);
Expand Down Expand Up @@ -233,10 +231,10 @@ function BillingPage(): JSX.Element {
plan.trial_info.ending_before !== "" ? (
<Text>
Free trial ends{" "}
{relativeDate(plan.trial_info.ending_before, true)}
{intlFormatDistance(Date.parse(plan.trial_info.ending_before), new Date())}
</Text>
) : (
<Text>Started on {readableDate(plan.starting_on)}</Text>
<Text>Started on {intlFormat(Date.parse(plan.starting_on))}</Text>
)}
</Container>
</Container>
Expand Down
Loading