Skip to content

Instantly share code, notes, and snippets.

@tomkuijsten
Last active March 8, 2016 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomkuijsten/cdf9f29db6e1523801a4 to your computer and use it in GitHub Desktop.
Save tomkuijsten/cdf9f29db6e1523801a4 to your computer and use it in GitHub Desktop.
if(self.Revision == 0)
{
// without history, we can't do anything
logger.Log("There is not history for this task, quit.");
return null;
}
var treatStates = new[] {"In Progress", "Review"};
var stateKey = "System.State";
var currentState = (string)self.Fields[stateKey].Value;
if(!treatStates.Contains(currentState))
{
logger.Log("Current task is not in a treat state, quit.");
return null;
}
var treatDatekey = "BHT.TreatDate";
var originalState = (string)self.LastRevision.Fields[stateKey].Value;
if(string.Equals(currentState, originalState))
{
logger.Log("State didn't change since last revision, quit.");
return null;
}
// When moved to progress, only mark as treat when moved from Review
if(currentState == "In Progress" && originalState != "Review")
{
logger.Log("Task is In Progress, but not moved from Review, quit.");
return null;
}
logger.Log("State is changed from <{0}> to <{1}>", currentState, originalState);
var treatDate = System.DateTime.Today.AddDays(2);
if(System.DateTime.Now.TimeOfDay > System.TimeSpan.FromHours(9))
{
// After standup, add an extra day
logger.Log("State changed after stand-up, add an extra day.");
treatDate = treatDate.AddDays(1);
}
var weekendDays = new[] {System.DayOfWeek.Saturday, System.DayOfWeek.Sunday};
if(weekendDays.Contains(treatDate.DayOfWeek))
{
// Skip non-working days
logger.Log("Treat day was in the weekend, add two extra days to skip it.");
treatDate = treatDate.AddDays(2);
}
logger.Log("Treat date is set on: {0:dd-MMM}", treatDate);
self[treatDatekey] = treatDate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment