Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » $Expires.InPast is not working.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 2063 Views
  • Jane Novice
    Avatar
    Community Member
    4 Posts

    $Expires.InPast is not working. Link to this post

    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?

  • RS26
    Avatar
    Community Member
    11 Posts

    Re: $Expires.InPast is not working. Link to this post

    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.

  • Jane Novice
    Avatar
    Community Member
    4 Posts

    Re: $Expires.InPast is not working. Link to this post

    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!

  • Darkoran
    Avatar
    Community Member
    1 Post

    Re: $Expires.InPast is not working. Link to this post

    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 %>

  • MartinPhone
    Avatar
    Community Member
    51 Posts

    Re: $Expires.InPast is not working. Link to this post

    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?

  • MartinPhone
    Avatar
    Community Member
    51 Posts

    Re: $Expires.InPast is not working. Link to this post

    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.

    2063 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.