-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Tweak NaiveDateTime.from_erl
and Time.from_erl
specs
#13987
Tweak NaiveDateTime.from_erl
and Time.from_erl
specs
#13987
Conversation
@@ -252,7 +252,7 @@ defmodule NaiveDateTime do | |||
Calendar.hour(), | |||
Calendar.minute(), | |||
Calendar.second(), | |||
Calendar.microsecond() | non_neg_integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, but the rest of the file uses non_neg_integer()
spec notation, so I tweaked the spec here.
@@ -317,7 +317,7 @@ defmodule NaiveDateTime do | |||
Calendar.hour(), | |||
Calendar.minute(), | |||
Calendar.second(), | |||
Calendar.microsecond() | non_neg_integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, but the rest of the file uses non_neg_integer()
spec notation, so I tweaked the spec here.
@@ -115,7 +115,7 @@ defmodule Time do | |||
Calendar.hour(), | |||
Calendar.minute(), | |||
Calendar.second(), | |||
Calendar.microsecond() | non_neg_integer, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure here, but the rest of the file uses non_neg_integer()
spec notation, so I tweaked the spec here.
@@ -355,13 +355,21 @@ defmodule Time do | |||
|
|||
## Examples | |||
|
|||
iex> Time.from_erl({23, 30, 15}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs were lacking the basic from_erl
case, from_erl!
has it, so I added one here too.
💚 💙 💜 💛 ❤️ |
The changes align
NaiveDateTime.from_erl
andTime.from_erl
specs with their correspondingNaiveDateTime.new
andTime.new
specs.The
new
function specs accept a non-negative integer or a tuple of {seconds, precision} for microseconds.Here's
NaiveDateTime.new/8
's spec:elixir/lib/elixir/lib/calendar/naive_datetime.ex
Lines 248 to 257 in cb2e036
And
NaiveDateTime.from_erl
's spec + implementation:elixir/lib/elixir/lib/calendar/naive_datetime.ex
Lines 1004 to 1011 in cb2e036
Here's the
Time.new/5
spec:elixir/lib/elixir/lib/calendar/time.ex
Lines 114 to 120 in cb2e036
And the corresponding
from_erl
:elixir/lib/elixir/lib/calendar/time.ex
Lines 364 to 371 in cb2e036
In both cases, the corresponding
new
functions handlenon_negative_integer
microseconds. I also added tests to confirm it.Please notice that both
NaiveDateTime.t.microsecond
andTime.t.microsecond
are ofCalendar.microsecond()
type, and it's okay becausenew
functions setmicrosecond: {microsecond, 6}
with default precision if none is provided.