Skip to content

Commit

Permalink
fix: 修复空白时钟计算周的问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jun 14, 2019
1 parent 997a703 commit 5de133d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/pages/Blank.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const date = () => {
return (
<div className={styles.date}>
{`${new Date().getMonth() + 1}${new Date().getDate()}${['周日', '周一', '周二', '周三', '周四', '周五', '周六'][new Date().getDay()]} `}
<sup>{`第${theWeek() + 1}周`}</sup>
<sup>{`第${theWeek()}周`}</sup>
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Github.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ export default class Github extends Component {
<div>Loading...</div>
) : (
<ul>
{content.map((item) => {
{content.map((item, idx) => {
return (
<li>
<li key={idx}>
<h3>
<a href={item.html_url}>{item.full_name}</a>
</h3>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/Github.module.less
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@
margin-top: -3px;
}
}
.star {
svg {}
}
.language {
span {
border-radius: 50%;
Expand Down
45 changes: 10 additions & 35 deletions src/utils/theWeek.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,13 @@
export function theWeek(str) {
let totalDays = 0;
const now = str ? new Date(str) : new Date();
let years = now.getYear();
if (years < 1000) years += 1900;

const days = new Array(12);
days[0] = 31;
days[2] = 31;
days[3] = 30;
days[4] = 31;
days[5] = 30;
days[6] = 31;
days[7] = 31;
days[8] = 30;
days[9] = 31;
days[10] = 30;
days[11] = 31;

// 判断是否为闰年,针对2月的天数进行计算
if (Math.round(now.getYear() / 4) === now.getYear() / 4) {
days[1] = 29;
} else {
days[1] = 28;
var today = new Date();
var firstDay = new Date(today.getFullYear(), 0, 1);
var dayOfWeek = firstDay.getDay();
var spendDay = 1;
if (dayOfWeek != 0) {
spendDay = 7 - dayOfWeek + 1;
}
if (now.getMonth() === 0) {
totalDays += now.getDate();
} else {
const curMonth = now.getMonth();
for (let count = 1; count <= curMonth; count += 1) {
totalDays += days[count - 1];
}
totalDays += now.getDate();
}
// 得到第几周
const week = Math.round(totalDays / 7);
return week;
firstDay = new Date(today.getFullYear(), 0, 1 + spendDay);
var d = Math.ceil((today.valueOf() - firstDay.valueOf()) / 86400000);
var result = Math.ceil(d / 7);
return result + 1;
}

0 comments on commit 5de133d

Please sign in to comment.