Skip to content

Commit

Permalink
fix: the original getLastMonth() cannot get the correct month when …
Browse files Browse the repository at this point in the history
…data >= 20
  • Loading branch information
tyn1998 committed Aug 6, 2023
1 parent cfa3705 commit 4869cb4
Showing 1 changed file with 4 additions and 18 deletions.
22 changes: 4 additions & 18 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,10 @@ const { Content } = Layout;
const META_URL =
'https://xlab-open-source.oss-cn-beijing.aliyuncs.com/open_leaderboard/meta.json';

const getLastMonth = (lastUpdateTime) => {
let year = lastUpdateTime.getFullYear();
let monthIndex = lastUpdateTime.getMonth();
let date = lastUpdateTime.getDate();

if (date < 20) {
monthIndex--;
}

if (monthIndex < 0) {
monthIndex += 12;
year--;
}
return [year, monthIndex];
};

const App = () => {
const NODE_ENV = process.env.NODE_ENV;
if (NODE_ENV !== 'development') {
console.log = function () {};
console.log = function () { };
}
let [lastUpdateTime, setLastUpdateTime] = useState(null);
const { t } = useTranslation();
Expand All @@ -50,7 +34,9 @@ const App = () => {
let year = null,
monthIndex = null;
if (lastUpdateTime) {
[year, monthIndex] = getLastMonth(lastUpdateTime);
const lastDataAvailableMonth = new Date(lastUpdateTime.setDate(0));
year = lastDataAvailableMonth.getFullYear();
monthIndex = lastDataAvailableMonth.getMonth();
}

return (
Expand Down

0 comments on commit 4869cb4

Please sign in to comment.