EEL Date.format() doesnt work properly

Hey there,

today I tried to use the EEL Date.format() function to convert a DateTime object to a readable string.
This causes the output “01.01.1970” for every value I try to convert. I checked everything but the syntax doesn’t seem wrong to me.


...
deadline = Neos.Fusion:Tag {
  tagName = 'p'
  content = ${Date.format(q(this.item).property('deadline'), 'd.m.Y')}
  attributes.class = 'announcement-deadline'
}
...

Is it possible that this function simply doesn’t work or is it my fault? I don’t really get the problem…

Thanks in advance, Max

EDIT: Found out it even causes this output when nothing is put in (like ‘null’)

Hi,

looks like this.item is not defined, thus q(this.item).property('deadline') evaluates to null.

Are you rendering this inside a Neos.Fusion:Collection with itemName = 'item'?

In this case, it should work, if you change your FlowQuery to: q(item).property('deadline').

Greetings,
Wilhelm

this.item is defined, I just trimmed off the rest of the Fusion file to simplify it for here.
The problem consists even if I put in a static value, therefore I’m a bit confused why it happens.
But I can say for sure that It’s not an error with variables or their values.

What exactly do you mean by static value? Did you try a unix timestamp or Date.now() instead of q(this.item).property('deadline')?

BTW: Just to be sure: this.item is only defined if it is set within the Neos.Fusion:Tag in this scenario. Are you sure it’s defined in the right place? This gets easily confused, that’s why I’m asking :slight_smile:

Greetings,
Wilhelm

Meanwhile the code changed a bit but still with same results.
I’ll add the whole file below to make everything clear (i hope).

With static I meant other DateTime Objects, not declared by variable. I haven’t tried Date.now() to be honest because I gave up after some time and changed it to
content = ${Date.dayOfMonth(q(item).property('deadline'))+'.'+Date.month(q(item).property('deadline'))+'.'+Date.year(q(item).property('deadline'))}
which actually works fine but then why the .format() not?

(And by the way thanks for the fast replies :slight_smile: )

AnnouncementItem.fusion

prototype(Gummersbach.MainWebsite:AnnouncementsList) < prototype(Neos.Fusion:Collection){
  collection = ${q(documentNode).children("[instanceof Gummersbach.MainWebsite:Announcement]")}
  itemName = 'announcement'
  itemRenderer = Neos.Fusion:Template {
    templatePath = 'resource://Gummersbach.MainWebsite/Private/Templates/NodeTypes/AnnouncementItem.html'
    @context.item = ${announcement}

    object = Neos.Fusion:Tag {
      tagName = 'h4'
      content = ${q(item).property('object')}
      attributes.class = 'announcement-title'
    }

    number = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${q(item).property('number')}
    }

    numberLabel = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${Translation.translate('Gummersbach.MainWebsite:NodeTypes.Announcement:properties.number')}
    }

    execution = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${q(item).property('execution')}
    }

    executionLabel = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${Translation.translate('Gummersbach.MainWebsite:NodeTypes.Announcement:properties.execution')}
    }

    deadline = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${Date.format(q(item).property('deadline'), 'd.m.Y')}
    }

    deadlineLabel = Neos.Fusion:Tag {
      tagName = 'span'
      content = ${Translation.translate('Gummersbach.MainWebsite:NodeTypes.Announcement:properties.deadline')}
    }

    deadlineYear = Neos.Fusion:Tag {
      tagName = 'p'
      content = ${Date.year(q(item).property('deadline'))}
    }

    moreLink = Gummersbach.MainWebsite.PostList.MoreLink {
      content = 'Details'
      attributes.href = NodeUri {
        node = ${item}
      }
    }

    @ignoreProperties = ${['item']}
  }
}

Hi @mschmidt, it seems that you’re right, that Date.format() doesn’t work like expected.

If you pass in a timestamp like
${Date.format(Date.now().timestamp, 'd.m.Y')}
then it works fine. But if you pass in a string it doesn’t work. In this case it seems that in the format-Method of the DateHelper-Class the string is not processed properly.

...} else {
            $timestamp = (integer)$date;
            return date($format, $timestamp);
        }
...

In the else-case the conversion of the given string to an integer doesn’t seem to result in a proper timestamp.

That’s just what I can see. But I’m rather new to Neos so I’m out at this point.

1 Like

As mentioned in my previous reply I’ve changed it to the three EEL functions for day, month and year therefore I’ll leave it like this to keep it working.
But I hope this will be reviewed sometime.
Thanks to @wbehncke and @Martelinho for your participation in my problem

Hi Maximilian, fyi.
I just read the thread “Welcome to the Neos Community” (Welcome to the Neos Community). There is one maybe important detail:

[…]For a maximum level of happiness, we ask you to…file bug reports to Github (Flow issues / Neos issues) […]

Sounds that yourself can trigger the review you’re hoping for.

Hi @mschmidt just wanted to ask if you made a bug report? Couldn’t find something about it on the given github pages. I think on give-and-take basis it would be fair to help improving the system. If you don’t write a report just let me know. Then I would do this by citing your posts.

Oh yes totally forgot about it while working around. I’ll report it today thanks for reminding me.

:+1: Was no real reminder or hectic. Just wanted to make sure that anybody reports it since it’s the best for all.

Hi @mschmidt, just looked for a bug report and couldn’t find one. But as I never did one on github and even don’t have an account for it it also might be that I just can’t find it.Is this problem already reported or maybe even solved?

I didn’t check if there’s a bug report, but it’s definitely not fixed in current master (see eel/Classes/Helper/DateHelper.php at 8.3 · neos/eel · GitHub)

Then now is the best chance to change this :wink:

In the meantime you should be able to work around this like follows:

...
deadline = Neos.Fusion:Tag {
  tagName = 'p'
  content = ${Date.format(Date.parse(q(this.item).property('deadline'), '<format>'), 'd.m.Y')}
  attributes.class = 'announcement-deadline'
}
...

Where you have to replace <format>with the format string of the deadline property (or pass null if you want PHP to try to determine the right format for you)

Just looked at my business and private todos and must say no, now is definitely not the best chance.:wink:
But of course the right time will come.

@mschmidt told he will report it:

As described I’m not used to the reporting processes and tools and therefore can not be sure that it is not already reported. So first an answer of Maximilan would make the situation and todos clearer.

OK, but do your business and private todos allow you to tell us whether the suggested work-around does the trick for you? :slight_smile:

Hi Bastian, sorry, right at the moment I have to do very urgent tax purposes. So a quick answer is ok but no time left for more. In addition as you can read above I didn’t have that problem. I just read this post and at that moment invested some time to analyze the core problem. Afterwards I just wanted to make sure that the problem and the infos will be reported to the community as a pay back. I already offered to do the report but Maximilian said to do so. If noone does I will do that as soon as I have the time fpr that which is not now, sorry. But maybe it’s already done, I don’t know. Maximilian can tell that without big effort.

Ah, nevermind, I just confused the two of you, sorry :wink:
Let’s see what @mschmidt has to say.

Good luck with your tax!

1 Like