Adding stronger support for dates as built ins for "?today and ?yesterday

Ken Egervari <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Hi, I have a feature request.

Today, I wrote a macro for formatting the date to be fairly pretty to look
at. It separates the date and time into different styles, and if the date is
today or yesterday, it says the actual word rather than the date. This is
all very common type of stuff we do these days:

<#macro formatDate date showTime=true>
    <#if date??>
        <span class="Date">
            <#if date?date?string.short == today?date?string.short>
                Today
            <#elseif date?date?string.short == yesterday?date?string.short>
                Yesterday
            <#else>
                ${date?date}
            </#if>
        </span>
        <#if showTime>
            <span class="Time">${date?time}</span>
        </#if>
    </#if>
</#macro>

The only problem with this implementation is that "today" and "yesterday"
need to be in the model. This is kind of a hassle to put these 2 objects in
the model in every spot where they are used. Sure, they could be added in a
base class controller and added to every page... but that's also kind of a
waste too.

It would be nice if freemarker added ?today and ?yesterday to return
true/false when you use them with dates.

Another issue was that I needed to use ?date?string.short 4 times in the
above code because ?date didn't properly return true when they were both
equal. They returned false :(

I think people would use these built-ins if you provided them, and they
would really clean up the model.

Thanks for listening.

Ken

------------------------------------------------------------------------------
What happens now with your Lotus Notes apps - do you make another costly 
upgrade, or settle for being marooned without product support? Time to move
off Lotus Notes and onto the cloud with Force.com, apps are easier to build,
use, and manage than apps on traditional platforms. Sign up for the Lotus 
Notes Migration Kit to learn more. http://p.sf.net/sfu/salesforce-d2d

_______________________________________________
FreeMarker-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freemarker-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.