-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,7 +252,7 @@ defmodule NaiveDateTime do | |
Calendar.hour(), | ||
Calendar.minute(), | ||
Calendar.second(), | ||
Calendar.microsecond() | non_neg_integer, | ||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: {:ok, t} | {:error, atom} | ||
def new(year, month, day, hour, minute, second, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure here, but the rest of the file uses |
||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: t | ||
def new!( | ||
|
@@ -993,6 +993,8 @@ defmodule NaiveDateTime do | |
|
||
iex> NaiveDateTime.from_erl({{2000, 1, 1}, {13, 30, 15}}) | ||
{:ok, ~N[2000-01-01 13:30:15]} | ||
iex> NaiveDateTime.from_erl({{2000, 1, 1}, {13, 30, 15}}, 5000) | ||
{:ok, ~N[2000-01-01 13:30:15.005000]} | ||
iex> NaiveDateTime.from_erl({{2000, 1, 1}, {13, 30, 15}}, {5000, 3}) | ||
{:ok, ~N[2000-01-01 13:30:15.005]} | ||
iex> NaiveDateTime.from_erl({{2000, 13, 1}, {13, 30, 15}}) | ||
|
@@ -1001,7 +1003,11 @@ defmodule NaiveDateTime do | |
{:error, :invalid_date} | ||
|
||
""" | ||
@spec from_erl(:calendar.datetime(), Calendar.microsecond(), Calendar.calendar()) :: | ||
@spec from_erl( | ||
:calendar.datetime(), | ||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: | ||
{:ok, t} | {:error, atom} | ||
def from_erl(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) | ||
|
||
|
@@ -1020,13 +1026,19 @@ defmodule NaiveDateTime do | |
|
||
iex> NaiveDateTime.from_erl!({{2000, 1, 1}, {13, 30, 15}}) | ||
~N[2000-01-01 13:30:15] | ||
iex> NaiveDateTime.from_erl!({{2000, 1, 1}, {13, 30, 15}}, 5000) | ||
~N[2000-01-01 13:30:15.005000] | ||
iex> NaiveDateTime.from_erl!({{2000, 1, 1}, {13, 30, 15}}, {5000, 3}) | ||
~N[2000-01-01 13:30:15.005] | ||
iex> NaiveDateTime.from_erl!({{2000, 13, 1}, {13, 30, 15}}) | ||
** (ArgumentError) cannot convert {{2000, 13, 1}, {13, 30, 15}} to naive datetime, reason: :invalid_date | ||
|
||
""" | ||
@spec from_erl!(:calendar.datetime(), Calendar.microsecond(), Calendar.calendar()) :: t | ||
@spec from_erl!( | ||
:calendar.datetime(), | ||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: t | ||
def from_erl!(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) do | ||
case from_erl(tuple, microsecond, calendar) do | ||
{:ok, value} -> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure here, but the rest of the file uses |
||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: {:ok, t} | {:error, atom} | ||
def new(hour, minute, second, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. The docs were lacking the basic |
||
{:ok, ~T[23:30:15]} | ||
iex> Time.from_erl({23, 30, 15}, 5000) | ||
{:ok, ~T[23:30:15.005000]} | ||
iex> Time.from_erl({23, 30, 15}, {5000, 3}) | ||
{:ok, ~T[23:30:15.005]} | ||
iex> Time.from_erl({24, 30, 15}) | ||
{:error, :invalid_time} | ||
|
||
""" | ||
@spec from_erl(:calendar.time(), Calendar.microsecond(), Calendar.calendar()) :: | ||
@spec from_erl( | ||
:calendar.time(), | ||
Calendar.microsecond() | non_neg_integer(), | ||
Calendar.calendar() | ||
) :: | ||
{:ok, t} | {:error, atom} | ||
def from_erl(tuple, microsecond \\ {0, 0}, calendar \\ Calendar.ISO) | ||
|
||
|
@@ -377,6 +385,8 @@ defmodule Time do | |
|
||
iex> Time.from_erl!({23, 30, 15}) | ||
~T[23:30:15] | ||
iex> Time.from_erl!({23, 30, 15}, 5000) | ||
~T[23:30:15.005000] | ||
iex> Time.from_erl!({23, 30, 15}, {5000, 3}) | ||
~T[23:30:15.005] | ||
iex> Time.from_erl!({24, 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.
I'm not sure here, but the rest of the file uses
non_neg_integer()
spec notation, so I tweaked the spec here.