Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

$Expires.InPast is not working.


Reply


6 Posts   2206 Views

Avatar
Jane Novice

Community Member, 4 Posts

26 April 2009 at 9:51am

Edited: 26/04/2009 7:26pm

I'm new to Silverstripe and realy start to like it!. But I think there is a bug.
The Expires.InPast seems to be not working correctly. It makes no sense to me! Can someone help me?

Please, take a look at this code and the output:

Code:
-------

      <% if Expires.InPast %>
             <h3>THE DATE HAS EXPIRED!</h3>
                <p><i>Today is $Now.</i></p>
                <p>Expiringdate is $Expires.</p>
                <p>Expiringdate has expired $Expires.Ago.</p>
      <% else %>
             <h3>Not yet Expired</h3>
                <p>Expiringdate will be $Expires.</p>
      <% end_if %>


output:
-------

THE DATE HAS EXPIRED!

Today is 2009-04-25.

Expiringdate is 2009-05-20.

Expiringdate has expired 24 days away.

-------
I'm using SilverStripe-v2.3.1.
What is wrong?

Avatar
RS26

Community Member, 11 Posts

13 May 2009 at 2:02am

is this line...

<% if Expires.InPast %>

missing a dollar sign for the variable?

<% if $Expires.InPast %>

I am also having issues with the InPast function in 2.2.1 ... I get a missing { php error, and can't seem to track it down.

Avatar
Jane Novice

Community Member, 4 Posts

17 May 2009 at 9:56am

Hi RS26,
The $ sign should not be there. You get an error if it is there.
But even if you do not put it ther, it will not work properly, I think.

Regards!

Avatar
Darkoran

Community Member, 1 Post

19 May 2009 at 5:17am

Edited: 19/05/2009 5:19am

What I by now figured out was, that the problem possibly lies in the rendering of the template.
Everything works fine and the Funktion returns the right value. in that case false or 0

I tried to put out something like

+Date.InPast+ in the .ss File and the output is ++
so the return value must be 0

but the following expression turns true

<% if Date.InPast %>

Avatar
MartinPhone

Community Member, 57 Posts

21 November 2012 at 6:48am

Edited: 21/11/2012 6:48am

I realise this is old and may be fixed in SS3 but I'm adding something to a 2.4.5 site that I can't really be bothered to convert to SS3... :)

What are we meant to do, just use <% if Date.InFuture %><% else %>? That seems a bit silly. It works, granted, but surely there must be a neater way?

Avatar
MartinPhone

Community Member, 57 Posts

27 November 2012 at 12:10pm

Edited: 27/11/2012 12:13pm

FWIW inFuture didn't actually work either so went with stealing and modifying the simple function suggested here: http://www.silverstripe.org/data-model-questions/show/9491 so that I always got back something True, as null obviously wasn't False enough.