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

Defining week number as a function #912

Closed
duncanfwalker opened this issue Jun 28, 2017 · 9 comments
Closed

Defining week number as a function #912

duncanfwalker opened this issue Jun 28, 2017 · 9 comments

Comments

@duncanfwalker
Copy link

A lot of big enterprises have their own week numbering system. I would like to be able provide a function as prop for calculating the current week number following that company's business logic.

The week numbers used in react-datepicker come from moment. The way to change how they are calculated in moment is to define a custom locales. There are a couple of problems with this 1) its not really a /locale/ we're talking about here 2) Custom locales only allow you to define the first day of the year as a fixed integer, which isn't enough to represent the logic that I need for determining the week number.

Instead I would like to passing a function as prop to DatePicker that calculates the week number. I can understand that you may want avoid doing this to keep moment handling the date domain. At the same time I think this is probably a fairly common use case so it would be great to see it supported in react-datepicker. What do you think? If you're happy with the idea in principle I'm happy to work up a PR.

@alex-shamshurin
Copy link
Contributor

Could your provide more info about your use case. The primary intention of this widget is a date selection. Why you need week numbers? You can calculate week number of selected date outside, I think.

@duncanfwalker
Copy link
Author

duncanfwalker commented Jun 29, 2017

We are trying to replace something that looks like this
screen shot 2017-06-29 at 15 41 19

The week numbers help with finding the date the user wants. In the corporation I'm working for (and in other very large organisations). All of the weeks of the year have numbers that are used consistently across the organisation for scheduling. For example when ours user is talking about a specific date they may say 'the tuesday of week 10', rather than 'March 12th'.

The week numbers are not necessarily the same as the ISO week numbers, the way of calculating week number may vary from one organisation to another.

@rafeememon
Copy link
Contributor

Can you give a concrete use case for needing a function, as opposed to just specifying a new start-of-the-week day? Any function that doesn't behave in that way would produce unpredictable layout behavior in the datepicker when showing the week number.

@duncanfwalker
Copy link
Author

At the organisation I am working for the
2017 week 1 is 31st Dec - 7th Jan
2016 week 1 is 2nd Jan - 9th Jan

How this is decided is based on complex logic that is roughly which week is the first to have more than 3 days in the new calendar year.

A rule I have seen at another organisations is week 1 starts the first Monday after Christmas

@duncanfwalker
Copy link
Author

If this seems a reasonable parameter to extract I can make a PR?

@sentient06
Copy link

sentient06 commented Jul 5, 2017

Some companies that deal with scheduling events do have unorthodox week numbering systems that can increase the number of weeks in an year or decrease, positioning the next year's 1st week before and ahead the ISO standard. Also, such prop could be useful for situations like fiscal year starting in April, for example.

@martijnrusschen
Copy link
Member

Sure, if you suggest a PR with some possible solution than we can take a look to see if we think it's a worthy addition.

@sentient06
Copy link

Hello, please find the PR below. All the best.
#934

@stale
Copy link

stale bot commented Aug 30, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Aug 30, 2019
@stale stale bot closed this as completed Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants