Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
50f7f131
Unverified
Commit
50f7f131
authored
Jan 29, 2024
by
Wen Sun
Committed by
GitHub
Jan 29, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: month grouping error in timeline page (#2861)
parent
a16bde23
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
6 deletions
+20
-6
ActivityCalendar.tsx
web/src/components/ActivityCalendar.tsx
+6
-4
datetime.ts
web/src/helpers/datetime.ts
+12
-0
Timeline.tsx
web/src/pages/Timeline.tsx
+2
-2
No files found.
web/src/components/ActivityCalendar.tsx
View file @
50f7f131
import
{
Tooltip
}
from
"@mui/joy"
;
import
classNames
from
"classnames"
;
import
{
getNormalizedDateString
}
from
"@/helpers/datetime"
;
import
{
getNormalizedDateString
,
getDateWithOffset
}
from
"@/helpers/datetime"
;
interface
Props
{
// Format: 2021-1
...
...
@@ -26,8 +26,8 @@ const getCellAdditionalStyles = (count: number, maxCount: number) => {
const
ActivityCalendar
=
(
props
:
Props
)
=>
{
const
{
month
:
monthStr
,
data
,
onClick
}
=
props
;
const
year
=
new
Date
(
monthStr
).
getFullYear
();
const
month
=
new
Date
(
monthStr
).
getMonth
()
+
1
;
const
year
=
new
Date
(
monthStr
).
get
UTC
FullYear
();
const
month
=
new
Date
(
monthStr
).
get
UTC
Month
()
+
1
;
const
dayInMonth
=
new
Date
(
year
,
month
,
0
).
getDate
();
const
firstDay
=
new
Date
(
year
,
month
-
1
,
1
).
getDay
();
const
lastDay
=
new
Date
(
year
,
month
-
1
,
dayInMonth
).
getDay
();
...
...
@@ -47,7 +47,9 @@ const ActivityCalendar = (props: Props) => {
return
(
<
div
className=
{
classNames
(
"w-36 h-auto p-0.5 shrink-0 grid grid-cols-7 grid-flow-row gap-1"
)
}
>
{
days
.
map
((
day
,
index
)
=>
{
const
date
=
getNormalizedDateString
(
`${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
);
const
date
=
getNormalizedDateString
(
getDateWithOffset
(
`${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`
),
);
const
count
=
data
[
date
]
||
0
;
const
isToday
=
new
Date
().
toDateString
()
===
new
Date
(
date
).
toDateString
();
const
tooltipText
=
count
?
`${count} memos in ${date}`
:
date
;
...
...
web/src/helpers/datetime.ts
View file @
50f7f131
...
...
@@ -169,3 +169,15 @@ export function isFutureDate(t?: Date | number | string): boolean {
const
timestamp
=
getTimeStampByDate
(
t
?
t
:
Date
.
now
());
return
timestamp
>
Date
.
now
();
}
/**
* Calculates a new Date object by adjusting the provided date, timestamp, or date string
* based on the current timezone offset.
*
* @param t - The input date, timestamp, or date string (optional). If not provided,
* the current date and time will be used.
* @returns A new Date object adjusted by the current timezone offset.
*/
export
function
getDateWithOffset
(
t
?:
Date
|
number
|
string
):
Date
{
return
new
Date
(
getTimeStampByDate
(
t
)
+
new
Date
().
getTimezoneOffset
()
*
60
*
1000
);
}
web/src/pages/Timeline.tsx
View file @
50f7f131
...
...
@@ -148,9 +148,9 @@ const Timeline = () => {
<
div
className=
{
classNames
(
"flex shrink-0"
,
md
?
"flex-col w-40 pr-4 pl-2 pb-8"
:
"flex-row w-full pl-1 mt-2 mb-2"
)
}
>
<
div
className=
{
classNames
(
"w-full flex flex-col"
,
md
&&
"mt-4 mb-2"
)
}
>
<
span
className=
"font-medium text-3xl leading-none mb-1"
>
{
new
Date
(
group
.
month
).
toLocaleString
(
i18n
.
language
,
{
month
:
"short"
})
}
{
new
Date
(
group
.
month
).
toLocaleString
(
i18n
.
language
,
{
month
:
"short"
,
timeZone
:
"UTC"
})
}
</
span
>
<
span
className=
"opacity-60"
>
{
new
Date
(
group
.
month
).
getFullYear
()
}
</
span
>
<
span
className=
"opacity-60"
>
{
new
Date
(
group
.
month
).
get
UTC
FullYear
()
}
</
span
>
<
span
className=
"text-xs opacity-40"
>
Total:
{
sum
(
Object
.
values
(
group
.
data
))
}
</
span
>
</
div
>
<
ActivityCalendar
month=
{
group
.
month
}
data=
{
group
.
data
}
onClick=
{
(
date
)
=>
setSelectedDay
(
date
)
}
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment