Skip to content

Commit 1829685

Browse files
committed
Added docstrings to datefunctions
1 parent 44c46fc commit 1829685

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

src/date_functions.jl

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,33 @@ const MILLISECONDS_IN_YEAR_365 = SECONDS_IN_YEAR_365 * 1000
33

44
# --- Time Conversions ---
55

6-
"Convert a `Date`, `DateTime`, or ticks (Int/Float64) to milliseconds since epoch."
7-
to_ticks(x::Date) = Dates.datetime2epochms(DateTime(x))
8-
to_ticks(x::DateTime) = Dates.datetime2epochms(x)
9-
to_ticks(x::Real) = x # Already Float64-compatible
6+
"""
7+
to_ticks(x::Date)
8+
9+
Convert a `Date` to milliseconds since the Unix epoch.
10+
"""
11+
function to_ticks(x::Date)
12+
return Dates.datetime2epochms(DateTime(x))
13+
end
14+
15+
"""
16+
to_ticks(x::DateTime)
17+
18+
Convert a `DateTime` to milliseconds since the Unix epoch.
19+
"""
20+
function to_ticks(x::DateTime)
21+
return Dates.datetime2epochms(x)
22+
end
23+
24+
"""
25+
to_ticks(x::Real)
26+
27+
Assume `x` is already a timestamp in milliseconds (e.g., `Float64` or `Int`).
28+
Used to normalize mixed inputs.
29+
"""
30+
function to_ticks(x::Real)
31+
return x
32+
end
1033

1134
# --- ACT/365 Year Fractions ---
1235

@@ -43,7 +66,16 @@ Returns the updated timestamp in milliseconds as `Float64`.
4366
4467
This version is AD-compatible.
4568
"""
46-
add_yearfrac(t::Real, yf::Real) = t + yf * MILLISECONDS_IN_YEAR_365
69+
function add_yearfrac(t::Real, yf::Real)
70+
return t + yf * MILLISECONDS_IN_YEAR_365
71+
end
4772

48-
# Date-based (returns DateTime)
49-
add_yearfrac(t::TimeType, yf::Real) = Dates.epochms2datetime(add_yearfrac(to_ticks(t), yf))
73+
"""
74+
add_yearfrac(t::TimeType, yf::Real) -> DateTime
75+
76+
Add a fractional number of years (ACT/365) to a `Date` or `DateTime`.
77+
Returns a `DateTime` object.
78+
"""
79+
function add_yearfrac(t::TimeType, yf::Real)
80+
return Dates.epochms2datetime(add_yearfrac(to_ticks(t), yf))
81+
end

0 commit comments

Comments
 (0)