Skip to content

Commit

Permalink
Merge pull request #19 from DoktorMike/main
Browse files Browse the repository at this point in the history
  • Loading branch information
drizk1 authored Oct 21, 2024
2 parents 40327c3 + 7068a23 commit d91532b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/TidierDates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ function floor_date(dt::Union{DateTime, Date, Time, Missing}, unit::String)

if unit == "year"
return floor(dt, Year)
elseif unit == "quarter"
return floor(dt, Quarter)
elseif unit == "month"
return floor(dt, Month)
elseif unit == "week"
Expand All @@ -84,7 +86,7 @@ function floor_date(dt::Union{DateTime, Date, Time, Missing}, unit::String)
elseif unit == "minute"
return floor(dt, Minute)
else
throw(ArgumentError("Unit must be one of 'year', 'month', 'week', 'day', 'hour', or 'minute'."))
throw(ArgumentError("Unit must be one of 'year', 'quarter', 'month', 'week', 'day', 'hour', or 'minute'."))
end
end

Expand All @@ -100,6 +102,8 @@ function round_date(dt::Union{DateTime, Date, Time, Missing}, unit::String)
if dt isa DateTime || dt isa Date
if unit == "year"
return round(dt, Year)
elseif unit == "quarter"
return round(dt, Quarter)
elseif unit == "month"
return round(dt, Month)
elseif unit == "day"
Expand All @@ -112,7 +116,7 @@ function round_date(dt::Union{DateTime, Date, Time, Missing}, unit::String)
elseif unit == "second"
return round(dt, Second)
else
throw(ArgumentError("Unit must be one of 'year', 'month', 'day', 'hour', 'minute', 'second'."))
throw(ArgumentError("Unit must be one of 'year', 'quarter', 'month', 'day', 'hour', 'minute', 'second'."))
end
else
throw(ArgumentError("Unit must be one of 'year', 'month', 'day'."))
Expand Down
12 changes: 9 additions & 3 deletions src/datedocstrings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ Round down a DateTime object to the nearest specified unit.
# Arguments
`dt`: A DateTime object (can contain missing values in a DataFrame).
`unit`: A string specifying the units to use for rounding down. The units can be one of the following: "year", "month", "week", "day", "hour", "minute".
`unit`: A string specifying the units to use for rounding down. The units can be one of the following: "year", "quarter", "month", "week", "day", "hour", "minute".
# Returns
The DateTime object rounded down to the nearest specified unit. If the input is missing, the function returns a missing value.
Expand All @@ -157,6 +157,9 @@ julia> floor_date(dt, "day")
julia> floor_date(dt, "week")
2023-06-11T00:00:00
julia> floor_date(dt, "quarter")
2023-04-01T00:00:00
julia> floor_date(missing, "day")
missing
```
Expand All @@ -170,7 +173,7 @@ Round a DateTime, Date, or Time object to the nearest specified unit.
# Arguments
`dt`: A DateTime, Date, or Time object (can contain missing values in a DataFrame).
`unit`: A string specifying the units to use for rounding. The units can be one of the following: "year", "month", "day", "hour", "minute", "second".
`unit`: A string specifying the units to use for rounding. The units can be one of the following: "year", "quarter", "month", "day", "hour", "minute", "second".
# Returns
The DateTime, Date, or Time object rounded to the nearest specified unit. If the input is missing, the function returns a missing value.
Expand All @@ -186,6 +189,9 @@ julia> round_date(dt, "hour")
julia> round_date(dt, "day")
2023-06-15T00:00:00
julia> round_date(dt, "quarter")
2023-07-01T00:00:00
julia> round_date(missing, "day")
missing
```
Expand Down Expand Up @@ -621,4 +627,4 @@ julia> hm("09:30")
julia> hm("12:60")
missing
```
"""
"""

0 comments on commit d91532b

Please sign in to comment.