Skip to content

Commit

Permalink
Fix print of DataValue times and dates
Browse files Browse the repository at this point in the history
  • Loading branch information
davidanthoff committed Jul 15, 2023
1 parent 5266bf6 commit df286d0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/TableShowUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ function printHTMLtable(io, source; force_unknown_rows=false)
print(io, "<tr>")
for c in values(r)
print(io, "<td>")
if c isa Dates.AbstractTime
if c isa Dates.AbstractTime
Markdown.htmlesc(io, sprint(io->print(IOContext(io, :compact => true),c)))
elseif c isa DataValues.DataValue && DataValues.hasvalue(c) && c[] isa Dates.AbstractDateTime
Markdown.htmlesc(io, sprint(io->print(IOContext(io, :compact => true),c[])))
else
Markdown.htmlesc(io, sprint(io->show(IOContext(io, :compact => true),c)))
end
Expand Down
7 changes: 6 additions & 1 deletion test/test_tableshowutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,15 @@
end

@testitem "DateTime" begin
using Dates
using Dates, DataValues

source = [(a=1,b=DateTime(2010, 5, 6)),(a=2,b=DateTime(2011, 5, 6))]

@test sprint(TableShowUtils.printHTMLtable, source) == """
<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2010-05-06T00:00:00</td></tr><tr><td>2</td><td>2011-05-06T00:00:00</td></tr></tbody></table>"""

source2 = [(a=1,b=DataValue(DateTime(2010, 5, 6))),(a=2,b=NA)]

@test sprint(TableShowUtils.printHTMLtable, source2) == """
<table><thead><tr><th>a</th><th>b</th></tr></thead><tbody><tr><td>1</td><td>2010-05-06T00:00:00</td></tr><tr><td>2</td><td>#NA</td></tr></tbody></table>"""
end

0 comments on commit df286d0

Please sign in to comment.