You're getting the Result
because there is a chance that parsing the string to a date failed. You can handle it one of 2 ways.
Ignore it
If you want to just say "I know this string will be valid date and I'm not worried that I may have messed it up" then you can just provide a default date
Date.fromString "2011/1/1" |> Result.withDefault (Date.fromTime 0)
This will leave you with a Date
but will default to the unix epoch if the parse fails.
Use it
Think about what you would want to happen if the parse were to fail and handle it where the date is used. Ex. if you're displaying it as a string you could display the date or if the parse failed display "TBA"
.
Note: You may have noticed that Date.fromTime
just returns a Date
not a Result
(because an Int
can always be parsed to a Date
). If you don't mind converting your dates to unix timestamps you could hardcode the timestamp and use that without having to deal with Result
s