Skip to content

Commit 89d3cd4

Browse files
committed
add timezone to revenue chartData. Fix min/max date for 7day value
1 parent bf99068 commit 89d3cd4

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

src/app/(main)/websites/[websiteId]/(reports)/revenue/Revenue.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ import { useCallback, useMemo, useState } from 'react';
1818

1919
export interface RevenueProps {
2020
websiteId: string;
21-
minDate: Date;
22-
maxDate: Date;
21+
startDate: Date;
22+
endDate: Date;
2323
unit: string;
2424
}
2525

26-
export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
26+
export function Revenue({ websiteId, startDate, endDate, unit }: RevenueProps) {
2727
const [currency, setCurrency] = useState('USD');
2828
const { formatMessage, labels } = useMessages();
2929
const { locale, dateLocale } = useLocale();
3030
const { countryNames } = useCountryNames(locale);
3131
const { data, error, isLoading } = useResultQuery<any>('revenue', {
3232
websiteId,
33-
minDate,
34-
maxDate,
33+
startDate,
34+
endDate,
3535
currency,
3636
});
3737

@@ -63,15 +63,15 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
6363
const color = colord(CHART_COLORS[index % CHART_COLORS.length]);
6464
return {
6565
label: key,
66-
data: generateTimeSeries(map[key], minDate, maxDate, unit, dateLocale),
66+
data: generateTimeSeries(map[key], startDate, endDate, unit, dateLocale),
6767
lineTension: 0,
6868
backgroundColor: color.alpha(0.6).toRgbString(),
6969
borderColor: color.alpha(0.7).toRgbString(),
7070
borderWidth: 1,
7171
};
7272
}),
7373
};
74-
}, [data, minDate, maxDate, unit]);
74+
}, [data, startDate, endDate, unit]);
7575

7676
const metrics = useMemo(() => {
7777
if (!data) return [];
@@ -122,8 +122,8 @@ export function Revenue({ websiteId, minDate, maxDate, unit }: RevenueProps) {
122122
<Panel>
123123
<BarChart
124124
chartData={chartData}
125-
minDate={minDate}
126-
maxDate={maxDate}
125+
minDate={startDate}
126+
maxDate={endDate}
127127
unit={unit}
128128
stacked={true}
129129
currency={currency}

src/app/(main)/websites/[websiteId]/(reports)/revenue/RevenuePage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function RevenuePage({ websiteId }: { websiteId: string }) {
1212
return (
1313
<Column gap>
1414
<WebsiteControls websiteId={websiteId} />
15-
<Revenue websiteId={websiteId} minDate={startDate} maxDate={endDate} unit={unit} />
15+
<Revenue websiteId={websiteId} startDate={startDate} endDate={endDate} unit={unit} />
1616
</Column>
1717
);
1818
}

src/lib/date.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,12 @@ export function parseDateRange(value: string, locale = 'en-US'): DateRange {
157157

158158
const now = new Date();
159159
const dateLocale = getDateLocale(locale);
160-
const { num = 1, unit } = parseDateValue(value);
160+
const { unit } = parseDateValue(value);
161+
let { num = 1 } = parseDateValue(value);
162+
163+
if (value === '7day') {
164+
num--;
165+
}
161166

162167
switch (unit) {
163168
case 'hour':

src/queries/sql/reports/getRevenue.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export interface RevenuParameters {
77
startDate: Date;
88
endDate: Date;
99
unit: string;
10+
timezone: string;
1011
currency: string;
1112
}
1213

@@ -30,7 +31,7 @@ async function relationalQuery(
3031
parameters: RevenuParameters,
3132
filters: QueryFilters,
3233
): Promise<RevenueResult> {
33-
const { startDate, endDate, currency, unit = 'day' } = parameters;
34+
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
3435
const { getDateSQL, rawQuery, parseFilters } = prisma;
3536
const { queryParams, filterQuery, cohortQuery, joinSessionQuery } = parseFilters({
3637
...filters,
@@ -44,7 +45,7 @@ async function relationalQuery(
4445
`
4546
select
4647
revenue.event_name x,
47-
${getDateSQL('revenue.created_at', unit)} t,
48+
${getDateSQL('revenue.created_at', unit, timezone)} t,
4849
sum(revenue.revenue) y
4950
from revenue
5051
join website_event
@@ -123,7 +124,7 @@ async function clickhouseQuery(
123124
parameters: RevenuParameters,
124125
filters: QueryFilters,
125126
): Promise<RevenueResult> {
126-
const { startDate, endDate, unit = 'day', currency } = parameters;
127+
const { startDate, endDate, unit = 'day', timezone = 'utc', currency } = parameters;
127128
const { getDateSQL, rawQuery, parseFilters } = clickhouse;
128129
const { filterQuery, cohortQuery, queryParams } = parseFilters({
129130
...filters,
@@ -143,7 +144,7 @@ async function clickhouseQuery(
143144
`
144145
select
145146
website_revenue.event_name x,
146-
${getDateSQL('website_revenue.created_at', unit)} t,
147+
${getDateSQL('website_revenue.created_at', unit, timezone)} t,
147148
sum(website_revenue.revenue) y
148149
from website_revenue
149150
join website_event

0 commit comments

Comments
 (0)