Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mrblur opened this issue Apr 15, 2019 · 0 comments
Open

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

mrblur opened this issue Apr 15, 2019 · 0 comments

Comments

@mrblur
Copy link

mrblur commented Apr 15, 2019

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

content = datetime.format(format);
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?
(

content = moment().diff(datetime);

content = moment.duration(content);

)

I am working with locale different than 'en'.

Niels-Be added a commit to Niels-Be/react-moment that referenced this issue Jun 24, 2019
This correctly applies format after the duration was calculated.
Previously format would always be applied first and the duration parsing would not work since it expects a number.

Fixes: headzoo#92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant