DateObject with DateFormat displays incorrectly in Dataset

Bug in 10.4.1 still in 11.0

DateObjects with DateFormat option appear to have the first date part truncated when displayed in a Dataset.

Outside of a Dataset the DateFormat displays as expected.

DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}]


However, in a Dataset it shows as with the "Year" truncated.

Dataset[
{DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}], 1, 2}]]


In fact, it truncates the first 4 characters of the formatted string.

Bug? Or am I doing something wrong?

10.4.1 Win 7 Ent SP1.

WRI confirmed bug. CASE:3625692

The result we see is due to a somewhat baffling formatting decision made within the machinery that generates the box form of datasets. When formatting a date object, it uses DateString form. However, it also expressly checks to see whether the date has three components. If so, it drops the first four characters from the string form. This is strange and I am tempted to call it a bug. It wouldn't hurt to report it to Wolfram.

Here is a direct exhibition of the problem:

DatasetMakeAtomBox[
TypeSystemAtom[DateObject]
, DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}]
]

(*
InterpretationBox[TagBox[TooltipBox[StyleBox["-01-20", ...], ...]
*)


Analysis (valid for version 10.4.1)

The problematic definition can be seen like this:

Block[{DatasetRichBox = HoldForm}
, DatasetMakeAtomBox[
TypeSystemAtom[DateObject]
, DateObject[{2007, 1, 20}, DateFormat -> {"Year", "-", "Month", "-", "Day"}]
]
]

(*
HoldForm[
DateObject[{2007, 1, 20}, DateFormat -> ...]
, If[Length[First[DateObject[{2007, 1, 20}, DateFormat -> ...]]] == 3
, StringDrop[#1, 4] &
, Identity][DateString[DateObject[{2007, 1, 20}, ...]]
]
]
*)


or by looking for the DateObject definition in the output of:

Dataset;
Needs["GeneralUtilities"]
PrintDefinitions[DatasetFormattingAtomicPackagePrivateabox]


Work-around

A quick fix, which will void your warranty, is to replace the problematic definition:

DatasetFormattingAtomicPackagePrivateabox[DateObject, x_DateObject] :=
DatasetRichBox[x, DateString[x]]


Giving:

Dataset[

• Adding four spaces to the front ( DateFormat ->{" ", "Year", "-", "Month", "-", "Day"}` ) is a less scary proposition. – Edmund Jun 7 '16 at 15:54