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

授業時間を現在のモジュールに合わせて表示するようにgetCurrentModule()を変更しました #81

Merged
merged 2 commits into from
Jan 16, 2025
Merged
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
42 changes: 38 additions & 4 deletions src/lib/course.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { setTimes } from "./utils"
import { Period } from "./scheduling"
import { Course, Day } from "@/third-party/twinte-parser-type"
import { Course, Day, Module } from "@/third-party/twinte-parser-type"
import { FETCH_EVENTS_DAYS } from "./const"

export type CoursePeriod = {
Expand Down Expand Up @@ -47,9 +47,43 @@ const isNextSchedule = (prevSchedule: CourseSchedule, schedule: CourseSchedule)
/**
* 現在(or与えられた日時が?)どのモジュール期間であるかを返します。
* @todo
* @returns 基本の6モジュールの時はその文字列を返す("春A")。そうでない場合は"Unknown"を返す。
*/
const getCurrentModule = () => {
return "秋B"
const getCurrentModule = (): Module => {
//春Aから秋Cまでの開始と終了日時を定義
const startSpringA = new Date(2024, 4, 15)
const startSpringB = new Date(2024, 5, 24)
const startSpringC = new Date(2024, 7, 5)
const endSpringC = new Date(20204, 8, 9)
const startFallA = new Date(2024, 10, 1)
const startFallB = new Date(2024, 11, 11)
const endFallB = new Date(2024, 12, 25)
const startFallC = new Date(2025, 1, 6)
const endFallC = new Date(2025, 2, 27)
//現在の日時を取得
const currentDate = new Date()
if (currentDate < startSpringA) {
return Module.Unknown
}
if (currentDate >= startSpringA && currentDate < startSpringB) {
return Module.SpringA
}
if (currentDate >= startSpringB && currentDate < startSpringC) {
return Module.SpringB
}
if (currentDate >= startSpringC && currentDate < endSpringC) {
return Module.SpringC
}
if (currentDate >= startFallA && currentDate < startFallB) {
return Module.FallA
}
if (currentDate >= startFallB && currentDate < endFallB) {
return Module.FallB
}
if (currentDate >= startFallC && currentDate < endFallC) {
return Module.FallC
}
return Module.Unknown
}

/**
Expand All @@ -60,7 +94,7 @@ const getCurrentModule = () => {
*/
export const courseToPeriods = (baseDate: Date, course: Course): Period[] => {
const currentModule = getCurrentModule()
const currentSchedules = course.schedules.filter(s => s.module == currentModule)
const currentSchedules = course.schedules.filter(s => s.module == currentModule.toString())
const periods = currentSchedules
.flatMap(s => {
const nextClassDate = nextDateOfDay(baseDate, s.day)
Expand Down