Skip to content

Close on selection of month instead of year when dateFormat is set to display quarter#523

Closed
MilosRasic wants to merge 1 commit into
arqex:masterfrom
gogoair:year-quarter-close-on-select
Closed

Close on selection of month instead of year when dateFormat is set to display quarter#523
MilosRasic wants to merge 1 commit into
arqex:masterfrom
gogoair:year-quarter-close-on-select

Conversation

@MilosRasic
Copy link
Copy Markdown
Contributor

Description

Altered getUpdateOn() method to return viewModes.MONTHS when Q token is used in dateFormat. In case of dateFormats like YYYY-[Q]Q, it would detect Y token and return 'years' instead, but month selection is required to specify a quarter of a year.

Added a test case to cover this but also one to cover behaviour when w token is used (week of year), which is handled correctly even though it's not explicitly matched because getUpdateOn() returns viewModes.DAY by default.

Motivation and Context

My team ran into this problem while using react-datetime with closeOnSelect=true to control data for rendering of charts in which date grain can also be selected in another component. Changing date grain updates dateFormat prop on datepickers. It works fine for all formats except YYYY-[Q]Q where it closes when year is selected, making it impossible for user to get to months view.

Also added a test case to check week of the year format (for example gggg-[W]ww), which is also something we use. This is currently working correctly because all token detection fail and the method returns 'days' by default. I feel however that it would be easy to break with future changes since it relies on the default return, hence a new test case.

Checklist

[ x ] I have not included any built dist files (us maintainers do that prior to a new release)
[ x ] I have added tests covering my changes
[ x ] All new and existing tests pass
[ ] My changes required the documentation to be updated
  [ ] I have updated the documentation accordingly
  [ ] I have updated the TypeScript 1.8 type definitions accordingly
  [ ] I have updated the TypeScript 2.0+ type definitions accordingly

…ded tests to cover quarter and week of year in date format
@arqex
Copy link
Copy Markdown
Owner

arqex commented Sep 20, 2020

Hey @MilosRasic

Sorry for the delay. Now in v3 there is a updateOnView property that does exactly what you want, no need to mess with the date format:

import React from "react";
import "react-datetime/css/react-datetime.css";
import Datetime from "react-datetime";

export default function App() {
  return (
    <Datetime updateOnView="months" timeFormat={false} closeOnSelect={true} />
  );
}

See it working: https://codesandbox.io/s/optimistic-bartik-mnxt2

@arqex arqex closed this Sep 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants