Is thete any "week" custom field?

Flavio Beck February 18, 2014

Hello people,

is there any week custom field available in JIRA, or some add-on for that?

I would like to have a field where I can select a calandar date (ie: Feb/19th/2014) and the field stores W7 value, or Week7.

Of course I can create a select list with W1 - w53, but users will be confusing.. because they need to convert their dates into week format manualy.

thanks

1 answer

1 accepted

1 vote
Answer accepted
Nitram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2014

Hi,

Nice question, This can be done,

How are we going to achieve ?

You will be having a datepicker custom field and you need to create a select list with W1 - w53, in datepicker customfield we are going to add a javascript, which will automatically select the week.

But You have to add javascript.Please check the below javascript.

These code which are below will come inside the date picker custom field .This is for getting the week

Date.prototype.getWeek = function () {

// Create a copy of this date object

var target = new Date(this.valueOf());

// ISO week date weeks start on monday

// so correct the day number

var dayNr = (this.getDay() + 6) % 7;

// ISO 8601 states that week 1 is the week

// with the first thursday of that year.

// Set the target date to the thursday in the target week

target.setDate(target.getDate() - dayNr + 3);

// Store the millisecond value of the target date

var firstThursday = target.valueOf();

// Set the target to the first thursday of the year

// First set the target to january first

target.setMonth(0, 1);

// Not a thursday? Correct the date to the next thursday

if (target.getDay() != 4) {

target.setMonth(0, 1 + ((4 - target.getDay()) + 7) % 7);

}

// The weeknumber is the number of weeks between the

// first thursday of the year and the thursday in the target week

return 1 + Math.ceil((firstThursday - target) / 604800000); // 604800000 = 7 * 24 * 3600 * 1000

}

This is for getting the week from datepicker customfield and setting it in the week customfield

$("#datecustomfield").change(function(){

var today = $("#datecustomfield").getDate();

var week = "W"+today.getWeek();

$("#weekcustomfield option[text="+week+"]").attr("selected","selected");

});

Hope this helps you!

Flavio Beck February 19, 2014

Thank you Nitram. I did not test it yet, but I got the idea.

Suggest an answer

Log in or Sign up to answer