react-moment moment component with duration props outputs 0 days, 0 weeks etc

Viewed 112

I have a Moment component with two props: duration and date.

<Moment duration={props.createdAt} date={props.dueDate}  />

props.createdAt and props.dueDate are from MongoDB and they are of type Date.

For example, it outputs 0 weeks, 5 days, 0 hours but it also outputs 3 days sometimes without 0s. How can I get rid of 0s? Shouldn't it get rid of 0s by default?

I have read the GitHub page but I couldn't find anything.

1 Answers

You can apply additional attribute to Moment element called "trim", this will remove the 0s from the output.

<Moment duration={props.createdAt} date={props.dueDate}  trim />

The attribute can be a boolean or string, you can find more details about the usage in the official documentation: https://github.com/jsmreese/moment-duration-format#trim

Related