@@ -12,16 +12,17 @@ struct UnixTime <: Dates.AbstractDateTime
1212end
1313
1414function UnixTime (
15- y:: Integer ,
16- m:: Integer = 1 ,
17- d:: Integer = 1 ,
18- h:: Integer = 0 ,
19- mi:: Integer = 0 ,
20- s:: Integer = 0 ,
21- ms:: Integer = 0 ,
22- us:: Integer = 0 ,
23- ns:: Integer = 0 )
24- convert (UnixTime, DateTime (y, m, d, h, mi, s, ms)) + Nanosecond (us * 1000 + ns)
15+ y:: Integer ,
16+ m:: Integer = 1 ,
17+ d:: Integer = 1 ,
18+ h:: Integer = 0 ,
19+ mi:: Integer = 0 ,
20+ s:: Integer = 0 ,
21+ ms:: Integer = 0 ,
22+ us:: Integer = 0 ,
23+ ns:: Integer = 0
24+ )
25+ return convert (UnixTime, DateTime (y, m, d, h, mi, s, ms)) + Nanosecond (us * 1000 + ns)
2526end
2627
2728const UNIX_EPOCH = UnixTime (Dates. UTInstant (Nanosecond (0 )))
@@ -41,12 +42,12 @@ Base.:-(x::UnixTime, p::Period) = x + (-p)
4142
4243function Base.:+ (x:: UnixTime , p:: Union{Month, Year} )
4344 trunc_ns = mod (Dates. value (x), 1_000_000 )
44- convert (UnixTime, convert (DateTime, x) + p) + Nanosecond (trunc_ns)
45+ return convert (UnixTime, convert (DateTime, x) + p) + Nanosecond (trunc_ns)
4546end
4647
4748function Dates. DateTime (x:: UnixTime )
4849 instant_ms = Dates. UNIXEPOCH + div (x. instant. periods. value, 1_000_000 )
49- DateTime (Dates. UTM (instant_ms))
50+ return DateTime (Dates. UTM (instant_ms))
5051end
5152
5253Dates. Date (x:: UnixTime ) = Date (DateTime (x))
9596
9697function Base. convert (:: Type{UnixTime} , x:: DateTime )
9798 instant_ns = (Dates. value (x) - Dates. UNIXEPOCH) * 1_000_000
98- UnixTime (Dates. UTInstant (Nanosecond (instant_ns)))
99+ return UnixTime (Dates. UTInstant (Nanosecond (instant_ns)))
99100end
100101
101102# Promotion rules for comparing UnixTime with DateTime
@@ -110,11 +111,11 @@ function Base.show(io::IO, x::UnixTime)
110111 print (io, div (v, d) % 10 + ' 0' )
111112 d = div (d, 10 )
112113 end
113- nothing
114+ return nothing
114115end
115116
116117function Base. floor (x:: UnixTime , p:: Union{DatePeriod, TimePeriod} )
117- convert (UnixTime, floor (convert (DateTime, x), p))
118+ return convert (UnixTime, floor (convert (DateTime, x), p))
118119end
119120
120121Dates. guess (a:: UnixTime , b:: UnixTime , c) = (Dates. value (b) - Dates. value (a)) ÷ Dates. tons (c)
@@ -131,12 +132,12 @@ if Sys.islinux()
131132 ts = Ref {LinuxTimespec} ()
132133 ccall (:clock_gettime , Cint, (Cint, Ref{LinuxTimespec}), 0 , ts)
133134 x = ts[]
134- UnixTime (Dates. UTInstant (Nanosecond (x. seconds * 1_000_000_000 + x. nanoseconds)))
135+ return UnixTime (Dates. UTInstant (Nanosecond (x. seconds * 1_000_000_000 + x. nanoseconds)))
135136 end
136137else
137138 @inline function unix_now ()
138139 tv = Libc. TimeVal ()
139- UnixTime (Dates. UTInstant (Nanosecond (tv. sec * 1_000_000_000 + tv. usec * 1_000 )))
140+ return UnixTime (Dates. UTInstant (Nanosecond (tv. sec * 1_000_000_000 + tv. usec * 1_000 )))
140141 end
141142end
142143
0 commit comments