Message Boards Message Boards

0
|
4647 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Test DateIntervals[ ] starting in the InfinitePast?

Posted 3 years ago

I have a DateInterval object that might begin in the InfinitePast and I want to test to see if this is the case. When you construct such a DateInterval it will have it's granularity updated to match the smallest granularity of the other end point. So for example DateInterval[{InfinitePast,Today}]["Min"] will give a DateObject with a year of -Infinity but it will also have day and month fields and a Day level granularity.

I first tried using DateOverlapsQ but that didn't work.

I also tried extracting the Year value to test to see if it's -Infinity but it seems to give an error (it used to work in 12.1, now under 12.2 it seems like it tests to see that the Year is an integer.)

I also tried to manually change the granularity of infinite past to match the interval granularity, but it seems like this doesn't work as, for example, DateObject[InfinitePast,"Day"] just keeps the same granularity of Eternity. This suggests that the granularity change on InfinitePast in the Min of the DateInterval is perhaps a bug? Maybe it should just return the regular InifnitePast DateObject, and then I could easily test it using regular equality.

3 Replies
Posted 3 years ago

Ah, I misunderstood the question. How about

infinitePastQ[interval_DateInterval] := Not@FreeQ[interval, -Infinity]

infinitePastQ@DateInterval[{InfinitePast, Today}]
(* True *)

infinitePastQ@DateInterval[{InfinitePast, DateObject[{2021}]}]
(* True *)

infinitePastQ@DateInterval[{Today, InfiniteFuture}]
(* False *)

infinitePastQ@DateInterval[{InfinitePast, InfiniteFuture}]
(* True *)
POSTED BY: Rohit Namjoshi
Posted 3 years ago

Hi Nicholas,

Try MinDate

d = DateInterval[{InfinitePast, Today}]
min = MinDate[d, "Year"]

InputForm@min
(* DateObject[{-Infinity}, "Year", "Gregorian", -6.] *)
POSTED BY: Rohit Namjoshi

MinDate gives the same results as DateInterval["Min"], but what is the way to do the comparison? For example:

MinDate[DateInterval[{InfinitePast,Today}]]==InfinitePast

returns unevaluated. I would like to be able to test an arbitrary DateInterval to see if it starts in the InfinitePast

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract