4
$\begingroup$

I am on version 12.3.1 (MS Windows) and I want to get the date bounds of a date interval of a few months (let's say October and November), but the max bound is wrong. I tried

DateBounds[DateInterval[{{{2021, 10}, {2021, 11}}}]]

but it gives me enter image description here. I want exact bounds with granularity of seconds, so I tried

DateBounds[DateInterval[{{{2021, 10}, {2021, 11}}}], "Second"]

but it gives me: enter image description here. This is obviously wrong, because it does not include November. I expect to get: enter image description here.

Mathematica clearly understands that November is included in the DateInterval, because both IntervalMemberQ and TimelinePlot work fine:

TimelinePlot[DateInterval[{{{2021, 10}, {2021, 11}}}]]

enter image description here

IntervalMemberQ[DateInterval[{{{2021, 10}, {2021, 11}}}], DateObject[{2021, 11, 15, 0, 0, 0}]]

enter image description here

How can I get the full date range with granularity of seconds?

This is a workaround I came up with so far, but I do not like it much:

MinMax[Map[DateInterval[#, "Second"] &, DateBounds[DateInterval[{{{2021, 10}, {2021, 11}}}]]]]
$\endgroup$

2 Answers 2

-1
$\begingroup$

From the help of "DateObject": "DateObject automatically chooses the first date compatible with the input information:". Therefore e.g.:

DateObject[{2020}, Second]

Compatible with this behavior is "DateInterval". E.g.:

DateInterval[{{{2020}, {2021}}}, "Second"]

enter image description here

And therefore also "DateBounds":

DateBounds[DateInterval[{{2020}, {2021}}, "Second"], "Second"]

enter image description here

This fits with "gives the earliest and latest of the Subscript[date, i]" from the help of "DataBounds"

$\endgroup$
3
  • $\begingroup$ As you can see, I never used the notation like DateInterval[{{2020}, {2021}}, "Second"]. Your last example is therefore already wrong before you call DateBounds on it. Documentation on DateBounds says DateBounds[interval,gran] gives the endpoints of interval in the specified granularity gran. First of November is clearly not the endpoint of my example interval. It is actually the midpoint. $\endgroup$
    – Jan Hubik
    Commented Dec 13, 2021 at 20:35
  • $\begingroup$ The usage is consistent with all other commands! $\endgroup$ Commented Dec 14, 2021 at 8:56
  • $\begingroup$ It is not consistent at least with TimelinePlot and IntervalMemberQ, which both use the interval bounds. $\endgroup$
    – Jan Hubik
    Commented Dec 14, 2021 at 9:57
-2
$\begingroup$

Try

DateBounds[DateInterval[{{{2021, 10}, {2021, 11}}}], "Second"]
(*{DateObject[{2021, 10, 1, 0, 0, 0}, "Second", "Gregorian", 1.], DateObject[{2021, 11, 1, 0, 0, 0.99999}, "Second", "Gregorian", 1.]}*)
$\endgroup$
1
  • $\begingroup$ As you can see, I already tried that and the result is wrong in both your example as well as mine. $\endgroup$
    – Jan Hubik
    Commented Dec 13, 2021 at 20:29

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.