From 264a35eb85d6cdc974dff0d5700e544528bcfee6 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Tue, 21 Nov 2017 11:44:29 +0100 Subject: [PATCH] unde beautiful hack and reimplement unix2datetime in LibGit2 --- base/libgit2/signature.jl | 24 ++++++++++++++++++------ stdlib/Dates/src/Dates.jl | 2 -- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/base/libgit2/signature.jl b/base/libgit2/signature.jl index f7cc75213d3218..3804d81a23bd31 100644 --- a/base/libgit2/signature.jl +++ b/base/libgit2/signature.jl @@ -35,16 +35,28 @@ function Base.convert(::Type{GitSignature}, sig::Signature) return GitSignature(sig_ptr_ptr[]) end -# Work around needing to access Dates from Base, -# even though Dates is in the stdlib. -# This Ref is filled with the needed function -# when Dates is loaed -const unix2datetime = Ref{Any}() +function yearmonthday(days) + z = days + 306; h = 100z - 25; a = fld(h, 3652425); b = a - fld(a, 4) + y = fld(100b + h, 36525); c = b + z - 365y - fld(y, 4); m = div(5c + 456, 153) + d = c - div(153m - 457, 5); return m > 12 ? (y + 1, m - 12, d) : (y, m, d) +end +lpad0(x) = lpad(x, 2, '0') + +function unix2date(t) + UNIXEPOCH = 62135683200000 + rata = UNIXEPOCH + round(Int64, Int64(1000) * t) + year, month, day = yearmonthday(fld(rata, 86400000)) + secs = t % (24 * 60 * 60) + mins = div(secs, 60) + m, d = lpad0(month), lpad0(day) + h, mi, s = lpad0.(round.(Int, (div(mins, 60), mins % 60, secs % 60))) + return "$year-$m-$d $h:$mi:$s" +end function Base.show(io::IO, sig::Signature) print(io, "Name: ", sig.name, ", ") print(io, "Email: ", sig.email, ", ") - print(io, "Time: ", unix2datetime[](sig.time + 60*sig.time_offset)) + print(io, "Time: ", unix2date(sig.time + 60*sig.time_offset)) @printf(io, "%+03i:%02i", divrem(sig.time_offset, 60)...) end diff --git a/stdlib/Dates/src/Dates.jl b/stdlib/Dates/src/Dates.jl index f353e5fd4e3371..6001e4d60d28bd 100644 --- a/stdlib/Dates/src/Dates.jl +++ b/stdlib/Dates/src/Dates.jl @@ -50,8 +50,6 @@ include("io.jl") include("parse.jl") include("deprecated.jl") -Base.LibGit2.unix2datetime[] = unix2datetime - export Period, DatePeriod, TimePeriod, Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond,