Skip to content

Commit

Permalink
simpliflies iteration calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
julliasaad committed May 17, 2018
1 parent 9c5b0b4 commit c378786
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions app/assets/javascripts/actions/column.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ const setColumn = (dispatch, project) => story => {
}

const isBacklog = (story, project) => {
const currentSprint = iteration.getSprint(project);
const storySprint = iteration.getIterationForStory(story, project);
const isFromCurrentSprint = currentSprint === storySprint;
const currentIteration = iteration.getCurrentIteration(project);
const storyIteration = iteration.getIterationForStory(story, project);
const isFromCurrentSprint = currentIteration === storyIteration;
return story.state !== 'accepted' || isFromCurrentSprint
}

Expand Down
25 changes: 15 additions & 10 deletions app/assets/javascripts/models/beta/iteration.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import moment from 'moment';

export const getSprint = (project) => {
const startDate = moment(new Date(project.startDate));
const weeks = moment().diff(startDate, 'week');
const sprintNumber = Math.ceil(weeks / project.iterationLength);
return project.iterationLength > weeks ? sprintNumber : sprintNumber + 1;
}
const weeksBetween = (dateA, dateB) =>
moment(new Date(dateA)).diff(moment(new Date(dateB)), 'week');

const getIterationForDate = (date, project) => {
const weeks = weeksBetween(date, project.startDate);
const iterationQuantity = Math.ceil(weeks / project.iterationLength);

return project.iterationLength > weeks ? iterationQuantity : iterationQuantity + 1;
};

export const getCurrentIteration = (project) => (
getIterationForDate(new Date(), project)
);

export const getIterationForStory = (story, project) => {
if(story.state === 'accepted') {
const weeks = moment().diff(new Date(story.acceptedAt), 'week');
const sprintNumber = Math.ceil(weeks / project.iterationLength);
return project.iterationLength > weeks ? sprintNumber : sprintNumber + 1;
if (story.state === 'accepted') {
return getIterationForDate(new Date(story.acceptedAt), project);
}
}
10 changes: 5 additions & 5 deletions spec/javascripts/models/beta/iteration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('iteration', function() {

describe('when 1 out of 1 week has passed', function() {
it('should return 2', function() {
const sprintNumber = Iteration.getSprint({
const sprintNumber = Iteration.getCurrentIteration({
iterationLength: 1,
startDate: "2018-04-24T16:00:00"
});
Expand All @@ -22,7 +22,7 @@ describe('iteration', function() {

describe("when 3 out of 3 weeks has passed", function() {
it('should return 2', function() {
const sprintNumber = Iteration.getSprint({
const sprintNumber = Iteration.getCurrentIteration({
iterationLength: 3,
startDate: "2018-04-10T16:00:00"
});
Expand All @@ -32,7 +32,7 @@ describe('iteration', function() {

describe("when 1 out of 2 weeks has passed", function() {
it('should return 1', function() {
const sprintNumber = Iteration.getSprint({
const sprintNumber = Iteration.getCurrentIteration({
iterationLength: 2,
startDate: "2018-04-24T16:00:00"
});
Expand All @@ -44,9 +44,9 @@ describe('iteration', function() {
it('should return 1', function() {
const sprintNumber = Iteration.getIterationForStory(
{ state: 'accepted', acceptedAt: "2018-04-24T16:00:00" },
{ iterationLength: 2 }
{ startDate: "2018-04-10T16:00:00", iterationLength: 2 }
);
expect(sprintNumber).toEqual(1);
expect(sprintNumber).toEqual(2);
});
});

Expand Down

0 comments on commit c378786

Please sign in to comment.