Fix errors in UTC conversion in UE2, add initial UE2.A3 implementation
This commit is contained in:
parent
c440186462
commit
ed91bdfc67
144
code/Angabe2.hs
144
code/Angabe2.hs
@ -89,13 +89,13 @@ is_date_valid (d, u)
|
||||
| monat d == Feb =
|
||||
let y = jahr d in
|
||||
let t = tag d in
|
||||
if y `mod` 4 /= 0 && (day_to_num t) > (day_to_num XXVIII) then False
|
||||
if y `mod` 4 /= 0 && (day_to_str t) > (day_to_str XXVIII) then False
|
||||
else
|
||||
if y `mod` 100 == 0 && y `mod` 400 /= 0 then False
|
||||
else
|
||||
if (day_to_num t) > (day_to_num XXIX) then False
|
||||
if (day_to_str t) > (day_to_str XXIX) then False
|
||||
else True
|
||||
| (day_to_num (tag d)) > (day_to_num XXX) && not(monat d `elem` full_months) = False
|
||||
| (day_to_str (tag d)) > (day_to_str XXX) && not(monat d `elem` full_months) = False
|
||||
| otherwise = True
|
||||
|
||||
uhrzeit_vhds :: Uhrzeit -> VHDS
|
||||
@ -115,25 +115,42 @@ anzahl :: DreiG_Status -> Anzahl
|
||||
anzahl (Geimpft (_, a)) = a
|
||||
|
||||
-- Dumb conversion functions
|
||||
person_to_string :: Person -> VorUndNachname
|
||||
person_to_string p = (show (vorname p)) ++ " " ++ (show (nachname p))
|
||||
|
||||
timeFormat = "%Y-%m-%d %l:%M:%S %p"
|
||||
|
||||
timeFormat = "%Y-%m-%d %0I:%0M:%S %p"
|
||||
understandTime = parseTimeOrError True defaultTimeLocale timeFormat
|
||||
|
||||
convert_to_utc :: (Datum, Uhrzeit) -> UTCTime
|
||||
convert_to_utc (d, u) =
|
||||
let
|
||||
day = show (day_to_num (tag d))
|
||||
month = show (month_to_num (monat d))
|
||||
day = day_to_str (tag d)
|
||||
month = month_to_str (monat d)
|
||||
year = show (jahr d)
|
||||
vm = vm_to_ampm (uhrzeit_vornach u)
|
||||
vhds = show (vhds_to_num (uhrzeit_vhds u))
|
||||
hour = (if vhds /= "0" then show (hour_to_num (uhrzeit_stunde u) - 1) else show (hour_to_num (uhrzeit_stunde u)))
|
||||
vhds = vhds_to_str (uhrzeit_vhds u)
|
||||
hour = (convert_hour (uhrzeit_stunde u) vhds)
|
||||
date = year ++ "-" ++ month ++ "-" ++ day
|
||||
time = hour ++ ":" ++ vhds ++ ":00"
|
||||
datetime = date ++ " " ++ time ++ " " ++ vm
|
||||
in
|
||||
understandTime datetime
|
||||
|
||||
convert_hour :: Stunde -> String -> String
|
||||
convert_hour s v
|
||||
| v /= "00" =
|
||||
if (hour_to_num s - 1) <= 9 then
|
||||
"0" ++ show (hour_to_num s - 1)
|
||||
else
|
||||
show (hour_to_num s - 1)
|
||||
| otherwise =
|
||||
if hour_to_num s <= 9 then
|
||||
"0" ++ show (hour_to_num s)
|
||||
else
|
||||
show (hour_to_num s)
|
||||
|
||||
|
||||
vm_to_ampm :: VorNachMittag -> String
|
||||
vm_to_ampm vm
|
||||
| vm == VM = "am"
|
||||
@ -153,58 +170,58 @@ hour_to_num Zehn = 10
|
||||
hour_to_num Elf = 11
|
||||
hour_to_num Zwoelf = 12
|
||||
|
||||
vhds_to_num :: VHDS -> Nat1
|
||||
vhds_to_num Schlag = 0
|
||||
vhds_to_num Viertel = 15
|
||||
vhds_to_num Halb = 30
|
||||
vhds_to_num Dreiviertel = 45
|
||||
vhds_to_str :: VHDS -> String
|
||||
vhds_to_str Schlag = "00"
|
||||
vhds_to_str Viertel = "15"
|
||||
vhds_to_str Halb = "30"
|
||||
vhds_to_str Dreiviertel = "45"
|
||||
|
||||
day_to_num :: Tag -> Nat1
|
||||
day_to_num I = 1
|
||||
day_to_num II = 2
|
||||
day_to_num III = 3
|
||||
day_to_num IV = 4
|
||||
day_to_num V = 5
|
||||
day_to_num VI = 6
|
||||
day_to_num VII = 7
|
||||
day_to_num VIII = 8
|
||||
day_to_num IX = 9
|
||||
day_to_num X = 10
|
||||
day_to_num XI = 11
|
||||
day_to_num XII = 12
|
||||
day_to_num XIII = 13
|
||||
day_to_num XIV = 14
|
||||
day_to_num XV = 15
|
||||
day_to_num XVI = 16
|
||||
day_to_num XVII = 17
|
||||
day_to_num XVIII = 18
|
||||
day_to_num XIX = 19
|
||||
day_to_num XX = 20
|
||||
day_to_num XXI = 21
|
||||
day_to_num XXII = 22
|
||||
day_to_num XXIII = 23
|
||||
day_to_num XXIV = 24
|
||||
day_to_num XXV = 25
|
||||
day_to_num XXVI = 26
|
||||
day_to_num XXVII = 27
|
||||
day_to_num XXVIII = 28
|
||||
day_to_num XXIX = 29
|
||||
day_to_num XXX = 30
|
||||
day_to_num XXXI = 31
|
||||
day_to_str :: Tag -> String
|
||||
day_to_str I = "01"
|
||||
day_to_str II = "02"
|
||||
day_to_str III = "03"
|
||||
day_to_str IV = "04"
|
||||
day_to_str V = "05"
|
||||
day_to_str VI = "06"
|
||||
day_to_str VII = "07"
|
||||
day_to_str VIII = "08"
|
||||
day_to_str IX = "09"
|
||||
day_to_str X = "10"
|
||||
day_to_str XI = "11"
|
||||
day_to_str XII = "12"
|
||||
day_to_str XIII = "13"
|
||||
day_to_str XIV = "14"
|
||||
day_to_str XV = "15"
|
||||
day_to_str XVI = "16"
|
||||
day_to_str XVII = "17"
|
||||
day_to_str XVIII = "18"
|
||||
day_to_str XIX = "19"
|
||||
day_to_str XX = "20"
|
||||
day_to_str XXI = "21"
|
||||
day_to_str XXII = "22"
|
||||
day_to_str XXIII = "23"
|
||||
day_to_str XXIV = "24"
|
||||
day_to_str XXV = "25"
|
||||
day_to_str XXVI = "26"
|
||||
day_to_str XXVII = "27"
|
||||
day_to_str XXVIII = "28"
|
||||
day_to_str XXIX = "29"
|
||||
day_to_str XXX = "30"
|
||||
day_to_str XXXI = "31"
|
||||
|
||||
month_to_num :: Monat -> Nat1
|
||||
month_to_num Jan = 1
|
||||
month_to_num Feb = 2
|
||||
month_to_num Mar = 3
|
||||
month_to_num Apr = 4
|
||||
month_to_num Mai = 5
|
||||
month_to_num Jun = 6
|
||||
month_to_num Jul = 7
|
||||
month_to_num Aug = 8
|
||||
month_to_num Sep = 9
|
||||
month_to_num Okt = 10
|
||||
month_to_num Nov = 11
|
||||
month_to_num Dez = 12
|
||||
month_to_str :: Monat -> String
|
||||
month_to_str Jan = "01"
|
||||
month_to_str Feb = "02"
|
||||
month_to_str Mar = "03"
|
||||
month_to_str Apr = "04"
|
||||
month_to_str Mai = "05"
|
||||
month_to_str Jun = "06"
|
||||
month_to_str Jul = "07"
|
||||
month_to_str Aug = "08"
|
||||
month_to_str Sep = "09"
|
||||
month_to_str Okt = "10"
|
||||
month_to_str Nov = "11"
|
||||
month_to_str Dez = "12"
|
||||
|
||||
-- Aufgabe A.2
|
||||
{-
|
||||
@ -291,13 +308,18 @@ calculate_time_diff u1 u2 =
|
||||
|
||||
-- Aufgabe A.3
|
||||
|
||||
--einzulassende :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> Einzulassende
|
||||
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht einzulassende folgendermassen vor:
|
||||
...
|
||||
-}
|
||||
|
||||
einzulassende :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> Einzulassende
|
||||
einzulassende p r k = allowed_people p r k []
|
||||
|
||||
allowed_people :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> [VorUndNachname] -> Einzulassende
|
||||
allowed_people (p:ps) r k res
|
||||
| (einzulassen (p, r, k)) == Einlassen = allowed_people ps r k (res ++ [person_to_string p])
|
||||
| otherwise = allowed_people ps r k res
|
||||
|
||||
-- Aufgabe A.4
|
||||
|
||||
--einzulassende_abzuweisende :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> ([Einzulassende],[Abzuweisende])
|
||||
|
Reference in New Issue
Block a user