react-moment icon indicating copy to clipboard operation
react-moment copied to clipboard

Cannot set settings for moment-duration-format / templating broken

Open mrblur opened this issue 6 years ago • 0 comments

Actually the statement in issue's title is not completely true, however, I cannot set template, or simple trim: false.

The code itself, allows providing settings object as the only argument to Duration's .format, however, react-moment tries to use that object to format datetime at https://github.com/headzoo/react-moment/blob/6f7ec60cf32a23c1f03d3337189327778dfb3a44/src/index.jsx#L313 which throws exception as it is not a String instance.

It could be worked around by setting fromNowDuring to anything, so it does not crash anymore, however, in the final result, I am getting "00"s as values in output string:

import Moment from "react-moment';

<Moment fromNowDuring durationFromNow date={ new Date("2019-12-24 12:00:00") } format={ { template: "dd [__] hh [__] mm [__] ss [__]", trim: false } }/>

will output: 00 days 00 hours 00 minutes 00 seconds

Putting that template into pure Duration.format() gives expected result. Is it possible that's due to use of plain "moment" vs configured Moment.globalMoment? ( https://github.com/headzoo/react-moment/blob/6f7ec60cf32a23c1f03d3337189327778dfb3a44/src/index.jsx#L329 https://github.com/headzoo/react-moment/blob/6f7ec60cf32a23c1f03d3337189327778dfb3a44/src/index.jsx#L335 )

I am working with locale different than 'en'.

mrblur avatar Apr 15 '19 12:04 mrblur