String date in the format "dd-MM-yyyy" cannot be transformed into a date using the 'DatePipe' function

Having trouble with date conversion in my custom pipe. It seems that when using a locale of 'nl-nl' and trying to format the date as 'dd-MM-YYYY', I'm seeing an error message stating

Unable to convert "16-02-2023" into a date for pipe 'DatePipe'
, while other dates like 02-09-2023 work fine.

import { DatePipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { ConfigurationService } from '../services/configuration.service';

@Pipe({
    name: 'formattedDate',
})
export class FormattedDatePipe implements PipeTransform {
    constructor(
        private datePipe: DatePipe,
        private configurationService: ConfigurationService,
    ) {}

    transform(value: Date | string | number): string {
        return this.datePipe.transform(value, this.configurationService.config.customer.dateFormat);
    }
}

I suspect there may be confusion between day and month values causing the issue, but I haven't been able to pinpoint the exact cause.

Answer №1

import { DatePipe } from '@angular/common';
import { Pipe, PipeTransform } from '@angular/core';
import { ConfigurationService } from '../services/configuration.service';

@Pipe({
    name: 'formattedDate',
})
export class FormattedDatePipe implements PipeTransform {
    constructor(
        private datePipe: DatePipe,
        private configurationService: ConfigurationService,
    ) {}

    transform(value: Date | string | number): string {
       
        return this.datePipe.transform(value, 'dd-MM-yyyy', 'nl-nl');
    }
}

In order to rectify the issue at hand, it is crucial to ensure that the date format being utilized corresponds with the norms of the 'nl-nl' locale. Within the Netherlands, the customary date structure typically follows 'dd-MM-yyyy,' wherein the year is denoted in lowercase as 'yyyy,' rather than uppercase as 'YYYY.' By conforming to these guidelines, potential errors stemming from date formatting within a Dutch context can be mitigated effectively.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to include a new property to an existing interface and then export the updated interface in Typescript?

Can you provide guidance on creating a new interface - UIInterface that combines SummaryInterface with additional properties? For example: import { SummaryInterface } from 'x-api'; // summaryInterface includes 20+ predefined properties generated ...

combine two separate typescript declaration files into a single package

Can anyone help me figure out how to merge two typescript definition packages, @types/package-a and @types/package-b, into one definition package? package-a.d.ts [export package-a {...}] package-b.d.ts [exports package-b {...}] package-mine.d.ts [ export ...

Using React.lazy, Suspense, and react-router-dom for code splitting in React does not function as intended

I'm currently working on setting up a simple example that is similar to the concept of lazy-loading route components as explained here: https://reactjs.org/docs/code-splitting.html#route-based-code-splitting The idea is to dynamically load ModuleOne ...

Looking to establish a connection between Azure blob storage and an Angular application using a NodeJS Express application

I am looking to implement a secure way of uploading files from an Angular web app to Azure blob storage. Instead of directly uploading files from the frontend, I want to send them first to a NodeJS app via an Express API, and then have the backend handle ...

Tips for extracting elements from an HTML document using Angular

I seem to be facing a small issue - I am trying to develop a form using Angular. Below is my HTML: <form [formGroup]="requeteForm" (ngSubmit)="ajouter()" *ngIf=" tables!= null"> <div class="form-group&quo ...

Validation of passwords containing special characters in Angular2

I am working on setting up password validation requirements to ensure the field contains: Both uppercase letters, lowercase letters, numbers and special characters This is my current progress: passwordValueValidator(control) { if (control.value != u ...

Getting Data Beyond the .subscribe() in AngularFire 2

Currently, I have a piece of code that retrieves user data from a database. import { Component } from '@angular/core'; import { NavController } from 'ionic-angular'; import {AngularFireAuth} from 'angularfire2/auth'; import { ...

Some code paths fail to return a value in Google Cloud Function callable functions

When utilizing async functions in my cloud function and including a 'return' statement in each potential output, I am still encountering the error message Not all code paths return a value I attempted removing my database calls and only leaving ...

Is it feasible to invoke a method without any arguments on this basic subscription?

A BRIEF SUMMARY Implementing an observable in my code, I strive for maintaining cleanliness and efficiency by utilizing the detectChanges() method to update *ngIf= in the HTML. QUERY Is there a way to invoke the detectChanges() method within subscribe() ...

I require the JSON data to be displayed in an array format

I am looking to convert a JSON object into a JSON array in Laravel. Currently, I am receiving JSON data in object format. $category = new Categories; return Response::json(array( 'error' => false, 'category' => $category- ...

When I attempt to conceal the filter within mat-table using *ngIf, I encounter an issue where I am unable to read the property 'value' due to it being

After creating a mat-table, I encountered an issue when trying to show and hide my input filter area using a button. If I use *ngIf="showInputFilter" to hide the filter area, I receive the error message Cannot read property 'value' of u ...

Extending Enums in Typescript: A Comprehensive Guide

How can you work with a list of constants or Enum? Here is an example: enum MyList { A, B } enum MyList2 { C } function process<T>(input:MyList | T):void { } process<MyList2>(123) // The compiler does not recognize that 123 ...

Differences between Angular2 local template variables and Jade ID shortcutsIn Angular2, local

Angular2 has introduced the local template variable feature, which is created using #var. When using the Jade Template Engine, this syntax gets converted to #var="var". Is there a method to avoid this conversion? Otherwise, accessing the original local t ...

Is there a way to hide the sign up link on the AWS Amplify Angular authenticator?

I am utilizing the amplify-authenticator component from the aws-amplify/ui-angular library in order to implement authentication within my application. I have been attempting to find a way to disable the "Create Account" link on the front end, but unfortuna ...

Tips for handling undefined values in observable next methods to return a default error message

I sent a request over the network and received a response. Whenever I encounter an undefined value in the response, I want to return a default error message. The response may contain multiple levels of nested objects. Is there a way to replace the if else ...

Error in Firebase Emulator: The refFromUrl() function requires a complete and valid URL to run properly

Could it be that refFromURL() is not functioning properly when used locally? function deleteImage(imageUrl: string) { let urlRef = firebase.storage().refFromURL(imageUrl) return urlRef.delete().catch((error) => console.error(error)) } Upon ...

Retrieving JSON data with Angular's HTTP GET method

Can anyone help me with retrieving a json file using a service in Angular 4? Service import { Injectable } from '@angular/core'; import { Http, Response } from '@angular/http'; import { CONFIG as APP_CONSTANTS } from '../config/c ...

Changing the row property value of a textarea dynamically based on text input in ReactJS

Here is what I have tried: <textarea rows='2' onChange={e => setSomething(e.target.value)} className='form-control text-area ' value={something} placeholder='write something'> </textarea> output: Expected ...

Struggling to retrieve service information for implementation in the component

I am currently working on a project where: 1. I have created a news.service.ts service file with the following code: 2. Within the service, I have implemented a function named throwData() that returns the service data. Here is the code snippet: im ...

Exploring Angular 4 with the power of Rangy modules

I've recently started working with Angular 4 and decided to create a basic app by forking the Angular quickstart. Now, I'm facing a challenge as I try to incorporate Rangy into my project. In my package.json, the dependencies are listed as follo ...