@@ -3,10 +3,33 @@ const MILLISECONDS_IN_YEAR_365 = SECONDS_IN_YEAR_365 * 1000
3
3
4
4
# --- Time Conversions ---
5
5
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
10
33
11
34
# --- ACT/365 Year Fractions ---
12
35
@@ -43,7 +66,16 @@ Returns the updated timestamp in milliseconds as `Float64`.
43
66
44
67
This version is AD-compatible.
45
68
"""
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
47
72
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