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

Setting relativeTimeThresholdOptions object doesn't work #231

Open
Cthulahoop opened this issue Jan 29, 2020 · 3 comments · May be fixed by #247
Open

Setting relativeTimeThresholdOptions object doesn't work #231

Cthulahoop opened this issue Jan 29, 2020 · 3 comments · May be fixed by #247

Comments

@Cthulahoop
Copy link

Description of the Issue and Steps to Reproduce:

Did you search for duplicate issue? [Yes / no]

Please describe the issue and steps to reproduce, preferably with a code sample / plunker:

Adding the relativeTimeThresholdOptions object to the imports as shown in the Usage section of the readme doesn't change the moment relative time thresholds.

Demo

Please see StackBlitz demo here

Notes

  • The relativeTimeThresholdOptions object is set in app.module.ts and should set the ss threshold to 1 (so that seconds start showing nearly right away).
  • Checking the ss threshold value returns 44, which is the default (s == 45, ss == s - 1).
  • You can see the desired behavior by editing app.component.ts, uncommenting line 16.
    • Note that StackBlitz won't automatically reload moment if you comment line 16 out again, so reload the preview pane to be sure you see the changes.

The workaround is to set moment.relativeTimeThreshold manually, but this is kludgy.

Ensure your issue is isolated to ngx-moment. Issues involving third party tools will be closed unless submitted by the tool's author/maintainer.

Environment:

Please answer the following questions:

  • Angular version?
    ^8.0.0 & higher
  • TypeScript version?
    ~3.1.1
  • moment version?
    ^2.24.0
  • Are you using moment-timezone?
    no
  • Are you using the angular-cli?
    yes
  • Using Rollup/Webpack/System.js/Ionic/similar?
    n/a
@StickNitro
Copy link

The relativeTimeThresholdOptions do not actually get set on the moment object, they are set and used (currently) in the amDuration pipe, so they will not get set on the moment object until the amDuration pipe gets called.

If you add a call in your template to the amDuration pipe then you will see that moment.relativeTimeThreshold('ss') will return the correct value

@darron1217
Copy link

That's weird.
relativeTimeThresholdOptions should also be applied to amTimeAgo pipe.

@libinvarghese
Copy link

When using moment.from or moment.fromNow moment uses the Relative Time Thresholds

See example

libinvarghese added a commit to libinvarghese/ngx-moment that referenced this issue Mar 1, 2021
@libinvarghese libinvarghese linked a pull request Mar 1, 2021 that will close this issue
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.

4 participants