diff --git a/REQUIRE b/REQUIRE index 144f796..26c7447 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ DataFrames -Compat \ No newline at end of file +Compat +Requires \ No newline at end of file diff --git a/src/datetime.jl b/src/datetime.jl index c916906..37f4c5c 100644 --- a/src/datetime.jl +++ b/src/datetime.jl @@ -1,5 +1,7 @@ # Constructors for the julia Date, Time and DateTime types. +using Requires + import Base.== function MySQLTime(timestr) @@ -77,3 +79,11 @@ end function ==(a::MySQLDateTime, b::MySQLDateTime) a.date == b.date && a.time == b.time end + +@require Dates begin +using Dates +Base.convert(::Type{Date}, date::MySQLDate) = Date(date.year, date.month, date.day) +Base.convert(::Type{DateTime}, dtime::MySQLDateTime) = + DateTime(dtime.date.year, dtime.date.month, dtime.date.day, + dtime.time.hour, dtime.time.minute, dtime.time.second) +end diff --git a/src/results.jl b/src/results.jl index 672b90e..14f8988 100644 --- a/src/results.jl +++ b/src/results.jl @@ -53,7 +53,7 @@ function mysql_get_julia_type(mysqltype::MYSQL_TYPE) return Clong elseif (mysqltype == MYSQL_TYPE_TIMESTAMP) - return Cint + return MySQLDateTime elseif (mysqltype == MYSQL_TYPE_DATE) return MySQLDate