Skip to content

日付からsemester特定#36

Merged
hikaru-0602 merged 2 commits intomainfrom
fix/semester-filter
Apr 7, 2026
Merged

日付からsemester特定#36
hikaru-0602 merged 2 commits intomainfrom
fix/semester-filter

Conversation

@hikaru-0602
Copy link
Copy Markdown
Contributor

やったこと

日付からsemester指定

  • Close #
    • [ ]

確認したこと

curlで確認

  • [ ]

メモ

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

日付配列(dates)から年度(Year)と学期(Semesters)を推定し、時間割取得クエリのフィルタに反映することで、個人カレンダー生成時の取得範囲を適切に絞り込むPRです。

Changes:

  • dates から Year / Semesters を算出して TimetableItemListFilter に設定
  • 年度・学期推定のための determineSemestersFromDates ヘルパーを追加

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +320 to +324
for _, date := range dates {
yearMap[date.Year()] = struct{}{}

month := date.Month()
if month >= 4 && month <= 9 {
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yearMap[date.Year()] だと暦年ベースになり、1〜3月の date では日本の大学の「年度(4月始まり)」とズレます(例: 2026-01 は本来 2025 年度の H2 になりそう)。ここでは date.Month() < time.April の場合に year を 1 減らした「年度」を使って yearMap に入れるなど、年度計算を入れた方が subjects.year フィルタと整合します。

Copilot uses AI. Check for mistakes.
Comment on lines +337 to +343
var year *int
if len(yearMap) == 1 {
for y := range yearMap {
year = &y
break
}
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(yearMap) != 1 のときに year=nil になるため、timetableItemRepo.List 側で subjects.year が一切絞られず、該当ユーザーの履修登録とは無関係な年度の時間割までまとめて取得する挙動になります。dates が年跨ぎ(例: 月表示の週が12月末〜1月頭)になるケースがあるなら、年度ごとにクエリを分けて結果をマージする/フィルタ側を Years []int のように拡張する等で、常に年度で絞れるようにした方がスケールしやすいです。

Copilot uses AI. Check for mistakes.
@hikaru-0602 hikaru-0602 changed the title 日付からsemester 日付からsemester特定 Apr 7, 2026
@hikaru-0602
Copy link
Copy Markdown
Contributor Author

前期はこれで大丈夫だと思うので後期の挙動は一旦考慮しない

Copy link
Copy Markdown
Member

@kantacky kantacky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devで動作確認済み

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings April 7, 2026 02:20
@hikaru-0602 hikaru-0602 merged commit ea5f59d into main Apr 7, 2026
2 of 3 checks passed
@hikaru-0602 hikaru-0602 deleted the fix/semester-filter branch April 7, 2026 02:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +320 to +335
for _, date := range dates {
yearMap[date.Year()] = struct{}{}

month := date.Month()
if month >= 4 && month <= 9 {
semesterMap[domain.CourseSemesterH1] = struct{}{}
semesterMap[domain.CourseSemesterQ1] = struct{}{}
semesterMap[domain.CourseSemesterQ2] = struct{}{}
semesterMap[domain.CourseSemesterAllYear] = struct{}{}
} else {
semesterMap[domain.CourseSemesterH2] = struct{}{}
semesterMap[domain.CourseSemesterQ3] = struct{}{}
semesterMap[domain.CourseSemesterQ4] = struct{}{}
semesterMap[domain.CourseSemesterAllYear] = struct{}{}
}
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Year の推定が暦年(date.Year())ベースになっており、学年/年度が4月開始の想定だと1〜3月が前年扱いになりません。例えば 2026/01 は学年度 2025 となるケースが多く、現在の実装だと yearMap が分断されて Year フィルタが nil になったり、誤った年度で絞り込む可能性があります。月が1〜3月の場合は年度を date.Year()-1 として扱うなど、学年度の定義に合わせて Year を算出してください。

Copilot uses AI. Check for mistakes.
for sem := range semesterMap {
semesters = append(semesters, sem)
}

Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

map から slice への変換結果が非決定順になるため、呼び出し側がスライスの順序に依存している場合(比較、ログ、キャッシュキー、SQLのIN句生成とテストの期待など)に結果が不安定になります。return 前に semesters を定義済みの順序(例: AllYear, H1, Q1, Q2, H2, Q3, Q4 などドメイン規約)でソートして、出力を決定的にするのが安全です。

Suggested change
semesterOrder := map[domain.CourseSemester]int{
domain.CourseSemesterAllYear: 0,
domain.CourseSemesterH1: 1,
domain.CourseSemesterQ1: 2,
domain.CourseSemesterQ2: 3,
domain.CourseSemesterH2: 4,
domain.CourseSemesterQ3: 5,
domain.CourseSemesterQ4: 6,
}
sort.Slice(semesters, func(i, j int) bool {
return semesterOrder[semesters[i]] < semesterOrder[semesters[j]]
})

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants