Skip to content

Commit 9ba5dba

Browse files
committed
When manipulating dates for periods force UTC
1 parent 16ad595 commit 9ba5dba

File tree

7 files changed

+34
-29
lines changed

7 files changed

+34
-29
lines changed

apps/webapp/app/components/billing/v3/UpgradePrompt.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ export function UpgradePrompt() {
1717
}
1818

1919
const nextMonth = new Date();
20-
nextMonth.setMonth(nextMonth.getMonth() + 1);
21-
nextMonth.setDate(1);
22-
nextMonth.setHours(0, 0, 0, 0);
20+
nextMonth.setUTCMonth(nextMonth.getMonth() + 1);
21+
nextMonth.setUTCDate(1);
22+
nextMonth.setUTCHours(0, 0, 0, 0);
2323

2424
return (
2525
<div
@@ -31,8 +31,8 @@ export function UpgradePrompt() {
3131
<Paragraph variant="small" className="text-error">
3232
You have exceeded the monthly $
3333
{(plan.v3Subscription?.plan?.limits.includedUsage ?? 500) / 100} free credits. No runs
34-
will execute in Prod until <DateTime date={nextMonth} includeTime={false} />, or you
35-
upgrade.
34+
will execute in Prod until{" "}
35+
<DateTime date={nextMonth} includeTime={false} timeZone="utc" />, or you upgrade.
3636
</Paragraph>
3737
</div>
3838
<LinkButton

apps/webapp/app/presenters/v3/UsagePresenter.server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export class UsagePresenter extends BasePresenter {
2929
public async call({ organizationId, startDate }: Options) {
3030
//month period
3131
const startOfMonth = new Date(startDate);
32-
startOfMonth.setDate(1);
33-
startOfMonth.setHours(0, 0, 0, 0);
32+
startOfMonth.setUTCDate(1);
33+
startOfMonth.setUTCHours(0, 0, 0, 0);
3434

3535
const endOfMonth = new Date(
3636
startOfMonth.getFullYear(),

apps/webapp/app/routes/_app.orgs.$organizationSlug.v3.billing/route.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
4343

4444
//periods
4545
const periodStart = new Date();
46-
periodStart.setHours(0, 0, 0, 0);
47-
periodStart.setDate(1);
46+
periodStart.setUTCHours(0, 0, 0, 0);
47+
periodStart.setUTCDate(1);
4848

4949
const periodEnd = new Date();
50-
periodEnd.setMonth(periodEnd.getMonth() + 1);
51-
periodEnd.setDate(0);
52-
periodEnd.setHours(0, 0, 0, 0);
50+
periodEnd.setUTCMonth(periodEnd.getMonth() + 1);
51+
periodEnd.setUTCDate(0);
52+
periodEnd.setUTCHours(0, 0, 0, 0);
5353

5454
const daysRemaining = Math.ceil(
5555
(periodEnd.getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)
@@ -101,8 +101,13 @@ export default function ChoosePlanPage() {
101101
{v3Subscription?.isPaying ? (
102102
<div className="flex gap-2 px-3 lg:items-center">
103103
<CalendarDaysIcon className="size-5 min-w-5 lg:-mt-0.5" />
104-
Billing period: <DateTime date={periodStart} includeTime={false} /> to{" "}
105-
<DateTime date={periodEnd} includeTime={false} /> ({daysRemaining} days remaining)
104+
Billing period: <DateTime
105+
date={periodStart}
106+
includeTime={false}
107+
timeZone="UTC"
108+
/>{" "}
109+
to <DateTime date={periodEnd} includeTime={false} timeZone="UTC" /> ({daysRemaining}{" "}
110+
days remaining)
106111
</div>
107112
) : null}
108113
</div>

apps/webapp/app/routes/_app.orgs.$organizationSlug.v3.usage/route.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
5656
//past 6 months, 1st day of the month
5757
const months = Array.from({ length: 6 }, (_, i) => {
5858
const date = new Date();
59-
date.setDate(1);
59+
date.setUTCDate(1);
6060
date.setUTCMonth(date.getUTCMonth() - i);
6161
date.setUTCHours(0, 0, 0, 0);
6262
return date;
@@ -65,7 +65,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
6565
const search = new URL(request.url).searchParams;
6666
const searchMonth = search.get("month");
6767
const startDate = searchMonth ? new Date(searchMonth) : months[0];
68-
startDate.setDate(1);
68+
startDate.setUTCDate(1);
6969
startDate.setUTCHours(0, 0, 0, 0);
7070

7171
const presenter = new UsagePresenter();

apps/webapp/app/routes/_app.orgs.$organizationSlug/route.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
4949

5050
//1st day of the month
5151
const firstDayOfMonth = new Date();
52-
firstDayOfMonth.setDate(1);
53-
firstDayOfMonth.setHours(0, 0, 0, 0);
52+
firstDayOfMonth.setUTCDate(1);
53+
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
5454
const tomorrow = new Date();
55-
tomorrow.setDate(tomorrow.getDate() + 1);
55+
tomorrow.setUTCDate(tomorrow.getDate() + 1);
5656
const [plan, usage] = await Promise.all([
5757
getCurrentPlan(organization.id),
5858
getUsage(organization.id, { from: firstDayOfMonth, to: tomorrow }),

apps/webapp/app/services/billing.v2.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ export class BillingService {
3333
const result = await this.#billingClient.currentPlan(orgId);
3434

3535
const firstDayOfMonth = new Date();
36-
firstDayOfMonth.setDate(1);
37-
firstDayOfMonth.setHours(0, 0, 0, 0);
36+
firstDayOfMonth.setUTCDate(1);
37+
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
3838

3939
const firstDayOfNextMonth = new Date();
40-
firstDayOfNextMonth.setDate(1);
41-
firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
42-
firstDayOfNextMonth.setHours(0, 0, 0, 0);
40+
firstDayOfNextMonth.setUTCDate(1);
41+
firstDayOfNextMonth.setUTCMonth(firstDayOfNextMonth.getUTCMonth() + 1);
42+
firstDayOfNextMonth.setUTCHours(0, 0, 0, 0);
4343

4444
const currentRunCount = await this.#replica.jobRun.count({
4545
where: {

apps/webapp/app/services/platform.v3.server.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export async function getCurrentPlan(orgId: string) {
1515
const result = await client.currentPlan(orgId);
1616

1717
const firstDayOfMonth = new Date();
18-
firstDayOfMonth.setDate(1);
19-
firstDayOfMonth.setHours(0, 0, 0, 0);
18+
firstDayOfMonth.setUTCDate(1);
19+
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
2020

2121
const firstDayOfNextMonth = new Date();
22-
firstDayOfNextMonth.setDate(1);
23-
firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
24-
firstDayOfNextMonth.setHours(0, 0, 0, 0);
22+
firstDayOfNextMonth.setUTCDate(1);
23+
firstDayOfNextMonth.setUTCMonth(firstDayOfNextMonth.getUTCMonth() + 1);
24+
firstDayOfNextMonth.setUTCHours(0, 0, 0, 0);
2525

2626
const currentRunCount = await $replica.jobRun.count({
2727
where: {

0 commit comments

Comments
 (0)