Skip to content

Commit

Permalink
Merge pull request #81 from enpit-super-koyomi/apply-module
Browse files Browse the repository at this point in the history
授業時間を現在のモジュールに合わせて表示するようにgetCurrentModule()を変更しました
  • Loading branch information
Amulnesia authored Jan 16, 2025
2 parents eb5fccf + caf5aaa commit 59bf4c9
Showing 1 changed file with 38 additions and 4 deletions.
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

0 comments on commit 59bf4c9

Please sign in to comment.