diff --git a/components/dashboard/src/components/UsageBasedBillingConfig.tsx b/components/dashboard/src/components/UsageBasedBillingConfig.tsx index 717c981a56a674..52c6843ad53e1a 100644 --- a/components/dashboard/src/components/UsageBasedBillingConfig.tsx +++ b/components/dashboard/src/components/UsageBasedBillingConfig.tsx @@ -19,6 +19,7 @@ import { getGitpodService } from "../service/service"; import DropDown from "../components/DropDown"; import Modal from "../components/Modal"; import Alert from "./Alert"; +import dayjs from "dayjs"; const BASE_USAGE_LIMIT_FOR_STRIPE_USERS = 1000; @@ -43,9 +44,9 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) { const [billingError, setBillingError] = useState(); const localStorageKey = `pendingStripeSubscriptionFor${attributionId}`; - const billingPeriodFrom = new Date(new Date().toISOString().slice(0, 7) + "-01"); // First day of this month: YYYY-MM-01T00:00:00.000Z - const billingPeriodTo = new Date(billingPeriodFrom.getUTCFullYear(), billingPeriodFrom.getMonth() + 1); // First day of next month - billingPeriodTo.setMilliseconds(billingPeriodTo.getMilliseconds() - 1); // Last millisecond of this month + const now = dayjs().utc(true); + const billingPeriodFrom = now.startOf("month"); + const billingPeriodTo = now.endOf("month"); useEffect(() => { if (!attributionId) { @@ -176,7 +177,7 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) { const response = await getGitpodService().server.listUsage({ attributionId, order: Ordering.ORDERING_DESCENDING, - from: billingPeriodFrom.getTime(), + from: billingPeriodFrom.toDate().getTime(), to: Date.now(), }); setCurrentUsage(response.creditsUsed); @@ -253,12 +254,8 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
Current Period
- - {billingPeriodFrom.toLocaleString("default", { month: "long" })}{" "} - {billingPeriodFrom.getFullYear()} - {" "} - ({billingPeriodFrom.toLocaleString("default", { month: "short", day: "numeric" })} -{" "} - {billingPeriodTo.toLocaleString("default", { month: "short", day: "numeric" })}) + {`${billingPeriodFrom.format("MMMM YYYY")}`}{" "} + {`(${billingPeriodFrom.format("MMM D")}` + ` - ${billingPeriodTo.format("MMM D")})`}
@@ -279,7 +276,8 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
- {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard workspace usage.{" "} + {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard workspace + usage.{" "}
Pay-as-you-go after 1,000 credits - {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard workspace usage. + + {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard + workspace usage. +
@@ -373,7 +374,10 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) { Pay-as-you-go after 1,000 credits - {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard workspace usage. + + {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of + Standard workspace usage. +
@@ -386,7 +390,8 @@ export default function UsageBasedBillingConfig({ attributionId }: Props) {
- {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of Standard workspace usage.{" "} + {currency === "EUR" ? "€" : "$"}0.36 for 10 credits or 1 hour of + Standard workspace usage.{" "}