Hello,
I wanted to use the dfnsDistanceInWords pipe to convert a number in a duration string (an absolute number, ie. a time interval but not a date per se).
For that, I usually cheat with distanceInWords function by passing a "zero" date for comparison, so I have two "absolute" referentials.
Ex: dateFns.distanceInWords(0, myDuration) would return something like "less than a minute".
Refactoring some code to use the pipes, I noticed that ngx-date-fns does not allow to pass "0" dates:
ERROR Error: dfnsDistanceInWords: missing required arguments
at DistanceInWordsPipe.transform (ngx-date-fns.js:76) [angular]
The reason is that ngx-date-fns checks the input and does not allow any flasey value :
Hello, I wanted to use the
dfnsDistanceInWords
pipe to convert a number in a duration string (an absolute number, ie. a time interval but not a date per se). For that, I usually cheat withdistanceInWords
function by passing a "zero" date for comparison, so I have two "absolute" referentials.Ex:
dateFns.distanceInWords(0, myDuration)
would return something like "less than a minute".Refactoring some code to use the pipes, I noticed that ngx-date-fns does not allow to pass "0" dates:
The reason is that ngx-date-fns checks the input and does not allow any flasey value :
https://github.com/joanllenas/ngx-date-fns/blob/master/projects/ngx-date-fns/src/lib/distance-in-words.pipe.ts#L43
Instead of:
We should have :
Loosy comparison with undefined works here, 0 would be allowed but not undefined or null, which would be expected.
Obviously, there are other pipes concerned. For now, I'll use
1
instead of0
:)