Compare date system with customl field date

Karim Belhadj
Contributor
December 26, 2018

Hello team

I tried to compare two date , first the date of system , second the date of a custom field so the problem 

is the date system return only day : 

the date of custom field timestamp return this : 

 

 

I need a help to compare the two dates 

I need help

WARN [runner.ScriptRunnerImpl]: DDP 10

 WARN [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 12:25:03 GMT+01:00 2018

 

Regards

1 answer

1 accepted

1 vote
Answer accepted
Adrián Plaza [DEISER]
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.
December 26, 2018

Hi @Karim Belhadj

 

Can you share the way that are you trying to compare the dates?

 

Adrián.

Karim Belhadj
Contributor
December 26, 2018

@Adrián Plaza [DEISER] of course , 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
long IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date).getDate();
log.warn("DDP " + IncidentStart )
def systemDate = new Date()
log.warn ("date de systeme " + systemDate.getTime() )

def warrantyField = customFieldManager.getCustomFieldObjectByName("DDP")

def warranty = issue.getCustomFieldValue(warrantyField)
log.warn("ddp " + warranty)

 


if (IncidentStart < systemDate)

{

 

]

 

 

Regards

Adrián Plaza [DEISER]
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.
December 26, 2018

Hi @Karim Belhadj,

 

I made some modifications in your code and now looks like works fine:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

//Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("KANBAN-8")

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
Date IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date)
log.error("IncidentStart " + IncidentStart )
Date systemDate = new Date()
log.error ("date de systeme " + systemDate )

if (IncidentStart.getTime() < systemDate.getTime()){
return true
}else{
return false
}

 

Can you try?

 

I hope this help,

Adrián.

Karim Belhadj
Contributor
December 26, 2018

hi @Adrián Plaza [DEISER]  always the result of return = null

 

Sorry for that !

Can you help me why !!

Adrián Plaza [DEISER]
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.
December 26, 2018

Hi @Karim Belhadj,


Can you send me the log output?

Karim Belhadj
Contributor
December 26, 2018

yes 

@Adrián Plaza [DEISER]

 

this is the log 

2018-12-26 15:23:30,835 ERROR [runner.ScriptRunnerImpl]: IncidentStart 2018-12-27 00:00:00.0

2018-12-26 15:23:30,836 ERROR [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 15:23:30 GMT+01:00 2018

Adrián Plaza [DEISER]
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.
December 26, 2018

Hi @Karim Belhadj,

 

Can you try with this code and show me the log:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import java.text.SimpleDateFormat

//Issue issue = ComponentAccessor.issueManager.getIssueByCurrentKey("KANBAN-8")

long createdDateTime = issue.created.getTime()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField IncidentStartField = customFieldManager.getCustomFieldObject("customfield_10801");
// String IncidentStart = issue.getCustomFieldValue(IncidentStartField)
Date IncidentStart = (issue.getCustomFieldValue(IncidentStartField) as Date)
log.error("IncidentStart " + IncidentStart +" and the time is "+ IncidentStart.getTime())
Date systemDate = new Date()
log.error ("date de systeme " + systemDate +" and the time is "+ systemDate.getTime())

if (IncidentStart.getTime() < systemDate.getTime()){
log.error("The incident start before the system date")
return true
}else{
log.error("The incident start after the system date")
return false
}

 

Adrián.

Karim Belhadj
Contributor
December 26, 2018

@Adrián Plaza [DEISER]   

this is the new log

2018-12-26 15:48:00,740 ERROR [runner.ScriptRunnerImpl]: IncidentStart 2018-12-27 00:00:00.0 and the time is 1545865200000

2018-12-26 15:48:00,741 ERROR [runner.ScriptRunnerImpl]: date de systeme Wed Dec 26 15:48:00 GMT+01:00 2018 and the time is 1545835680740

2018-12-26 15:48:00,741 ERROR [runner.ScriptRunnerImpl]: The incident start after the system date

Adrián Plaza [DEISER]
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.
December 26, 2018

Hi @Karim Belhadj,

Now it's working well, you can compare system date with custom field date, this is what do you need? I am right?

Adrián.

Karim Belhadj
Contributor
December 26, 2018

yes thank you very much 

 

Regards

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events