Skip to content

Commit f3df7f5

Browse files
committed
format: add explicit return statements.
1 parent 5318948 commit f3df7f5

1 file changed

Lines changed: 18 additions & 17 deletions

File tree

src/UnixTimes.jl

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ struct UnixTime <: Dates.AbstractDateTime
1212
end
1313

1414
function 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)
2526
end
2627

2728
const UNIX_EPOCH = UnixTime(Dates.UTInstant(Nanosecond(0)))
@@ -41,12 +42,12 @@ Base.:-(x::UnixTime, p::Period) = x + (-p)
4142

4243
function 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)
4546
end
4647

4748
function 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))
5051
end
5152

5253
Dates.Date(x::UnixTime) = Date(DateTime(x))
@@ -95,7 +96,7 @@ end
9596

9697
function 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)))
99100
end
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
114115
end
115116

116117
function 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))
118119
end
119120

120121
Dates.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
136137
else
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
141142
end
142143

0 commit comments

Comments
 (0)