GithubHelp home page GithubHelp logo

ngx-date-fns's Introduction

+ = ngx-date-fns

Build Status codecov npm version npm downloads

date-fns pipes for Angular applications.

Table Of Contents

The latest version of this library requires:

  • date-fns >= v3.0.0.
  • Angular >= v17.0.0.
  • npm install --save date-fns
  • npm install --save ngx-date-fns

⚠️ There's a range of date-fns versions for which tree shaking is broken, so we recommend that you either install v2.16.1 or >= v2.21.1.

stackblitz example

import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import 'zone.js';
import { es } from 'date-fns/locale';
import { DateFnsModule } from 'ngx-date-fns';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, DateFnsModule],
  template: `
    <p>{{ dateOne | dfnsFormat: 'MM/dd/yyyy' }}</p>
    <p>{{ [dateOne, dateTwo] | dfnsMin | dfnsFormat: 'EEE LLLL d yyyy' }}</p>
    <p>
      {{ [dateOne, dateTwo] | dfnsMax | dfnsFormat: 'EEE LLLL d yyyy' }}
    </p>
    <p>
      {{ dateThree | dfnsFormatDistanceToNow: options }} - (Explicit 'es'
      locale)
    </p>
    <p>{{ 0 | dfnsWeekdayName: 'full':options }} - (Explicit 'es' locale)</p>
    <p>
      {{
        '12 de Marzo'
          | dfnsParse: parseFormat:parseDate:parseLocale
          | dfnsFormat: 'MM/dd/yyyy'
      }}
    </p>
  `
})
export class App {
  dateOne = new Date(2016, 0, 1);
  dateTwo = new Date(2017, 0, 1);
  dateThree: Date;
  options = {
    locale: es,
    addSuffix: true
  };
  parseDate = new Date(2010, 0, 1);
  parseFormat = `do 'de' MMMM`;
  parseLocale = { locale: es };

  constructor() {
    this.dateThree = new Date();
    this.dateThree.setDate(this.dateThree.getDate() - 6);
  }
}

bootstrapApplication(App);

The output:

01/01/2016
Fri January 1 2016
Sun January 1 2017
hace 6 días - (Explicit 'es' locale)
lunes - (Explicit 'es' locale)
03/12/2010

All locale-aware pipes use English by default.

Instead of passing the locale to each pipe via options you can set it globally in one single step by overriding the default DateFnsConfiguration implementation:

stackblitz example

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { DateFnsConfigurationService } from 'ngx-date-fns';
import { fr } from 'date-fns/locale';

const frenchConfig = new DateFnsConfigurationService();
frenchConfig.setLocale(fr);

export const appConfig: ApplicationConfig = {
  providers: [{ provide: DateFnsConfigurationService, useValue: frenchConfig }]
};
// main.ts
import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import 'zone.js';
import { es } from 'date-fns/locale';
import { DateFnsModule } from 'ngx-date-fns';
import { appConfig } from './app.config';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, DateFnsModule],
  template: `
    (...)
  `
})
export class App {
  // (...)
}

bootstrapApplication(App, appConfig).catch(err => console.error(err));

It is also possible to change the default locale at runtime:

stackblitz example

import { CommonModule } from '@angular/common';
import { Component } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
import 'zone.js';
import { es, de } from 'date-fns/locale';
import { DateFnsConfigurationService, DateFnsModule } from 'ngx-date-fns';

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [CommonModule, DateFnsModule],
  template: `
    <p>{{ dateOne | dfnsFormat: 'EEE LLLL d yyyy' }}</p>
    <hr />
    Set default locale to: <a href="#" (click)="changeToGerman()">German</a>,
    <a href="#" (click)="changeToSpanish()">Spanish</a>.
  `
})
export class App {
  dateOne = new Date(2016, 0, 1);
  constructor(public config: DateFnsConfigurationService) {}
  changeToGerman() {
    this.config.setLocale(de);
  }
  changeToSpanish() {
    this.config.setLocale(es);
  }
}

bootstrapApplication(App);

Should I use the pure or impure version of the locale-aware pipes?

The answer is quite simple:

  • Do you set the locale only once when the application starts?
    • Use only pure pipes.
  • Do you need to change the locale at runtime?
    • Use impure pipes.

The main difference is that pure pipes do not get notified when the locale is changed via DateFnsConfiguration.setLocale(locale: Locale), because the instance is not kept in memory. Impure pipes, on the other hand, are kept in memory and listen for Locale change notifications, which adds some memory and performance overhead.

All pipes are pure unless stated otherwise.

Since v7.0.0 invalid Dates will return an empty string instead of throwing an exception.

A collection of utilities built around date-fns functions.

dfnsFormatRelativeToNow

This pipe is (impure), but there's the pure version dfnsFormatRelativeToNowPure too.

Same as dfnsFormatRelative but the date to comapre against is always Date.now().

dfnsWeekdayName

This pipe is (impure)

Given a weekday number, returns its name.

@param WeekdayNameFormat

Optional weekday format. Allowed values are:

  • x1: One char. 'M' for Monday.
  • x2: Two chars. 'Mo' for Monday.
  • x3: Three chars. 'Mon' for Monday.
  • full: Full weekday name. 'Monday' for Monday.

Defaults to full.

@param Locale

Optional date-fns Locale object.

Optional locale object.

Basic example

<div>
  <!-- Prints Monday -->
  {{ 0 | dfnsWeekdayName }}
</div>
<div>
  <!-- Prints Mon -->
  {{ 0 | dfnsWeekdayName : 'x3' }}
</div>

ngx-date-fns's People

Contributors

chrisjohns-me avatar greenkeeper[bot] avatar joanllenas avatar joarkm1 avatar jorgeucano avatar kingdarboja avatar layzeedk avatar rafaelss95 avatar toverux avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ngx-date-fns's Issues

An in-range update of @types/node is breaking the build 🚨

Version 8.5.6 of @types/node was just published.

Branch Build failing 🚨
Dependency @types/node
Current Version 8.5.5
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of @angular/platform-browser-dynamic is breaking the build 🚨

Version 4.3.3 of @angular/platform-browser-dynamic just got published.

Branch Build failing 🚨
Dependency @angular/platform-browser-dynamic
Current Version 4.3.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/platform-browser-dynamic is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

is*() functions are missing

Description of the Issue and Steps to Reproduce:

Did you search for duplicate issue? Yes

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

Some pipes are missing, which are available in date-fns.

  • isThisWeek()
  • isYesterday()
  • isThisMonth()

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

Environment:

Browser.

Please answer the following questions:

  • Angular version? 12
  • TypeScript version? 4.3.5
  • date-fns version? 2.25.0

An in-range update of css-loader is breaking the build 🚨

Version 0.28.8 of css-loader was just published.

Branch Build failing 🚨
Dependency css-loader
Current Version 0.28.7
Type dependency

This version is covered by your current version range and after updating it in your project the build failed.

css-loader is a direct dependency of this project, and it is very likely causing it to break. If other packages depend on yours, this update is probably also breaking those in turn.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes v0.28.8

2018-01-05

Bug Fixes

  • loader: correctly check if source map is undefined (#641) (0dccfa9)
  • proper URL escaping and wrapping (url()) (#627) (8897d44)
Commits

The new version differs by 10 commits.

  • 0fc46c7 chore(release): 0.28.8
  • 333a2ce chore(package): update dependencies
  • 39773aa ci(travis): use npm
  • 8897d44 fix: proper URL escaping and wrapping (url()) (#627)
  • 0dccfa9 fix(loader): correctly check if source map is undefined (#641)
  • d999f4a docs: Update importLoaders documentation (#646)
  • 05c36db test: removed redundant modules argument (#599)
  • c45fa66 test: add case for url processing (#603)
  • 7039740 docs(README): add anchor tags to options table (#609)
  • 0840c80 Fix markdown for link to webpack resolve.alias doc (#595)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of mocha is breaking the build 🚨

Version 3.5.0 of mocha just got published.

Branch Build failing 🚨
Dependency mocha
Current Version 3.4.2
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As mocha is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Release Notes free-as-in-freezing

3.5.0 / 2017-07-31

📰 News

  • Mocha now has a code of conduct (thanks @kungapal!).
  • Old issues and PRs are now being marked "stale" by Probot's "Stale" plugin. If an issue is marked as such, and you would like to see it remain open, simply add a new comment to the ticket or PR.
  • WARNING: Support for non-ES5-compliant environments will be dropped starting with version 4.0.0 of Mocha!

🔒 Security Fixes

🎉 Enhancements

  • #2696: Add --forbid-only and --forbid-pending flags. Use these in CI or hooks to ensure tests aren't accidentally being skipped! (@charlierudolph)
  • #2813: Support Node.js 8's --napi-modules flag (@jupp0r)

🔩 Other

Commits

The new version differs by 34 commits.

  • 82d879f Release v3.5.0
  • bf687ce update mocha.js for v3.5.0
  • ec73c9a update date for release of v3.5.0 in CHANGELOG [ci skip]
  • 1ba2cfc update CHANGELOG.md for v3.5.0 [ci skip]
  • 065e14e remove custom install script from travis (no longer needed)
  • 4e87046 update karma-sauce-launcher URL for npm@5
  • 6886ccc increase timeout for slow-grepping test
  • 2408d90 Make dependencies use older version of readable-stream to work around incompatibilities introduced by 2.3.0 on June 19th
  • 68a1466 Try not clearing the env for debug in the integration test and see if that fixes Node 0.10 on AppVeyor; if need be, some other fix/workaround can be applied to handle whatever was up with debug without causing this issue
  • 958fbb4 Update new tests to work in browser per test hierarchy reorganization
  • 1df7c94 Merge pull request #2704 from seppevs/increase_test_coverage_of_mocha_js
  • 1f270cd Stop timing out (#2889)
  • 27c7496 upgrade to [email protected]; closes #2859 (#2860)
  • 50fc47d fix CI; closes #2867 (#2868)
  • 1b1377c Add test for ignoreLeaks and fix descriptions

There are 34 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Get weekday name pipe

Please check my suggestion for pipe <div>{{0 | dfnsWeekdayName:weekdayName.short}}</div>

import locale from 'date-fns/esm/locale/ru';

enum WeekdayName {
  full = 'full',
  short = 'short'
}

function getWeekdayName(day: number, view: WeekdayName = WeekdayName.full) {
  const now = new Date();
  const week = eachDayOfInterval({
    start: startOfWeek(now, {locale: locale}),
    end: endOfWeek(now, {locale: locale})
  });
  return format(week[day], view === WeekdayName.short 
    ? 'EEEEEE' : 'EEEE', {locale: locale});
}

console.log(getWeekdayName(0, WeekdayName.short)); // пн
console.log(getWeekdayName(1)); // вторник

The pipe will be useful to create calendars as we should write weekdays names based on current locale.

date-fns 3.x support

Description of the Issue and Steps to Reproduce:

Hi

I tried to upgrade my project dependencies and switched from date-fns 2.30.0 to 3.0.6.
However I received a lot of errors after that:

Type 'typeof import("/node_modules/date-fns/closestTo")' provides no match for the signature '(...args: any): any'. [plugin angular-compiler]

[ERROR] TS2304: Cannot find name 'Duration'. [plugin angular-compiler]

   node_modules/ngx-date-fns/lib/format-duration.pipe.d.ts:11:24:
     11 │     transform(duration: Duration, options?: {
 [ERROR] TS2304: Cannot find name 'Locale'. [plugin angular-compiler]

    node_modules/ngx-date-fns/lib/is-match.pipe.d.ts:12:17:
      12 │         locale?: Locale;

Environment:

Please answer the following questions:

  • Angular version? 17.0.8
  • TypeScript version? 5.2.2
  • date-fns version? 3.0.6

Allow to import pipe selectively

Description of the Issue and Steps to Reproduce:

Looks like the current implementation always imports all the pipe, making the final bundle excessively large:

image

It would be better to be able to import pipes in a more selective way, in order not to increase the final app size including unused code.

Environment:

Please answer the following questions:

  • Angular version? 7.1.0
  • TypeScript version? 3.1.6
  • ng-xdate-fns version? 2.0.3

Angular 16 support

Angular 16 support ?

Please answer the following questions:

Angular version? 16.x
TypeScript version? 5.x

What is the amLocal equivalent of ngx-moment?

I am trying to migrate ngx-moment to ngx-date-fns since momentjs is no longer maintained. Only I understand that it is not quite possible to do the same thing. In my case all dates are stored in UTC in the database. The "format" of the dates returned by the backend is in ISO (C# ASP Core).
So to date I was doing this for example with ngx-moment:

{{ myDate | amFromUtc | amLocal | amDateFormat:'LL' }}

I understand that the equivalent of amFromUTC is dfnsParseIso in ngx-date-fns

But what about amLocal how to do it? I see that you should use date-fns-tz but ngx-date-fns doesn't offer a pipe to use it. So I created something like that, but it doesn't work, the date displayed is still not according to the user's timezone.

import { Pipe, PipeTransform } from '@angular/core';

import { zonedTimeToUtc, utcToZonedTime, format } from 'date-fns-tz';

@Pipe({ name: 'utcToZonedTime' })
export class UtcToZonedTimePipe implements PipeTransform {
  transform(
    dateString: string
  ): string {
    const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
    return utcToZonedTime(dateString, timezone);
  }
}

Have you got an idea? Why not integrate the pipe to use date-fns-tz?
Thanks

Improve documentation

To improve documentation:

  • Organize pipes by type (add, sub, difference, etc.).
  • Add a usage example for each pipe type.

Create pure versions of impure pipes

Create a pure version of all impure pipes:

  • dfnsFormat
  • dfnsFormatDistance
  • dfnsFormatDistanceStrict
  • dfnsFormatDistanceToNow
  • dfnsGetWeek
  • dfnsGetWeekOfMonth
  • dfnsGetWeeksInMonth
  • dfnsGetWeekYear
  • dfnsStartOfWeek
  • dfnsStartOfWeekYear
  • dfnsLastDayOfWeek
  • dfnsParse

FR: dfnsFormatRelativeToNow

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!

An in-range update of @types/node is breaking the build 🚨

Version 8.0.56 of @types/node was just published.

Branch Build failing 🚨
Dependency @types/node
Current Version 8.0.55
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

IsEqual Pipe

Description of the Issue and Steps to Reproduce:

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

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

Hi it looks like dfnsIsEqual pipe is not working properly. Or maybe I'm doing something wrong.
Here you can find dfnsIsEqual (results: false) together with isEqual function (results: true)
https://stackblitz.com/edit/ngx-date-fns-is-equal?file=src/app/hello.component.ts

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

Environment:

Please answer the following questions:

  • Angular version? 11.2.3
  • TypeScript version? Stackblitz
  • date-fns version? 7.0.2

Angular 13 : "Encourage the library authors to publish an Ivy distribution"

During the build of a project, angular-cli 13 issues the following message :

⠙ Generating browser application bundles (phase: setup)...Processing legacy "View Engine" libraries:
- ngx-date-fns [es2015/esm2015] (git+https://github.com/joanllenas/ngx-date-fns.git)
Encourage the library authors to publish an Ivy distribution.

Except this message ngx-date-fns works fine. But it seems something has to be done in the ngx-date-fns library.

Auto-detect language

I want to auto-detect the formatting based on user language. I find myself writing a configuration factory like:

import {de, enGB, enUS, fr, it} from 'date-fns/locale';

const dateLocaleFactory = () => {
  const lang = navigator.language;
  if (lang.startsWith('en')) {
    if (lang === 'en-GB') {
      return enGB;
    } else {
      return enUS;
    }
  } else if (lang.startsWith('de')) {
    return de;
  } else if (lang.startsWith('it')) {
    return it;
  } else if (lang.startsWith('fr')) {
    return fr;
  } else { // default
    return enUS;
  }
};
const dateConfigFactory = () => {
  const c = new DateFnsConfigurationService();
  c.setLocale(dateLocaleFactory());
  return c;
};

I wonder if there is a helper function or better way of implementing all available languages? I know date-fns is written in a way to not import all locale but it would be great to have a function which would ease the process of auto-detecting the language. Are there some ideas or better ways to solve it instead of a giant if else?

Configure locale in module

Hi @joanllenas as we discussed in #309

I offer to configure locale in module directly DateFnsModule.forRoot({locale: ru}).

The main advantage of this is all pipes could be pure and that will be good for performance.

import ru from 'date-fns/locale';
@NgModule({
  imports: [
    DateFnsModule.forRoot({locale: ru})
  ]

The disadvantage is that we will not be able to change locale dynamically.

Or we will need to reload the page, e.g.

import ru, de from 'date-fns/locale';

let locale;
const code = localStorage.locale || 'ru';
switch(code) {
  case 'de':
    locale = de;
  break;
  default:
     locale = ru;   
}

@NgModule({
  imports: [
    DateFnsModule.forRoot({locale: locale})
  ]

What do you think? Thanks a lot!

An in-range update of @types/node is breaking the build 🚨

Version 8.0.53 of @types/node was just published.

Branch Build failing 🚨
Dependency @types/node
Current Version 8.0.52
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of awesome-typescript-loader is breaking the build 🚨

Version 3.2.2 of awesome-typescript-loader just got published.

Branch Build failing 🚨
Dependency awesome-typescript-loader
Current Version 3.2.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As awesome-typescript-loader is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Commits

The new version differs by 2 commits.

  • 5304203 chore(release): 3.2.2
  • 9473d2c fix(dependencies): upgrading node dependencies (#472)

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Support `strictTemplates` / All pipes should accept null and undefined

With Angular strict mode all inputs need to be optional:

export class myComponent implements OnInit {
  @Input() myDate?: number;
}

Or using the async pipe returns null:

<app-my-compontent [myDate]="myDate$ | async"></app-my-component>

But then the compiler is throwing an error with ngx-date-fns pipes, e.g.:

Type 'undefined' is not assignable to type 'DateFnsInputDate'.
{{ myDate | dfnsFormat: 'dd.MM.yyyy'}}

I would suggest to add strict typechecking to tsconfig:

"angularCompilerOptions": {
    "strictInjectionParameters": true,
    "strictInputAccessModifiers": true,
    "strictTemplates": true,
    "preserveSymlinks": true
  }

and add a questionmark to all pipe inputs to support undefined and also accept null, e.g. the format pipe:

transform(
    date?: DateFnsInputDate | null,
    ...
  ): string {
    if (!date || isInvalidDate(date)) {
      return '';
    }
    ...
  }
}

An in-range update of typescript is breaking the build 🚨

Version 2.4.1 of typescript just got published.

Branch Build failing 🚨
Dependency typescript
Current Version 2.4.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As typescript is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build failed Details

Commits

The new version differs by 141 commits.

  • 8b2fe13 Update LKG.
  • 14d95ed Test:Block-scoped definition of Promise works
  • a8846bf Skip block scope check with no error location
  • 44f2336 Merge pull request #16633 from Microsoft/release-2.4_fixIncrementalParsing
  • 4875a27 Add tests
  • 15ef20d Set the structureReused to be safemoudles when dynamic import change
  • 6d33083 Add tests
  • 11b9f6e Wip-fix incremental parsing
  • 2721fd4 In TypeScript code, never bind JSDoc normally, just set parent pointers (#16555) (#16561)
  • 0968ed9 Revert string enum changes (#16569)
  • 096f8cc Update LKG
  • 9241175 Allow running in strict mode (#16557)
  • f49b007 Update LKG
  • f1b0f59 Update version to 2.4.1
  • ed9cde9 Update LKG

There are 141 commits in total.

See the full diff

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Documentation about tree shaking is not correct

The documentation says:

The library itself is optimized to be tree-shakable by just importing DateFnsModule.forRoot()

I did this and checked with ng build --stats-json and then using webpack-bundle-analyzer to see full 512kb ngx-date-fns is imported:

Bildschirmfoto 2021-03-09 um 12 59 55

But when I import just the specific pipe it works and ngx-date-fns is not even visible.

Dont try to reproduce with something newer than 2.16.1 since newer versions do not support tree shaking in the first place: date-fns/date-fns#2207

An in-range update of @angular/compiler is breaking the build 🚨

Version 4.4.2 of @angular/compiler just got published.

Branch Build failing 🚨
Dependency @angular/compiler
Current Version 4.4.1
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Update to date-fns 2.0.0

Update the library to use date-fns 2.0.0.
Currently, using it with date-fns 2.0.0, it gives multiple warnings of functions not being found, ex.:

WARNING in ./node_modules/ngx-date-fns/esm5/ngx-date-fns.es5.js 1090:15-26
"export 'addISOYears' was not found in 'date-fns'

Documentation for lazy loaded modules

When having lazy loaded modules:

- AppModule
    - LazyModule1
    - LazyModule2

Should AppModule import with forRoot() and all others without? Or should all 3 import with forRoot?

Maybe would be nice if you could add this information to the docs, too :)

Version 10 of node.js has been released

Version 10 of Node.js (code name Dubnium) has been released! 🎊

To see what happens to your code in Node.js 10, Greenkeeper has created a branch with the following changes:

  • Added the new Node.js version to your .travis.yml

If you’re interested in upgrading this repo to Node.js 10, you can open a PR with these changes. Please note that this issue is just intended as a friendly reminder and the PR as a possible starting point for getting your code running on Node.js 10.

More information on this issue

Greenkeeper has checked the engines key in any package.json file, the .nvmrc file, and the .travis.yml file, if present.

  • engines was only updated if it defined a single version, not a range.
  • .nvmrc was updated to Node.js 10
  • .travis.yml was only changed if there was a root-level node_js that didn’t already include Node.js 10, such as node or lts/*. In this case, the new version was appended to the list. We didn’t touch job or matrix configurations because these tend to be quite specific and complex, and it’s difficult to infer what the intentions were.

For many simpler .travis.yml configurations, this PR should suffice as-is, but depending on what you’re doing it may require additional work or may not be applicable at all. We’re also aware that you may have good reasons to not update to Node.js 10, which is why this was sent as an issue and not a pull request. Feel free to delete it without comment, I’m a humble robot and won’t feel rejected 🤖


FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Allow "0" date values

Hello,
I wanted to use the dfnsDistanceInWords pipe to convert a number in a duration string (an absolute number, ie. a time interval but not a date per se).
For that, I usually cheat with distanceInWords function by passing a "zero" date for comparison, so I have two "absolute" referentials.

Ex: dateFns.distanceInWords(0, myDuration) would return something like "less than a minute".

Refactoring some code to use the pipes, I noticed that ngx-date-fns does not allow to pass "0" dates:

ERROR Error: dfnsDistanceInWords: missing required arguments
    at DistanceInWordsPipe.transform (ngx-date-fns.js:76) [angular]

The reason is that ngx-date-fns checks the input and does not allow any flasey value :

https://github.com/joanllenas/ngx-date-fns/blob/master/projects/ngx-date-fns/src/lib/distance-in-words.pipe.ts#L43

Instead of:

if (!dateToCompare || !date) {
  throw new Error(DistanceInWordsPipe.NO_ARGS_ERROR);
}

We should have :

if (dateToCompare == undefined || date == undefined) {
  throw new Error(DistanceInWordsPipe.NO_ARGS_ERROR);
}

Loosy comparison with undefined works here, 0 would be allowed but not undefined or null, which would be expected.

Obviously, there are other pipes concerned. For now, I'll use 1 instead of 0 :)

An in-range update of @angular/compiler-cli is breaking the build 🚨

Version 4.4.0 of @angular/compiler-cli just got published.

Branch Build failing 🚨
Dependency @angular/compiler-cli
Current Version 4.3.6
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/compiler-cli is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Error is is not a Module when adding locales

Hi,

I followed the instructions to Changing locale globally.

The next error appears:

ERROR in src/app/app.module.ts(43,27): error TS2306: File '.../node_modules/date-fns/locale/es/index.d.ts' is not a module.

I can serve the app and is working but the error is very anoying.

What can i do ?¿

  • Angular version? 7.2.12
  • TypeScript version? 3.2.4
  • date-fns version? 1.30.1

Thanks in advance.

Pipes isToday, isWeekend, isSameMonth

Hi Joanllenas!
Thx for adding pipes in this issue! But you didn't add isToday, it will be nice to use it
And also will be good to have pipes such as isWeekend and isSameMonth or something like this
Thx a lot for you job!)

An in-range update of @angular/core is breaking the build 🚨

Version 4.3.5 of @angular/core just got published.

Branch Build failing 🚨
Dependency @angular/core
Current Version 4.3.4
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

As @angular/core is “only” a devDependency of this project it might not break production or downstream projects, but “only” your build or test tools – preventing new deploys or publishes.

I recommend you give this issue a high priority. I’m sure you can resolve this 💪

Status Details
  • continuous-integration/travis-ci/push The Travis CI build could not complete due to an error Details

Not sure how things should work exactly?

There is a collection of frequently asked questions and of course you may always ask my humans.


Your Greenkeeper Bot 🌴

Documentation request: i18n example

Description of the Issue and Steps to Reproduce:
I see from other issues that your pipes support passing in an options argument for date-fns, and thus it supports i18n. I'm new to date-fns however, and haven't written many pipes of my own yet.I would really love to see an example of how i18n works with the angular pipes you provide for the library since loading the locale and passing in the desired locale may not be immediately obvious.

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

Please describe the issue and steps to reproduce, preferably with a code sample / plunker:
No real steps to reproduce, just looking for a clear i18n example in the README.md file of the project if it isn't too much trouble.

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

Environment:

Please answer the following questions:

  • Angular version?
    4.x
  • TypeScript version?
    2.3.4
  • date-fns version?
    1.29.0

Runtime locale change & OnPush strategy

Hello,

I am using OnPush components and DateFnsConfigurationService.setLocale to change language at runtime. I react to LangChangeEvents from ngx-translate to sync the locale used by ngx-date-fns.

The thing is, I use OnPush components and that prevents Angular from cheking the pipes used in the component. Since the locale is changed outside of the Inputs of the component, Angular doesn't replays the pipes' transform.

However, the pipes from ngx-translate work just fine when changing the locale globally. So I went to see how they've done, and each pipe subscribes to locale changes from the TranslateService and mark themselves for check : https://github.com/ngx-translate/core/blob/master/projects/ngx-translate/core/src/lib/translate.pipe.ts#L25.

Would it be possible to implement the same here, on the library's side? For now I'll workaround that with the component subscribing to changes from my custom service, in order to call the change detector from the component.

Little addendum: the declaration of locale() / setLocale() could be improved so they take/return object | undefined instead of Object. undefined is the built-in "en" locale. In strictNullChecks mode, it causes type-checking error and I have to cast the value.

Thanks for your work!

PS: On a side note, will you plan to support date-fns v.2 when it's out ?

rxjs-compat need

I think rxjs-compat is needed. You could replace imports like import { Subject } from "rxjs/Subject" with import { Subject } from "rxjs'

"CommonJS or AMD" warnings

Question: Is it normal to have warnings like ...js depends on 'date-fns/...'. CommonJS or AMD dependencies can cause optimization bailouts. and is the supposed way to fix it to add date-fns to allowedCommonJsDependencies? If so, doesnt it make sense to add the instruction to the readme?

Also is there an open issue on date-fns project to build ecmascript modules?

Add dfnsParseIso pipe

Hi!
I found myself needing a dfnsParseIso pipe since the dates coming from my server API are ISO-formatted (ie. not localized) and since date-fns 2.0 doesn't supports strings anymore.

import { Pipe, PipeTransform } from '@angular/core';
import { parseISO } from 'date-fns';

@Pipe({
    name: 'myDfnsParseIso',
    pure: true
})
export class DfnsParseIsoPipe implements PipeTransform {
    public transform(value: string, options?: { additionalDigits?: 0 | 1 | 2 }): Date {
        return parseISO(value, options);
    }
}

Angular 14 support

Description of the Issue and Steps to Reproduce:

Did you search for duplicate issue? [Yes]

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

Requires angular 13.2.* in peer

Environment:

Ionic:

Ionic CLI : 6.19.1 (/usr/local/lib/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 6.1.9
@angular-devkit/build-angular : 14.0.1
@angular-devkit/schematics : 14.0.1
@angular/cli : 14.0.1
@ionic/angular-toolkit : 6.1.0

Cordova:

Cordova CLI : 10.0.0 ([email protected])
Cordova Platforms : android 10.1.1, ios 6.2.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 10 other plugins)

Utility:

cordova-res : 0.15.4
native-run : 1.6.0

System:

Android SDK Tools : 26.1.1 (/Users/vs/Library/Android/sdk)
ios-deploy : 1.11.4
ios-sim : 8.0.2
NodeJS : v14.18.1 (/usr/local/bin/node)
npm : 8.10.0
OS : macOS Monterey
Xcode : Xcode 13.4.1 Build version 13F100

Please answer the following questions:

  • Angular version? 14
  • TypeScript version? 4.6.4
  • date-fns version? latest

Allow empty value (Prevent throwing "Invalid time value")

Description of the Issue and Steps to Reproduce:

Did you search for duplicate issue? [Yes]

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

@Component({
  selector: 'app-a',
  template: `
    <div>{{empty|dfnsFormatDistanceToNow}}</div>
  `,
})
export class ExamBComponent implements OnInit {
  empty: undefined = undefined;
}

This will throw:

ERROR RangeError: Invalid time value
    at formatDistance (index.js:134)
    at formatDistanceToNow (index.js:111)
    at FormatDistanceToNowPipe.transform (ngx-date-fns.js:971)
    ...

Support date-fns-tz

It'd be cool if you could also format timezone-aware dates. For that you need the format function from date-fns-tz.

I'm willing to create a PR, but I wanted to check if/how you'd integrate a feature like that.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.