AndrewPoyntz / time-ago-pipe

An Angular pipe for converting a date string into a time ago
MIT License
130 stars 67 forks source link

added type support for passing date as a number #28

Open eranation opened 5 years ago

eranation commented 5 years ago

This fix is needed for IDEs to not complain about type mismatch, e.g. in cases such as

{{ item.modifiedDate | timeAgo }}

in case modified date is a number.

It works in practice because Date has a constructor that accepts number (milliseconds time stamp), but some IDEAs will complain about the pipe accepting only strings where the attribute is a number.

note: the ? condition seems redundant, but needed for typescript type guard to work. otherwise (at least in TS 2.7.2) it doesn't know to pick the right Date constructor based on the type of value