Strange behavior DateInterval in PHP [X-post r/PHP]
stackoverflow.com/q/26258550/250259Posted Oct 8, 2014, 3:27 PM UTC
Posted Oct 8, 2014, 3:27 PM UTC
I spent five hours fucking around with dateinterval on Friday. I eventually gave up, and this explains it.
Yeah, PHP sucks at date/time problems; yes, I know it has the "awesome" try-to-read-any-formatting... but that's a whole can of worms in itself.
In Ada, time can be pretty easy to handle:
Use all type Ada.Calendar.Time; -- Makes operators visible.
Function Is_In( Query, Start, Stop : Ada.Calendar.Time ) return Boolean is
( Start <= Query and Query <= Stop );
Function Is_In( Query, Start : Ada.Calendar.Time; Stop : Duration ) return Boolean is
( Is_In( Query => Query, Start => Start, Stop => Start+Stop) );
What the fuck.
...However, using > to compare two objects in a language without operator overloading seems like a bad idea.
At first I thought maybe the object was implicitly being cast to a string, and the strings compared, but trying to cast a dateinterval to a string results in Object of class DateInterval could not be converted to string. So it's not string comparison. What exactly happens when you use an inequality comparison operator on two objects in PHP?
This is interesting: http://3v4l.org/jLSDU
Hm. I guess the object returned by createFromDateString is lazily evaluated in some way?
Even if the object is lazy, you have to force it before you can compare it. Otherwise you're just comparing thunks, and that doesn't make any sense.
to compare two objects in a language without operator overloading
PHP does have operator overloading for internal classes (i.e. those written in C). It's just not exposed to userland.
Wat.
I can't even.
I've lost my ability to can.
It's like Schrodinger cat - measurement is changing the outcome.
I was thinking of the double slit experiment, but r/php seems to disagree
lol
Have you tried odd?