我正在尝试从switch语句中获取cal
的输出,但是它给了我当前的日期,我做错了什么?一个解释也将非常感激。谢谢。
import static java.util.Calendar.*
import java.sql.Timestamp.*
every = 4 //testing
period = 'weeks(s)' //testing
if (every && period){
def cal = Calendar.instance
def addTime
addTime = cal.time
switch (period) {
case "day(s)":
cal[DATE] = cal[DATE] + every
addTime = cal.time
break
case "weeks(s)":
cal[DATE] = cal[DATE] + every*7
addTime = cal.time
break
case "month(s)":
cal[DATE] = cal[MONTH] + every
addTime = cal.time
break
case "year(s)":
cal[YEAR] = cal[YEAR] + every
addTime = cal.time
break
case "day of the month":
cal[MONTH] = cal[MONTH] + 1
cal[DATE] = every
addTime = cal.time
break
}
java.sql.Timestamp newTimestamp = new java.sql.Timestamp(addTime.getTime());
dueDate = newTimestamp
}
println dueDate
例如,这个脚本可以完成工作,例如我的dueDate
已正确更新,但它在newTimestamp
行中是硬编码的,那么如何在下面的代码中实现上述开关呢?
//import com.atlassian.jira.ComponentManager
//import com.atlassian.jira.issue.CustomFieldManager
//import com.atlassian.jira.issue.MutableIssue
//import com.atlassian.jira.issue.customfields.CustomFieldType
//import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp;
//MutableIssue myIssue = issue
Calendar cal = Calendar.getInstance();
// set due date to: current date + 30 days
Timestamp mydueDate = new Timestamp(cal.getTimeInMillis()+ 2592000000);
println mydueDate
//myIssue.setDueDate(mydueDate);
答案 0 :(得分:1)
这是实际的方式,所以JIRA会停止抱怨。
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.customfields.CustomFieldType
import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp;
def every, period
if (cfValues['Every']){
every = cfValues['Every'] as int
}
if (cfValues["Period"]){
period = cfValues["Period"]
}
Calendar cal = Calendar.getInstance();
if (every && period){
switch (period) {
case "day(s)":
cal.add(Calendar.DAY_OF_MONTH, every)
break
case "week(s)":
cal.add(Calendar.DAY_OF_MONTH, every*7)
break
case "month(s)":
cal.add(Calendar.MONTH, every)
break
case "year(s)":
cal.add(Calendar.YEAR, every)
break
case "day of the month":
cal.add(Calendar.MONTH, 1)
cal.set(Calendar.DAY_OF_MONTH, every)
break
}
}
MutableIssue myIssue = issue
Timestamp mydueDate = new Timestamp(cal.getTimeInMillis());
myIssue.setDueDate(mydueDate);
//copy the parent issue summary
issue.summary = sourceIssue.summary
//delete the links and attachements
checkLink = {link -> false};
checkAttachment = {attachment -> false}