@@ -39,33 +39,6 @@ function reopen!(drfl::DatetimeRotatingFileLogger)
39
39
return nothing
40
40
end
41
41
42
- # I kind of wish these were defined in Dates
43
- isless (:: Type{Millisecond} , :: Type{Millisecond} ) = false
44
- isless (:: Type{Millisecond} , :: Type{T} ) where {T <: Dates.Period } = true
45
-
46
- isless (:: Type{Second} , :: Type{Millisecond} ) = false
47
- isless (:: Type{Second} , :: Type{Second} ) = false
48
- isless (:: Type{Second} , :: Type{T} ) where {T <: Dates.Period } = true
49
-
50
- isless (:: Type{Minute} , :: Type{Millisecond} ) = false
51
- isless (:: Type{Minute} , :: Type{Second} ) = false
52
- isless (:: Type{Minute} , :: Type{Minute} ) = false
53
- isless (:: Type{Minute} , :: Type{T} ) where {T <: Dates.Period } = true
54
-
55
- isless (:: Type{Hour} , :: Type{Day} ) = true
56
- isless (:: Type{Hour} , :: Type{Month} ) = true
57
- isless (:: Type{Hour} , :: Type{Year} ) = true
58
- isless (:: Type{Hour} , :: Type{T} ) where {T <: Dates.Period } = false
59
-
60
- isless (:: Type{Day} , :: Type{Month} ) = true
61
- isless (:: Type{Day} , :: Type{Year} ) = true
62
- isless (:: Type{Day} , :: Type{T} ) where {T <: Dates.Period } = false
63
-
64
- isless (:: Type{Month} , :: Type{Year} ) = true
65
- isless (:: Type{Month} , :: Type{T} ) where {T <: Dates.Period } = false
66
-
67
- isless (:: Type{Year} , :: Type{T} ) where {T <: Dates.Period } = false
68
-
69
42
"""
70
43
next_datetime_transition(fmt::DateFormat)
71
44
@@ -76,30 +49,37 @@ function next_datetime_transition(fmt::DateFormat)
76
49
extract_token (x:: Dates.DatePart{T} ) where {T} = T
77
50
token_timescales = Dict (
78
51
# Milliseconds is the smallest timescale
79
- ' s' => Millisecond,
52
+ ' s' => Millisecond ( 1 ) ,
80
53
# Seconds
81
- ' S' => Second,
54
+ ' S' => Second ( 1 ) ,
82
55
# Minutes
83
- ' M' => Minute,
56
+ ' M' => Minute ( 1 ) ,
84
57
# Hours
85
- ' I' => Hour,
86
- ' H' => Hour,
58
+ ' I' => Hour ( 1 ) ,
59
+ ' H' => Hour ( 1 ) ,
87
60
# Days
88
- ' d' => Day,
89
- ' e' => Day,
90
- ' E' => Day,
61
+ ' d' => Day ( 1 ) ,
62
+ ' e' => Day ( 1 ) ,
63
+ ' E' => Day ( 1 ) ,
91
64
# Month
92
- ' m' => Month,
93
- ' u' => Month,
94
- ' U' => Month,
65
+ ' m' => Month ( 1 ) ,
66
+ ' u' => Month ( 1 ) ,
67
+ ' U' => Month ( 1 ) ,
95
68
# Year
96
- ' y' => Year,
97
- ' Y' => Year,
69
+ ' y' => Year ( 1 ) ,
70
+ ' Y' => Year ( 1 ) ,
98
71
)
99
72
73
+ # Dates for some reason explicitly does not define equality between the smaller
74
+ # timescales (Second, Minute, Day, etc..) and the larger, non-constant timescales
75
+ # (Month, Year). We do so explicitly here, without committing type piracy:
76
+ custom_isless (x, y) = isless (x, y)
77
+ custom_isless (x:: Union{Millisecond,Second,Minute,Hour,Day} , y:: Union{Month, Year} ) = true
78
+ custom_isless (x:: Union{Month, Year} , y:: Union{Millisecond,Second,Minute,Hour,Day} ) = false
79
+
100
80
tokens = filter (t -> isa (t, Dates. DatePart), collect (fmt. tokens))
101
- minimum_timescale = minimum ( map (t -> token_timescales[extract_token (t)], tokens))
102
- return Dates . ceil (now (), minimum_timescale) - Second (1 )
81
+ minimum_timescale = first ( sort ( map (t -> token_timescales[extract_token (t)], tokens), lt = custom_isless ))
82
+ return ceil (now (), minimum_timescale) - Second (1 )
103
83
end
104
84
105
85
calc_logpath (dir, filename_pattern) = joinpath (dir, Dates. format (now (), filename_pattern))
0 commit comments