Skip to content
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

Change Time#date to return a Tuple of year, month, day instead of Time #5822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions spec/std/time/time_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,17 @@ describe Time do
describe ".local" do
it "initializes" do
t1 = Time.local 2002, 2, 25
t1.date.should eq({2002, 2, 25})
t1.year.should eq(2002)
t1.month.should eq(2)
t1.day.should eq(25)
t1.hour.should eq(0)
t1.minute.should eq(0)
t1.second.should eq(0)
t1.local?.should be_true

t2 = Time.local 2002, 2, 25, 15, 25, 13, nanosecond: 8
t2.date.should eq({2002, 2, 25})
t2.year.should eq(2002)
t2.month.should eq(2)
t2.day.should eq(25)
Expand Down
11 changes: 4 additions & 7 deletions src/time.cr
Original file line number Diff line number Diff line change
Expand Up @@ -741,13 +741,10 @@ struct Time
)
end

# Returns a copy of `self` with time-of-day components (hour, minute, second,
# nanoseconds) set to zero.
#
# This equals `at_beginning_of_day` or
# `Time.local(year, month, day, 0, 0, 0, nanoseconds: 0, location: location)`.
def date : Time
Time.local(year, month, day, location: location)
# Returns a `Tuple` with `year`, `month` and `day`.
def date : Tuple(Int32, Int32, Int32)
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
year, month, day, _ = year_month_day_day_year
straight-shoota marked this conversation as resolved.
Show resolved Hide resolved
{year, month, day}
end

# Returns the year of the proleptic Georgian Calendar (`0..9999`).
Expand Down