Skip to content

Commit 5de133d

Browse files
committed
fix: 修复空白时钟计算周的问题。
1 parent 997a703 commit 5de133d

4 files changed

Lines changed: 13 additions & 41 deletions

File tree

src/pages/Blank.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const date = () => {
2828
return (
2929
<div className={styles.date}>
3030
{`${new Date().getMonth() + 1}${new Date().getDate()}${['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date().getDay()]} `}
31-
<sup>{`第${theWeek() + 1}周`}</sup>
31+
<sup>{`第${theWeek()}周`}</sup>
3232
</div>
3333
);
3434
};

src/pages/Github.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ export default class Github extends Component {
143143
<div>Loading...</div>
144144
) : (
145145
<ul>
146-
{content.map((item) => {
146+
{content.map((item, idx) => {
147147
return (
148-
<li>
148+
<li key={idx}>
149149
<h3>
150150
<a href={item.html_url}>{item.full_name}</a>
151151
</h3>

src/pages/Github.module.less

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@
8585
margin-top: -3px;
8686
}
8787
}
88-
.star {
89-
svg {}
90-
}
9188
.language {
9289
span {
9390
border-radius: 50%;

src/utils/theWeek.js

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,13 @@
11
export function theWeek(str) {
2-
let totalDays = 0;
3-
const now = str ? new Date(str) : new Date();
4-
let years = now.getYear();
5-
if (years < 1000) years += 1900;
6-
7-
const days = new Array(12);
8-
days[0] = 31;
9-
days[2] = 31;
10-
days[3] = 30;
11-
days[4] = 31;
12-
days[5] = 30;
13-
days[6] = 31;
14-
days[7] = 31;
15-
days[8] = 30;
16-
days[9] = 31;
17-
days[10] = 30;
18-
days[11] = 31;
19-
20-
// 判断是否为闰年,针对2月的天数进行计算
21-
if (Math.round(now.getYear() / 4) === now.getYear() / 4) {
22-
days[1] = 29;
23-
} else {
24-
days[1] = 28;
2+
var today = new Date();
3+
var firstDay = new Date(today.getFullYear(), 0, 1);
4+
var dayOfWeek = firstDay.getDay();
5+
var spendDay = 1;
6+
if (dayOfWeek != 0) {
7+
spendDay = 7 - dayOfWeek + 1;
258
}
26-
if (now.getMonth() === 0) {
27-
totalDays += now.getDate();
28-
} else {
29-
const curMonth = now.getMonth();
30-
for (let count = 1; count <= curMonth; count += 1) {
31-
totalDays += days[count - 1];
32-
}
33-
totalDays += now.getDate();
34-
}
35-
// 得到第几周
36-
const week = Math.round(totalDays / 7);
37-
return week;
9+
firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
10+
var d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
11+
var result = Math.ceil(d / 7);
12+
return result + 1;
3813
}

0 commit comments

Comments
 (0)