From 27874fad37bc4b6c01db70078886312820af578e Mon Sep 17 00:00:00 2001 From: Starcea Date: Fri, 28 Jun 2024 15:29:33 +0900 Subject: [PATCH] fix: fetch data when date changes --- src/data.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/data.ts b/src/data.ts index f8c768d..65f9fa1 100644 --- a/src/data.ts +++ b/src/data.ts @@ -15,7 +15,7 @@ interface Data { export default class DataManager { private _data: Data | null = null - private _lastFetch = 0 + private _lastFetchDate = 0 constructor(private readonly rest: AxiosInstance) {} @@ -43,7 +43,7 @@ export default class DataManager { const subject = RegExes.SubjectCode.exec(data) if (!subject) throw new Error('Failed to fetch subject code') - this._lastFetch = Date.now() + this._lastFetchDate = new Date().getDate() this._data = { mainRoute: main[0], searchRoute: search[0], @@ -56,7 +56,7 @@ export default class DataManager { } async getData() { - if (this._data && Date.now() - this._lastFetch < 1000 * 60 * 60) + if (this._data && this._lastFetchDate === new Date().getDate()) return this._data return this.fetchData()