DateObject
s can be of varying physical dimensions.
CurrentDate[Today, #] & /@ {"Day", "Month", "Year"}
How do you get the size of a DateObject
? I tried AbsoluteOptions[Today]
but it returns unevaluated. Ideas?
Answer
Here's a way to do it entirely in the FE (i.e. without a full Rasterize
call, which is done in the FE anyway):
getBoxSize[c_Cell] :=
{#[[1]], Total@#[[2 ;;]]} &@First@
FrontEndExecute@GetBoundingBoxSizePacket[c];
getBoxSize[e_] := getBoxSize[Cell[BoxData@ToBoxes[e]]]
getBoxSize@CurrentDate[#] & /@ {"Day", "Month", "Year"}
{{148., 25.}, {121., 25.}, {90., 25.}}
Note that this is much faster than using a raw Rasterize
:
getBoxSize@CurrentDate[#] & /@ {"Day", "Month",
"Year"} // RepeatedTiming
{0.04, {{151., 25.}, {121., 25.}, {90., 25.}}}
Rasterize[CurrentDate[#], "RasterSize"] & /@ {"Day", "Month",
"Year"} // RepeatedTiming
{0.24, {{151, 26}, {121, 26}, {90, 26}}}
Comments
Post a Comment