Skip to main content
Inspiring
January 28, 2011
Answered

DateFormat function inserts space in front !

  • January 28, 2011
  • 2 replies
  • 1075 views

Hi to all,

I recently started a brand new project in CF9.0.1 (hotfix 1 in place).

In one of my main components I have a function as per the following :

________________________________________

    <cffunction name="DateFormatBE"

                     access="public"

                     returntype="string"

                     description="Formats a given string to Belgian date format, returns a blanco when no date is given">
        <cfargument name="myDate"

                           type="string"

                          required="false"

                          default=""

                          hint="the string to date format">
       <cfscript>
            if (Len(Trim(ARGUMENTS.myDate))) {
                if (! IsDate(ARGUMENTS.myDate)) {
                    ARGUMENTS.myDate = ParseDateBE(ARGUMENTS.myDate);
                    if (! Len(Trim(ARGUMENTS.myDate)))
                        return "";
                }
                return Trim(LSDateFormat(ARGUMENTS.myDate,"DD/MM/YYYY"));
            } else
                return "";
        </cfscript>
    </cffunction>

    <cffunction name="ParseDateBE"

                    returntype="any"

                    access="public"

                    output="false"

                    hint="Parses a given string to a date object (dd/mm/yyyy).">
        <cfargument name="myDate"

                            required="No"

                            type="string"

                            default=""

                            hint="the string to parse of format (dd/mm/yyyy)">
        <cfscript>
            if (ListLen(ARGUMENTS.myDate,"/") == 3) // expects two slashes
                return CreateDate(ListGetAt(ARGUMENTS.myDate,3,"/"), ListGetAt(ARGUMENTS.myDate,2,"/"),ListGetAt(ARGUMENTS.myDate,1,"/"));
            else
                return "";
        </cfscript>
    </cffunction>

________________________________________

As of version 9.0.1 I always receive an extra space in front if I output a date as following :

     <cfoutput>

          <input type="Text"

                    name="SomeName"

                    value="#DateFormatBE(Now())#" >

     </cfoutput>

However, this does seem to work as expected :

     <cfdump var="#DateFormatBE(Now())#">

Is this a known bug or am I missing something?

Thanks for reading!

Bert.

    This topic has been closed for replies.
    Correct answer Adam Cameron.

    Yes, you are missing something: OUTPUT="FALSE" on your <cffunction> signature for DateFormatBE().

    However this would not have been "since 9.0.1" it would have been "since 6.0" (ie: since the introduction of <cffunction>).

    --

    Adam

    2 replies

    Adam Cameron.Correct answer
    Inspiring
    January 28, 2011

    Yes, you are missing something: OUTPUT="FALSE" on your <cffunction> signature for DateFormatBE().

    However this would not have been "since 9.0.1" it would have been "since 6.0" (ie: since the introduction of <cffunction>).

    --

    Adam

    Inspiring
    January 28, 2011

    Super, it works as a charm now !

    I do have put output="false" in my component tag definition, but that seems to do just nothing...

    Anyway, thanks for your feedback !

    Cheers Bert.

    Inspiring
    January 28, 2011
    I do have put output="false" in my component tag definition, but that seems to do just nothing...

    When one instantiates a CFC, any code outside any <cffunction> within the CFC file is executed.  That could generate spurious whitespace if you don't have OUTPUT="FALSE" on the CFCOMPONENT tag.

    --

    Adam

    Owainnorth
    Inspiring
    January 28, 2011

    I actually get this a lot with various CF functions, never managed to sort it.

    Very annoying.