LocalTime to UTC in Elm

In my last application i need a function to transform the local time in a utc time.
At start point i have a utc string of the day of interest and the local time that i want transform in utc time, example “08–07–2020T:12:12:00.000Z” “14:30” and i’d like have 2020–01–01T13:30:00.000Z.
To do this i used this elm package:
"justinmimbs/time-extra"
"justinmimbs/timezone-data"
"rtfeldman/elm-iso8601-date-strings"
The code:
localToUTC : String -> String -> Zone -> String
localToUTC utcTime slot zone =
let
result = Iso8601.toTime utcTime
hourPlusMinutes = String.split ":" slothour = case (List.head hourPlusMinutes) of
Just a ->
case String.toInt a of
Just h ->
hNothing ->
0
Nothing ->
0minutes = case List.head (List.drop 1 hourPlusMinutes) of
Just a ->
case String.toInt a of
Just m ->
mNothing ->
0
Nothing ->
0romeDay = case result of
Ok value ->
toDay zone value
Err msg ->
1romeMonth = case result of
Ok value ->
toMonth zone value
Err msg ->
JanromeYear = case result of
Ok value ->
(toYear zone value)
Err msg ->
2020from = Iso8601.fromTime (partsToPosix rome (Parts romeYear romeMonth romeDay hour minutes 0 0))
in
from
Look the declaration, the utcTime is something utc time of the day of interest, slot is the time in local (HH:mm) and Zone is the timezone.
At first we transform the utc time in time and split the slot in hour and minutes. After we get the day, month and year of the time. At the end we create the utc time from the posix time that we create with the single parts of the datetime.
I hope that this can be helpful to developer that need to play with Date and Time in Elm. Here you can run the code https://ellie-app.com/9nwQB2gjyFGa1.