Bug introduced in 12.0 or earlier, completely fixed in 13.0.0

Update 2021-05-28

Granularity bug not fixed in 12.3.0

The originally reported tooltip bug has been fixed in 12.2.0, however, now in some cases, the granularity is completely ignored in the tooltip. e.g. using dates from @kglr's answer

enter image description here

Tooltip bug not fixed in 12.1.1.

The Part::partw: error has been fixed in 12.1.0. Tooltip bug has not.

Update 2019-11-28

WRI has confirmed that this is a bug.

Update 2019-11-25

The workaround suggested by @alx works if all of the dates have the same granularity. While experimenting with the workaround suggested by @kglr I ran into another issue.

  DateObject[{2019}, "Year"] -> "Foo",
  DateObject[{2019, 11}, "Month"] -> "Bar"

Generates the error

Part::partw: Part 2 of {{3.75529*10^9,2019,{0.01,0}}} does not exist.

Reported to WRI CASE:4360060

Original question

The tooltip shows "Day: 2019" even though the DateObject represents a Year. Is this a bug? How to show "Year: 2019" in the tooltip?

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"]

enter image description here

DateObject[{2019}, "Year"]

enter image description here


2 Answers 2


Update: For input data with mixed date granularity:

dates = {DateObject[{2019, 11}, "Month"] -> "Month", 
  DateObject[{2019}, "Year"] -> "Year", 
  DateObject[{2019, 5, 15}, "Week"] -> "Week", 
  DateObject[{2020, 10}, "Year"] -> "Year2", 
  DateObject[{2019, 10}, "Quarter"] -> "Quarter"}; 

TimelinePlot[Tooltip[#, #] -> #2 & @@@ Sort[dates]]

enter image description here

Original answer:

An alternative work-around is to wrap DateObjects with Tooltip:

TimelinePlot[Tooltip[#, #] & @ DateObject[{2019}, "Year"] -> "Foo"]

enter image description here

TimelinePlot[Tooltip[#, #]& @ DateObject[{2019, 11}, "Month"] -> "Foo"]

enter image description here


From InputForm[TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"]] one can see, that MMA uses Day as granularity for DateObjects. So, one possible solution is to change these objects to the needed form:

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo"] /. 
 DateObject[a__, "Day", b__] :> DateObject[a, "Year", b]

Another possibility is using custom LabelingFunction:

TimelinePlot[DateObject[{2019}, "Year"] -> "Foo", 
 LabelingFunction -> (DateObject[FromAbsoluteTime@First@#, "Year"] &)]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.