Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调整时间进度百分比为当月进度百分比 #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
10 changes: 7 additions & 3 deletions Scripts/ChinaTelecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Widget extends DmYY {
this.format(this.date.getMinutes()),
];

monthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

// percent 的计算方式,剩余/总量 * 100 = 百分比| 百分比 * 3.6 ,为显示进度。
phoneBill = {
percent: 0,
Expand Down Expand Up @@ -99,9 +101,11 @@ class Widget extends DmYY {

init = async () => {
try {
const nowHours = this.date.getHours();
const updateHours = nowHours > 12 ? 24 : 12;
this.updateTime.percent = Math.floor((nowHours / updateHours) * 100);
const nowHours = (this.date.getDate() - 1) * 24 + this.date.getHours();
//闰年简单判断,本世纪内直接用4取模没问题的
const totalHours = this.monthDays[this.date.getMonth()] * 24
+ (this.date.getFullYear() % 4 == 0 && this.date.getMonth() == 1 ? 24 : 0);
this.updateTime.percent = Math.floor(nowHours / totalHours * 100);
await this.getData();
} catch (e) {
console.log(e);
Expand Down