Unverified Commit 24bb3e09 authored by Noah Alderton's avatar Noah Alderton Committed by GitHub

fix: DatePicker by passing in Timezone to API (#2770)

* Fix DatePicker by passing in Timezone to API

* Add some clarity
parent 5bcbbd4c
...@@ -446,9 +446,14 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G ...@@ -446,9 +446,14 @@ func (s *APIV2Service) GetUserMemosStats(ctx context.Context, request *apiv2pb.G
return nil, status.Errorf(codes.Internal, "failed to list memos") return nil, status.Errorf(codes.Internal, "failed to list memos")
} }
location, err := time.LoadLocation(request.Timezone)
if err != nil {
return nil, status.Errorf(codes.Internal, "invalid timezone location")
}
creationStats := make(map[string]int32) creationStats := make(map[string]int32)
for _, memo := range memos { for _, memo := range memos {
creationStats[time.Unix(memo.CreatedTs, 0).Format("2006-01-02")]++ creationStats[time.Unix(memo.CreatedTs, 0).In(location).Format("2006-01-02")]++
} }
response := &apiv2pb.GetUserMemosStatsResponse{ response := &apiv2pb.GetUserMemosStatsResponse{
......
...@@ -236,6 +236,11 @@ message GetUserMemosStatsRequest { ...@@ -236,6 +236,11 @@ message GetUserMemosStatsRequest {
// name is the name of the user to get stats for. // name is the name of the user to get stats for.
// Format: users/{username} // Format: users/{username}
string name = 1; string name = 1;
// timezone location
// Format: uses tz identifier
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
string timezone = 2;
} }
message GetUserMemosStatsResponse { message GetUserMemosStatsResponse {
......
...@@ -1779,6 +1779,7 @@ ...@@ -1779,6 +1779,7 @@
| Field | Type | Label | Description | | Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- | | ----- | ---- | ----- | ----------- |
| name | [string](#string) | | name is the name of the user to get stats for. Format: users/{username} | | name | [string](#string) | | name is the name of the user to get stats for. Format: users/{username} |
| timezone | [string](#string) | | timezone location Format: uses tz identifier https://en.wikipedia.org/wiki/List_of_tz_database_time_zones |
......
This diff is collapsed.
...@@ -28,6 +28,7 @@ const PersonalStatistics = (props: Props) => { ...@@ -28,6 +28,7 @@ const PersonalStatistics = (props: Props) => {
setIsRequesting(true); setIsRequesting(true);
const { memoCreationStats } = await memoServiceClient.getUserMemosStats({ const { memoCreationStats } = await memoServiceClient.getUserMemosStats({
name: user.name, name: user.name,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}); });
setIsRequesting(false); setIsRequesting(false);
setMemoAmount(Object.values(memoCreationStats).reduce((acc, cur) => acc + cur, 0)); setMemoAmount(Object.values(memoCreationStats).reduce((acc, cur) => acc + cur, 0));
......
...@@ -38,6 +38,7 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => { ...@@ -38,6 +38,7 @@ const DatePicker: React.FC<DatePickerProps> = (props: DatePickerProps) => {
(async () => { (async () => {
const { memoCreationStats } = await memoServiceClient.getUserMemosStats({ const { memoCreationStats } = await memoServiceClient.getUserMemosStats({
name: user.name, name: user.name,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
}); });
const m = new Map(); const m = new Map();
Object.entries(memoCreationStats).forEach(([k]) => { Object.entries(memoCreationStats).forEach(([k]) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment