adopted-ember-addons / ember-moment

MIT License
399 stars 122 forks source link

Odd & inconsistent behaviour from moment-format and is-after helpers #246

Open jdurand opened 7 years ago

jdurand commented 7 years ago

I have something like this in a template:

{{#each things as |thing|}}
  {{d3-graph
    (pipe
      (d3-text (moment-format thing.dateTime 'H:mm'))
      (d3-attr 'class'
        (if
          (is-after now thing.dateTime)
          'late'
          'not-late'
        )
      )
    )
  tagName='text'}}
{{/each}}

The inconsistent

The is-after helper logs the an empty value (null, undefined, or "") was passed to moment-format warning while the moment-format helper renders without any warning. Everything works as expected; the time is rendered with the late class (if now is after dateTime)... but with an ugly console warning :-(.

The odd

In the same conditions, if I set allow-empty=true on the is-after helper, the text is rendered with the not-late class (instead of late).

It seems like the comparison helper fails with allow-empty=true and looking at https://github.com/stefanpenner/ember-moment/blob/master/addon/utils/helper-compute.js I don't really understand why allowEmpty is taken into account in a comparison helper.

Tested with v7.3.1 on ember v2.14.1 & v2.13.4

jasonmit commented 7 years ago

Thanks for reporting, I will look into this to see what can be done to improve consistency.