Configuring jQuery UI Datepicker

I most likely suspect that this is impossible, but I wanted to know if someone worked with setting the calendar displayed on the jQuery UI datepicker, in addition to changing the dates. Here is my situation. My company uses a fiscal year instead of a calendar year, when it starts on a different day every year, I actually made an Excel calendar on average, and I could use this principle in javascript, my question is, is there a way to set the start date in the calendar and start counting weeks from this day ...

Example

The fiscal year begins on August 28 (Sunday), given that: AUG28-SEPT3 = FW1
SEPT4-SEPT10 = FW2
SEPT11-SEPT17 = FW3
.
.
.
and so on ... I want to show a calendar with the week number starting from August 28, 2011 (fw1) and ending with aug25 2012 (fw52).

I have already read the documentation and I cannot find anything related, if I were not clear enough, let me know so that I can rephrase.

+6
source share
2 answers

You will need to create your own weekly calculation, see the docs for jQuery UI calculateWeek . Its beginning, but not too useful in these documents. A little more helpful was this blog post here .

In any case, here is the code I managed to crack, see the link below to see how it works.

Define a datapicker:
$("#mydatepicker").datepicker({ calculateWeek: fisc, maxDate: '08/25/12', minDate: '08/28/11', showWeek: true }); 

And weeks calculation function:
 function fisc(date) { var checkDate = new Date(date.getTime()); checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7)); var time = checkDate.getTime(); checkDate.setMonth(7); checkDate.setDate(28); var week = (Math.floor(Math.round((time - checkDate) / 86400000) / 7) + 2); if (week < 1) { week = 52 + week; } return 'FW: '+week; } 

Click here to see it in action.

I'm sure this is probably not the perfect way to do this, but it seems to be working at this time of night, hopefully it will point you in the right direction.

+5
source

Maybe you can try

 $('.dateinput').datepicker({ dateFormat:'yy-mm-dd', duration: 'normal', changeMonth: true, changeYear: true, showWeek: true, /*other options goes here...*/ calculateWeek: function(mydate){ return 'FW'+( $.datepicker.iso8601Week(mydate + 1/*offset A*/)+1/*or offsetB*/ ); } }); 
0
source

Source: https://habr.com/ru/post/900087/


All Articles