Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

DateFormat function inserts space in front !

Participant ,
Jan 28, 2011 Jan 28, 2011

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.

944
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jan 28, 2011 Jan 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

Translate
Guide ,
Jan 28, 2011 Jan 28, 2011

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

Very annoying.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2011 Jan 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2011 Jan 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2011 Jan 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 28, 2011 Jan 28, 2011
LATEST

Thanks for the clarification, I must of misread that part in some old documentation as it now clearly states the behaviour as you mention.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources