Add UE2 A.5
This commit is contained in:
parent
cc4469a5c1
commit
31af5c1350
@ -23,7 +23,7 @@ data Stunde = Eins | Zwei | Drei | Vier | Fuenf | Sechs
|
||||
| Sieben | Acht | Neun | Zehn | Elf
|
||||
| Zwoelf deriving (Eq,Ord,Show)
|
||||
data VorNachMittag = VM | NM deriving (Eq,Ord,Show)
|
||||
newtype Uhrzeit = U (VHDS,Stunde,VorNachMittag) deriving (Eq,Ord,Show)
|
||||
newtype Uhrzeit = U (VHDS,Stunde,VorNachMittag) deriving (Eq,Ord)
|
||||
data Tag = I | II | III | IV | V | VI | VII | VIII | IX | X
|
||||
| XI | XII | XIII | XIV | XV | XVI | XVII | XVIII
|
||||
| XIX | XX | XXI | XXII | XXIII | XXIV | XXV
|
||||
@ -36,7 +36,7 @@ data Datum = D {
|
||||
tag :: Tag,
|
||||
monat :: Monat,
|
||||
jahr :: Jahr
|
||||
} deriving (Eq,Show,Ord)
|
||||
} deriving (Eq,Ord)
|
||||
data Testart = PCR | Antigen deriving (Eq,Show,Ord)
|
||||
data Impfstoff = AstraZeneca | BioNTec | JundJ | Moderna
|
||||
| Sputnik | Sinovac deriving (Eq,Show,Ord)
|
||||
@ -129,6 +129,10 @@ person_to_string p =
|
||||
n = nachname_to_str (nachname p)
|
||||
|
||||
|
||||
{-
|
||||
Convert datetime from our type to utc time (am/pm mode)
|
||||
-}
|
||||
|
||||
timeFormat = "%Y-%m-%d %0I:%0M:%S %p"
|
||||
understandTime = parseTimeOrError True defaultTimeLocale timeFormat
|
||||
|
||||
@ -140,15 +144,18 @@ convert_to_utc (d, u) =
|
||||
year = show (jahr d)
|
||||
vm = vm_to_ampm (uhrzeit_vornach u)
|
||||
vhds = vhds_to_str (uhrzeit_vhds u)
|
||||
hour = (convert_hour (uhrzeit_stunde u) vhds)
|
||||
hour = (convert_hour_am_pm (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
|
||||
{-
|
||||
Convert hour to string (am/pm mode)
|
||||
-}
|
||||
convert_hour_am_pm :: Stunde -> String -> String
|
||||
convert_hour_am_pm s v
|
||||
| v /= "00" =
|
||||
if (hour_to_num s - 1) <= 9 then
|
||||
"0" ++ show (hour_to_num s - 1)
|
||||
@ -160,6 +167,27 @@ convert_hour s v
|
||||
else
|
||||
show (hour_to_num s)
|
||||
|
||||
{-
|
||||
Convert hour to string (24h mode)
|
||||
-}
|
||||
convert_hour :: Stunde -> String -> VorNachMittag -> String
|
||||
convert_hour s v vn
|
||||
| v /= "00" =
|
||||
if vn == VM then
|
||||
if (hour_to_num s - 1) <= 9 then
|
||||
"0" ++ show (hour_to_num s - 1)
|
||||
else
|
||||
show (hour_to_num s - 1)
|
||||
else
|
||||
show ((hour_to_num s + 12) - 1)
|
||||
| otherwise =
|
||||
if vn == VM then
|
||||
if hour_to_num s <= 9 then
|
||||
"0" ++ show (hour_to_num s)
|
||||
else
|
||||
show (hour_to_num s)
|
||||
else
|
||||
show ((hour_to_num s + 12))
|
||||
|
||||
vm_to_ampm :: VorNachMittag -> String
|
||||
vm_to_ampm vm
|
||||
@ -325,7 +353,7 @@ calculate_time_diff u1 u2 =
|
||||
when the tail is empty, terminate
|
||||
-}
|
||||
|
||||
einzulassende :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> Einzulassend
|
||||
einzulassende :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> Einzulassende
|
||||
einzulassende p r k = allowed_people p r k []
|
||||
|
||||
allowed_people :: Einlassbegehrende -> Regel -> Kontrollzeitpunkt -> [VorUndNachname] -> Einzulassende
|
||||
@ -350,19 +378,28 @@ einzulassende_abzuweisende p r k = ((einzulassende p r k), (disallowed_people p
|
||||
|
||||
-- Aufgabe A.5
|
||||
|
||||
--instance Show Uhrzeit where
|
||||
--show ...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Implementierung von show fuer Uhrzeit
|
||||
folgendermassen vor:
|
||||
...
|
||||
{-
|
||||
call the conversion methods that we defined for the utc conversion above and build the string
|
||||
-}
|
||||
|
||||
instance Show Uhrzeit where
|
||||
show (U (m, h, a)) =
|
||||
hour ++ ":" ++ min ++ " Uhr"
|
||||
where
|
||||
min = vhds_to_str m
|
||||
hour = convert_hour h (vhds_to_str m) a
|
||||
|
||||
--instance Show Datum where
|
||||
-- show ...
|
||||
|
||||
{- Knapp, aber gut nachvollziehbar geht die Implementierung von show fuer Datum
|
||||
folgendermassen vor:
|
||||
...
|
||||
{-
|
||||
call the conversion methods that we defined for the utc conversion above and build the string
|
||||
-}
|
||||
|
||||
instance Show Datum where
|
||||
show (D d m y) =
|
||||
if (is_date_valid ((D d m y), (U (Dreiviertel,Acht,NM)))) == False then "Datum ungueltig" -- check with valid hour, cause the function also requires hours
|
||||
else
|
||||
day ++ "." ++ month ++ "." ++ year
|
||||
where
|
||||
day = (if head (day_to_str d) == '0' then tail (day_to_str d) else day_to_str d)
|
||||
month = (if head (month_to_str m) == '0' then tail (month_to_str m) else month_to_str m)
|
||||
year = show y
|
||||
|
Reference in New Issue
Block a user