Page Blocks

Hosting sponsored by:

Point In Space

 

API: Date

Filename:
fwpDate_relative.ctag

Released With:
5.0.0

Current Version:
1.1.0

Status: Active

Min Lasso Tested: 8.1.0

Max Lasso Tested: 8.5.3

Related:

Still don't get it?

Check out the talk list archives, or join and ask your questions.

Documentation Error or Request?

Email documentation corrections or comments

API Reference

fwpDate_relative (Tag)

Description

Shows a date in relative format if possible (Yesterday, Today, or Tomorrow), or defaults to a specified alternate format. Allows the relative string to be specified as an alternate to the defaults.

Syntax

fwpDate_relative: 
   date,
   -todayStr|-tomorrowStr=|-yesterdayStr=string,
   -usSlash2|-usSlash4|-euroSlash2|-euroSlash4|-mmShort4|-mmLong4
   -default=Lasso dateFormat string,
   -timeformat=Lasso timeFormat string;

Parameters & Member Tags

date (unnamed) = any valid Lasso date or datetime string

-todayStr = a literal string to display if the date is today (defaults to Today)

-yesterdayStr = a literal string to display if the date is yesterday (defaults to Yesterday)

-tomorrowStr = a literal string to display if the date is tomorrow (defaults to Tomorrow)

-default = a lasso date format string to format the date in when it is not arelative date. Use -default or one of the predefined formats in the list below.

-usSlash2|-usSlash4|-euroSlash2|-euroSlash4|-mmShort4|-mmLong4 = a predefined format defined by the fwpDate_ tags of the same name. A value is not required when using these parameters.

-timeformat = if unspecified then no time is shown with the date, if a Lasso time format is defined such as '%h:%M:%S' then the time is shown is that format

Examples

See the demos page for additional examples to these below.

[fwpDate_relative: ($myDate),-mmLong4]

[fwpDate_relative: ($myDate),-euroSlash4]

[fwpDate_relative: ($myDate),-todayStr='Brand New Post!',-mmShort2]

[fwpDate_relative: ($myDate),
   -yesterdayStr='Old Hat!',
   -tomorrowStr='Coming Soon', 
   -todayStr='Just Arrived', 
   -mmLong4]

Source Code

View in separate window

<?lassoscript
//............................................................................
//
//    pageblocks: (c) 2002-2007 http://www.pageblocks.org/
//
//............................................................................
/*

    {fileName=        fwpDate_relative.ctag }
    {rsrcType=        tag }
    {rsrcName=        fwpDate_relative }
    {rsrcHTTP=        http://www.pageblocks.org/refc/fwpDate_relative }

    {lassoVrsnMin=    8.1.0 }
    {lassoVrsnMax=    8.5.3 }

    {author=        Greg Willits, Chris Corwin, Doug Burchard, Bil Corry }
    {authorEmail=    subscribe to pbTalk at www.pageblocks.org/talk/ }
    {authorHTTP=    www.pageblocks.org }

    {desc=            Returns a date in a variety of formats including
                    relative names like Today, Yesterday, Tomorrow
                    and uses the other fwpDate format tags as options }

    {maintvsrn=        1.0 }
    {maintrelease=    5.0.0 }
    {maintdate=        2006-01-16 }
    {maintauthor=    Greg Willits }
    {maintnotes=    initial release }

*/
//.............................................................................

define_tag: 'fwpDate_relative', 
    -priority = 'replace', 
    -required = 'date';

    local: 
        'fw_thisDate'     = (date: #date),
        'fw_resultDate'    = (string),
        'fw_timeformat'    = (string);

    // set the formats to display.

    if: (params->find:'-timeformat')->size == 0;
        #fw_timeformat = '';
    else;
        #fw_timeformat = ' ' + #fw_timeformat;
    /if;
    if: (params->find:'-tomorrowStr')->size == 0;
        local: 'tomorrowStr' = 'Tomorrow';
    /if;
    if: (params->find:'-todayStr')->size == 0;
        local: 'todayStr' = 'Today';
    /if;
    if: (params->find:'-yesterdayStr')->size == 0;
        local: 'yesterdayStr' = 'Yesterday';
    /if;
    if: (params->find:'-default')->size == 0;
        local: 'default' = '%b %d, %Y';
    /if;

    // calculate the difference (in days) between today and the passed date
    local:'dayOrigin' = date;
    #dayOrigin->(SetFormat:'%D');
    local: 'difference' = 
        (date_difference: (string: #dayOrigin + ' 12:00:00'), '1/1/1970 12:00:00', -day) - 
        (date_difference: (string: #fw_thisDate + ' 12:00:00'), '1/1/1970 12:00:00', -day);

    var:'fw_relDateDifference' = #difference;


    // calculate which format to return.
    if: #difference == 0;
        #fw_resultDate = #fw_thisDate -> (format: #todayStr + #fw_timeformat);
    else: #difference == (-1);
        #fw_resultDate = #fw_thisDate -> (format: #tomorrowStr + #fw_timeformat);
    else: #difference == 1;
        #fw_resultDate = #fw_thisDate -> (format: #yesterdayStr + #fw_timeformat);
    else;
        if: (params->find:'-mmShort')->size > 0;
            #fw_resultDate = fwpDate_mmShort: string:#fw_thisDate;
        else: (params->find:'-mmShort4')->size > 0;
            #fw_resultDate = fwpDate_mmShort4: string:#fw_thisDate;
        else: (params->find:'-mmLong4')->size > 0;
            #fw_resultDate = fwpDate_mmLong4: string:#fw_thisDate;
        else: (params->find:'-usSlash2')->size > 0;
            #fw_resultDate = fwpDate_usSlash2: string:#fw_thisDate;
        else: (params->find:'-usSlash4')->size > 0;
            #fw_resultDate = fwpDate_usSlash4: string:#fw_thisDate;
        else: (params->find:'-euroSlash2')->size > 0;
            #fw_resultDate = fwpDate_euroSlash2: string:#fw_thisDate;
        else: (params->find:'-euroSlash4')->size > 0;
            #fw_resultDate = fwpDate_euroSlash4: string:#fw_thisDate;
        else;
            #fw_resultDate = #fw_thisDate -> (format: #default  + #fw_timeformat);
        /if;
    /if;

    return: @#fw_resultDate;

/define_tag;

?>


© 2002-2012, pageblocks.org