npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-datefns-pipes-all-locales

v1.0.0

Published

Angular pipes based on date-fns. Date pipe, time-ago pipe, minDate pipe, maxDate pipe, distanceBetweenDates pipe. Supports all date-fns locales.

Downloads

63

Readme

ng-datefns-pipes-all-locales

Angular pipes based on date-fns. Date pipe, time-ago pipe, minDate pipe, maxDate pipe, distanceBetweenDates pipe. I initially built these for Ionic projects, because the Angular date pipe was not performing well on all mobile devices, and the date-fns functions were not exhibiting problems. However, no use of Ionic is required. This npm library should work with any Angular 5 project, and any Ionic 3 project. All date-fns locales are supported.

Installation

npm install ng-datefns-pipes-all-locales --save

Sample usage (Examples in English)

Date pipe:

napoleon = new Date(1804, 11, 2);                           // in ts file
Napoleon crowned himself emperor on {{ napoleon | date }}.  // in template
Napoleon crowned himself emperor on December 2nd, 1804.     // output

Time ago pipe:

aquinas = new Date(1274, 2, 7);          // in ts file
Aquinas died {{ aquinas | ago }}.<br>    // in template
Aquinas died almost 744 years ago.       // output

Time ago pipe second example:

now = new Date();                              // in ts file
You entered this page {{ now | ago }}.         // in template
You entered this page less than 5 seconds ago. // output (updates every 15 seconds)

Distance between dates:

datePair = [ this.aquinas, this.napoleon ];                                                // in ts file
Aquinas's and Napoleon's actions were separated by {{ datePair | distanceBetweenDates }}.  // in template
Aquinas's and Napoleon's actions were separated by almost 531 years.                       // output

Min date:

dateArray = [ this.aquinas, this.napoleon, this.now ];    // in ts file
The earliest of those dates is {{ dateArray | minDate }}. // in template
The earliest of those dates is March 7th, 1274.           // output 

Max date:

The most recent of those dates is {{ dateArray | maxDate }}. // in template (ts file same as before)
The most recent of those dates is ___.    // <-- output, blank contains today's date

Basic setup

In app.module.ts:

import { DatePipesModule } from 'ng-datefns-pipes';

@NgModule({
  declarations: [],
  imports: [
    DatePipesModule.forRoot() // < -- add this line
  ],
  bootstrap: [],
  entryComponents: [],
  providers: []
})
export class AppModule {}

This gives you access to all the (English language) date pipes, with the default configuration.

Advanced Setup

You can specify a default date format; whether date distance functions include seconds; and the prefix, suffix, refresh rate and use of seconds of the timeAgo pipe. (For more detail about these settings, see the API below. You can also set and reset each setting during the program by injecting the DatePipeManager.) You can aso set as default any locale supported by date-fns. (There are over 30.)

In app.module.ts:

import { DatePipesModule, DatePipeConfiguration, Locale } from 'ng-datefns-pipes';

const DATE_PIPE_CONFIG: DatePipeConfiguration = {
   defaultDateFormat: 'your date format string',    // default: 'MMMM Do, YYYY'
   dateDistanceIncludesSeconds: your boolean here,  // default: false
   agoPipeOptions: {
     refreshRate: your milliseconds here,           // default: 15000
     prefix: 'your prefix string',                  // default: ''
     suffix: 'your suffix string',                  // default: ' ago' <-- note the space
     includeSeconds: your boolean here              // default: false
   }
}

const DEFAULT_LOCALE: Locale = Locale.FRENCH        // <-- substitute for any other supported locale, e.g., Locale.THAI
                                                    //     Locale is an enum

@NgModule({
  declarations: [],
  imports: [
    DatePipesModule.forRoot(DATE_PIPE_CONFIG, DEFAULT_LOCALE) // < -- add this line
  ],
  bootstrap: [],
  entryComponents: [],
  providers: []
})
export class AppModule {}