When manipulating dates for periods force UTC

This commit is contained in:
Matt Aitken
2024-07-09 09:25:01 +01:00
parent 16ad595338
commit 9ba5dbaf91
7 changed files with 34 additions and 29 deletions
@@ -17,9 +17,9 @@ export function UpgradePrompt() {
}
const nextMonth = new Date();
nextMonth.setMonth(nextMonth.getMonth() + 1);
nextMonth.setDate(1);
nextMonth.setHours(0, 0, 0, 0);
nextMonth.setUTCMonth(nextMonth.getMonth() + 1);
nextMonth.setUTCDate(1);
nextMonth.setUTCHours(0, 0, 0, 0);
return (
<div
@@ -31,8 +31,8 @@ export function UpgradePrompt() {
<Paragraph variant="small" className="text-error">
You have exceeded the monthly $
{(plan.v3Subscription?.plan?.limits.includedUsage ?? 500) / 100} free credits. No runs
will execute in Prod until <DateTime date={nextMonth} includeTime={false} />, or you
upgrade.
will execute in Prod until{" "}
<DateTime date={nextMonth} includeTime={false} timeZone="utc" />, or you upgrade.
</Paragraph>
</div>
<LinkButton
@@ -29,8 +29,8 @@ export class UsagePresenter extends BasePresenter {
public async call({ organizationId, startDate }: Options) {
//month period
const startOfMonth = new Date(startDate);
startOfMonth.setDate(1);
startOfMonth.setHours(0, 0, 0, 0);
startOfMonth.setUTCDate(1);
startOfMonth.setUTCHours(0, 0, 0, 0);
const endOfMonth = new Date(
startOfMonth.getFullYear(),
@@ -43,13 +43,13 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
//periods
const periodStart = new Date();
periodStart.setHours(0, 0, 0, 0);
periodStart.setDate(1);
periodStart.setUTCHours(0, 0, 0, 0);
periodStart.setUTCDate(1);
const periodEnd = new Date();
periodEnd.setMonth(periodEnd.getMonth() + 1);
periodEnd.setDate(0);
periodEnd.setHours(0, 0, 0, 0);
periodEnd.setUTCMonth(periodEnd.getMonth() + 1);
periodEnd.setUTCDate(0);
periodEnd.setUTCHours(0, 0, 0, 0);
const daysRemaining = Math.ceil(
(periodEnd.getTime() - new Date().getTime()) / (1000 * 60 * 60 * 24)
@@ -101,8 +101,13 @@ export default function ChoosePlanPage() {
{v3Subscription?.isPaying ? (
<div className="flex gap-2 px-3 lg:items-center">
<CalendarDaysIcon className="size-5 min-w-5 lg:-mt-0.5" />
Billing period: <DateTime date={periodStart} includeTime={false} /> to{" "}
<DateTime date={periodEnd} includeTime={false} /> ({daysRemaining} days remaining)
Billing period: <DateTime
date={periodStart}
includeTime={false}
timeZone="UTC"
/>{" "}
to <DateTime date={periodEnd} includeTime={false} timeZone="UTC" /> ({daysRemaining}{" "}
days remaining)
</div>
) : null}
</div>
@@ -56,7 +56,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
//past 6 months, 1st day of the month
const months = Array.from({ length: 6 }, (_, i) => {
const date = new Date();
date.setDate(1);
date.setUTCDate(1);
date.setUTCMonth(date.getUTCMonth() - i);
date.setUTCHours(0, 0, 0, 0);
return date;
@@ -65,7 +65,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
const search = new URL(request.url).searchParams;
const searchMonth = search.get("month");
const startDate = searchMonth ? new Date(searchMonth) : months[0];
startDate.setDate(1);
startDate.setUTCDate(1);
startDate.setUTCHours(0, 0, 0, 0);
const presenter = new UsagePresenter();
@@ -49,10 +49,10 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
//1st day of the month
const firstDayOfMonth = new Date();
firstDayOfMonth.setDate(1);
firstDayOfMonth.setHours(0, 0, 0, 0);
firstDayOfMonth.setUTCDate(1);
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
tomorrow.setUTCDate(tomorrow.getDate() + 1);
const [plan, usage] = await Promise.all([
getCurrentPlan(organization.id),
getUsage(organization.id, { from: firstDayOfMonth, to: tomorrow }),
@@ -33,13 +33,13 @@ export class BillingService {
const result = await this.#billingClient.currentPlan(orgId);
const firstDayOfMonth = new Date();
firstDayOfMonth.setDate(1);
firstDayOfMonth.setHours(0, 0, 0, 0);
firstDayOfMonth.setUTCDate(1);
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
const firstDayOfNextMonth = new Date();
firstDayOfNextMonth.setDate(1);
firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
firstDayOfNextMonth.setHours(0, 0, 0, 0);
firstDayOfNextMonth.setUTCDate(1);
firstDayOfNextMonth.setUTCMonth(firstDayOfNextMonth.getUTCMonth() + 1);
firstDayOfNextMonth.setUTCHours(0, 0, 0, 0);
const currentRunCount = await this.#replica.jobRun.count({
where: {
@@ -15,13 +15,13 @@ export async function getCurrentPlan(orgId: string) {
const result = await client.currentPlan(orgId);
const firstDayOfMonth = new Date();
firstDayOfMonth.setDate(1);
firstDayOfMonth.setHours(0, 0, 0, 0);
firstDayOfMonth.setUTCDate(1);
firstDayOfMonth.setUTCHours(0, 0, 0, 0);
const firstDayOfNextMonth = new Date();
firstDayOfNextMonth.setDate(1);
firstDayOfNextMonth.setMonth(firstDayOfNextMonth.getMonth() + 1);
firstDayOfNextMonth.setHours(0, 0, 0, 0);
firstDayOfNextMonth.setUTCDate(1);
firstDayOfNextMonth.setUTCMonth(firstDayOfNextMonth.getUTCMonth() + 1);
firstDayOfNextMonth.setUTCHours(0, 0, 0, 0);
const currentRunCount = await $replica.jobRun.count({
where: {