Skip to content

Commit

Permalink
Merge pull request #38277 from PaulSoderlind/master
Browse files Browse the repository at this point in the history
added missing trunc methods for Quarter
  • Loading branch information
quinnj authored Nov 4, 2020
2 parents 99805a3 + b7324f4 commit b00802b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/Dates/src/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

### truncation
Base.trunc(dt::Date, p::Type{Year}) = Date(UTD(totaldays(year(dt), 1, 1)))
Base.trunc(dt::Date, p::Type{Quarter}) = firstdayofquarter(dt)
Base.trunc(dt::Date, p::Type{Month}) = firstdayofmonth(dt)
Base.trunc(dt::Date, p::Type{Day}) = dt

Base.trunc(dt::DateTime, p::Type{Year}) = DateTime(trunc(Date(dt), Year))
Base.trunc(dt::DateTime, p::Type{Quarter}) = DateTime(trunc(Date(dt), Quarter))
Base.trunc(dt::DateTime, p::Type{Month}) = DateTime(trunc(Date(dt), Month))
Base.trunc(dt::DateTime, p::Type{Day}) = DateTime(Date(dt))
Base.trunc(dt::DateTime, p::Type{Hour}) = dt - Minute(dt) - Second(dt) - Millisecond(dt)
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Dates/test/adjusters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ using Dates
@testset "trunc" begin
dt = Dates.Date(2012, 12, 21)
@test trunc(dt, Dates.Year) == Dates.Date(2012)
@test trunc(dt, Dates.Quarter) == Dates.Date(2012, 10)
@test trunc(dt, Dates.Month) == Dates.Date(2012, 12)
@test trunc(dt, Dates.Day) == Dates.Date(2012, 12, 21)
dt = Dates.DateTime(2012, 12, 21, 16, 30, 20, 200)
@test trunc(dt, Dates.Year) == Dates.DateTime(2012)
@test trunc(dt, Dates.Quarter) == Dates.DateTime(2012, 10)
@test trunc(dt, Dates.Month) == Dates.DateTime(2012, 12)
@test trunc(dt, Dates.Day) == Dates.DateTime(2012, 12, 21)
@test trunc(dt, Dates.Hour) == Dates.DateTime(2012, 12, 21, 16)
Expand Down

4 comments on commit b00802b

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - successfully executed benchmarks. A full report can be found here. cc @christopher-dG

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected. A full report can be found here. cc @maleadt

Please sign in to comment.