-
Notifications
You must be signed in to change notification settings - Fork 109
Add non-throwing LocalDate(Time) construction & parsing #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
However, why is this needed for |
User input directly from form fields.
…On Thu, Jun 3, 2021, 12:24 dkhalanskyjb ***@***.***> wrote:
orNull variants of TimeZone.of or Something.parse probably make sense and
follow the spirit of the provided link, which describes orNull as a
modifier that shows that error conditions are expected (for example, when
validating user input) and must be handled.
However, why is this needed for LocalDate? Could you please describe some
situations where a programmer has values for year, month, and day, then
puts these values into a LocalDate constructor, which rejects them, but
this error is not a logic error and can somehow be recovered from?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#68 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAUZ6RE3YWCTML5KHCHYNTTQ5Q5RANCNFSM4TOM35EQ>
.
|
Wouldn't one want the users to know what field did they make a mistake in? Better yet, why not give the users a date picker that prevents invalid dates altogether? |
Long-term? Probably. It's more work and probably pointless. I found more use-cases in my code where I use
|
What do you think of |
The lack of a verb really throws me. I would expect parseOrNull or tryParse or something. The top-level function will always match the class name/pretend to be a constructor, but a companion function could be imported and used bare without the type qualifier. |
Definitely, the null-returning parsing function is going to be called There isn't really a precedent for this, so we are treading new ground. |
The problem i found with ...orNull() like functions, is that they hide the reason behind the error or failure that caused the object not being created. |
There should be
null
-returning variants for creatingLocalDate(Time)
instances. It shouldn't be necessary to catch an exception. This is especially useful when creating instances from user input.Also:
Instant.parse(…)
TimeZone.of(…)
Just like all similar stdlib functions have
…OrNull
variants.https://elizarov.medium.com/kotlin-and-exceptions-8062f589d07
The text was updated successfully, but these errors were encountered: