joanllenas / ngx-date-fns

⏳ date-fns pipes for Angular
163 stars 14 forks source link

FR: dfnsFormatRelativeToNow #363

Closed joeveiga closed 2 years ago

joeveiga commented 2 years ago

Description of the Issue and Steps to Reproduce:

Hello 👋 ! I'd like to propose the addition of a new dfnsFormatRelativeToNow pipe which assumes new Date() as the second argument. Alternatively you could modify dfnsFormatRelative pipe to behave that way here, but I understand perhaps you want to keep that pipe consistent with the original behavior in date-fns (although having a default wouldn't be a breaking change, IMO).

Motivation

For my usecase(s), and probably others as well, the most common scenario in which I use that pipe is I want to see the date relative to "now". The required pipe argument becomes an issue because then in every component I need to have a field to expose the current date, like so:

@Component({
  template: '<div>{{ someDate | dfnsFormatRelative: now }}</div>'
})
export class MyComponent {
  get now(): Date {
    return new Date();
  }
  // ...
}

I'd much rather not have to create my own pipe just to add that default argument 😄 . Thanks!

joanllenas commented 2 years ago

Hi @joeveiga , I like the idea of `dfnsFormatRelativeToNow, and I'm pretty sure other users will benefit from this. I will be releasing a new version with the new pipe in the coming days. Cheers!

joeveiga commented 2 years ago

@joanllenas Thank you! 🙏

joanllenas commented 2 years ago

@joeveiga this is ready! https://github.com/joanllenas/ngx-date-fns/releases/tag/v8.2.0 Cheers!

joanllenas commented 2 years ago

Closing