Skip to content

Commit b00802b

Browse files
authored
Merge pull request #38277 from PaulSoderlind/master
added missing trunc methods for Quarter
2 parents 99805a3 + b7324f4 commit b00802b

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

stdlib/Dates/src/adjusters.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
### truncation
44
Base.trunc(dt::Date, p::Type{Year}) = Date(UTD(totaldays(year(dt), 1, 1)))
5+
Base.trunc(dt::Date, p::Type{Quarter}) = firstdayofquarter(dt)
56
Base.trunc(dt::Date, p::Type{Month}) = firstdayofmonth(dt)
67
Base.trunc(dt::Date, p::Type{Day}) = dt
78

89
Base.trunc(dt::DateTime, p::Type{Year}) = DateTime(trunc(Date(dt), Year))
10+
Base.trunc(dt::DateTime, p::Type{Quarter}) = DateTime(trunc(Date(dt), Quarter))
911
Base.trunc(dt::DateTime, p::Type{Month}) = DateTime(trunc(Date(dt), Month))
1012
Base.trunc(dt::DateTime, p::Type{Day}) = DateTime(Date(dt))
1113
Base.trunc(dt::DateTime, p::Type{Hour}) = dt - Minute(dt) - Second(dt) - Millisecond(dt)

stdlib/Dates/test/adjusters.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ using Dates
88
@testset "trunc" begin
99
dt = Dates.Date(2012, 12, 21)
1010
@test trunc(dt, Dates.Year) == Dates.Date(2012)
11+
@test trunc(dt, Dates.Quarter) == Dates.Date(2012, 10)
1112
@test trunc(dt, Dates.Month) == Dates.Date(2012, 12)
1213
@test trunc(dt, Dates.Day) == Dates.Date(2012, 12, 21)
1314
dt = Dates.DateTime(2012, 12, 21, 16, 30, 20, 200)
1415
@test trunc(dt, Dates.Year) == Dates.DateTime(2012)
16+
@test trunc(dt, Dates.Quarter) == Dates.DateTime(2012, 10)
1517
@test trunc(dt, Dates.Month) == Dates.DateTime(2012, 12)
1618
@test trunc(dt, Dates.Day) == Dates.DateTime(2012, 12, 21)
1719
@test trunc(dt, Dates.Hour) == Dates.DateTime(2012, 12, 21, 16)

0 commit comments

Comments
 (0)