primeng icon indicating copy to clipboard operation
primeng copied to clipboard

p-calendar does not use dateFormat from locale although the docs imply it

Open simhnna opened this issue 7 years ago • 6 comments

the docs suggest that you can provide the dateFormat as part of the locale.

export class MyModel {

    en: any;

    ngOnInit() {
        this.en = {
            firstDayOfWeek: 0,
            dayNames: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
            dayNamesShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
            dayNamesMin: ["Su","Mo","Tu","We","Th","Fr","Sa"],
            monthNames: [ "January","February","March","April","May","June","July","August","September","October","November","December" ],
            monthNamesShort: [ "Jan", "Feb", "Mar", "Apr", "May", "Jun","Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
            today: 'Today',
            clear: 'Clear',
            dateFormat: 'mm/dd/yy'
        };
    }
}

However p-calendar uses a defined interface of localeSettings that doesn't include dateFormat. Instead it only uses the dateFormat from the direct input.

export interface LocaleSettings {
    firstDayOfWeek?: number;
    dayNames: string[];
    dayNamesShort: string[];
    dayNamesMin: string[];
    monthNames: string[];
    monthNamesShort: string[];
    today: string;
    clear: string;
}

Either remove dateFormat from the docs and explicitly state that the dateFormat needs to be provided seperately or use the dateFormat from the LocaleSettings.

I personally would prefer the second option.

simhnna avatar Feb 20 '19 10:02 simhnna

The same issue here when I use 'es' locale. It always displays date in the default dateFormat. So it would be better if it will pick the dateFormat from the locale if dateFormat was not specified.

Cheers.

mickeyjohn avatar Jun 11 '19 13:06 mickeyjohn

@cagataycivici some news here? Would you accept a PR for this bug or only the primeng team can do it?

rafa-suagu avatar Aug 23 '19 14:08 rafa-suagu

any update ?

PunkHaz4rd avatar Nov 05 '19 09:11 PunkHaz4rd

Same problem.

Antilamer1709 avatar Jan 15 '20 10:01 Antilamer1709

Unable to replicate with PrimeNG 9, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.

The current code is;

    getDateFormat() {
        return this.dateFormat || this.locale.dateFormat;
    }

cagataycivici avatar Mar 19 '20 09:03 cagataycivici

Unable to replicate with PrimeNG 9, if the issue persists please create a new ticket with a test case reproducing the issue e.g. stackblitz or a github repo and it will be reviewed by our team once again.

The current code is;

    getDateFormat() {
        return this.dateFormat || this.locale.dateFormat;
    }

The issue is that the dateFormat has a default value so it is always preferred:

@Input() dateFormat: string = 'mm/dd/yy';

I would also suggest that the dateFormat from the locale is preferred over the other one, like this:

return this.locale.dateFormat || this.dateFormat

neergaard79 avatar Apr 16 '20 07:04 neergaard79