Homework-4/src/ClassSchedule/Model.elm

71 lines
1.4 KiB
Elm

module ClassSchedule.Model exposing (..)
import Dict exposing (..)
import Http exposing (Error)
type alias Crn = (String, Int)
type DayOfWeek
= Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
type DayHalf = AM | PM
type alias Time = (Int, Int, DayHalf)
flipDayHalf : DayHalf -> DayHalf
flipDayHalf dh =
case dh of
AM -> PM
PM -> AM
hour24 : Time -> Int
hour24 (h, _, th) = if th == AM then h else h + 12
from24 : Int -> Time
from24 i = (modBy 12 i, 0, if i >= 12 then PM else AM)
addHours : Int -> Time -> Time
addHours hh (h, m, dh) =
if h + hh >= 12
then (h + hh - 12, m, flipDayHalf dh)
else (h + hh, m, dh)
addMinutes : Int -> Time -> Time
addMinutes mm (h, m, dh) =
let
remainder = modBy 60 (m + mm)
hh = (m + mm) // 60
in
addHours hh (h, remainder, dh)
type alias Course =
{ crn : Crn
, name : String
, instructors : List String
, times : List (DayOfWeek, Time, Time)
}
type CourseStatus = NotAdded | Added
type alias Flags = ()
type Msg
= SearchInput String
| SelectTerm String
| SelectCourse Int
| AddCourse Int
| RemoveCourse Int
| ReceiveData (Result Error (List Course))
type alias Model =
{ terms : Dict String (List (CourseStatus, Course))
, term : String
, selected : Maybe Int
, searchInput : String
}