-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Saved ExamSchedule to local storage, move some function to utils.ts.
- Loading branch information
Showing
2 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Exam } from "@lib/interfaces"; | ||
|
||
export const saveExamScheduleToLocalStorage = (schedule: Exam[]) => { | ||
localStorage.setItem('examSchedule', JSON.stringify(schedule)); | ||
}; | ||
|
||
export const loadExamScheduleFromLocalStorage = () => { | ||
const schedule = localStorage.getItem('examSchedule'); | ||
return schedule ? JSON.parse(schedule) : []; | ||
}; | ||
|
||
export const calculateRemainingTime = (endTime: string) => { | ||
const now = new Date(); | ||
const end = new Date(now.toDateString() + " " + endTime); | ||
const remainingMinutes = Math.floor((end.getTime() - now.getTime()) / 60000); | ||
return remainingMinutes >= 0 ? remainingMinutes : 0; | ||
}; |