Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calendar using locale date format #993

Closed
NoFr1ends opened this issue Aug 19, 2019 · 2 comments
Closed

Calendar using locale date format #993

NoFr1ends opened this issue Aug 19, 2019 · 2 comments
Assignees
Labels
Type: New Feature Issue contains a new feature or new component request
Milestone

Comments

@NoFr1ends
Copy link
Contributor

There is no guarantee in receiving an immediate response in GitHub Issue Tracker, If you'd like to secure our response, you may consider PrimeReact PRO Support where support is provided within 4 business hours

I'm submitting a ... (check one with "x")

[ ] bug report
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://forum.primefaces.org/viewforum.php?f=57

Current behavior
Currently it is only possible to provide a date format string to the Calendar component.

Expected behavior
It would be nice to also have the ability to have a prop where I can give an instance of Intl.DateTimeFormat and use that instead of a date format string.
We should consider what we should do if this is not implemented in the current browser (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat#Browser_compatibility).

If it is okay to add a new optional property to the Calendar component and modify the formatDateTime method accordingly I can submit a PR.

@mertsincan mertsincan added the Status: Discussion Issue or pull request needs to be discussed by Core Team label Feb 9, 2021
@mertsincan mertsincan added this to the 6.1.0 milestone Feb 9, 2021
@mertsincan mertsincan modified the milestones: 6.1.0, 7.0.0 Mar 9, 2021
@mertsincan mertsincan added the Type: New Feature Issue contains a new feature or new component request label Jul 6, 2021
@mertsincan mertsincan modified the milestones: 8.2.0, 9.0.0 Jul 6, 2022
@carlesfelix
Copy link

carlesfelix commented Jul 13, 2022

I have the same problem. I guess it would be better accepting a callback in the dateFormat prop. So we can pick the value and return an any string as the parsed value in the input.

<Calendar
      className={rootClassName}
      inputId={id}
      value={value}
      ref={ref}
      inputRef={inputRef}
      name={name}
      onChange={changeHandler}
      disabled={disabled}
      onBlur={blurHandler}
      minDate={minDate}
      maxDate={maxDate}
      readOnlyInput
      showButtonBar
      showIcon
      dateFormat={d => {
        // This callback will let us to have freedom to parse whatever
        return d.toLocaleDateString();
      }}
    />

I went for this temporary solution. I don't like this way because if we transform a date containing letters like 'y', 'm' the library will replace by years, or months. For me it fits fine for now because I want to display always numbers and slashes but I don't think it's de best solution if we want non limitations.

return (
    <Calendar
      className={rootClassName}
      inputId={id}
      value={value}
      ref={ref}
      inputRef={inputRef}
      name={name}
      onChange={changeHandler}
      disabled={disabled }
      onBlur={blurHandler}
      minDate={minDate}
      maxDate={maxDate}
      readOnlyInput
      showButtonBar
      showIcon
      dateFormat={value instanceof Date ? value.toLocaleDateString() : ''}
    />
  );

@melloware melloware self-assigned this Sep 30, 2022
@melloware
Copy link
Member

melloware commented Sep 30, 2022

Implemented in 8.6.2. See: #3381

@melloware melloware modified the milestones: 9.0.0, 8.6.2 Sep 30, 2022
@melloware melloware removed the Status: Discussion Issue or pull request needs to be discussed by Core Team label Sep 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: New Feature Issue contains a new feature or new component request
Projects
None yet
Development

No branches or pull requests

4 participants