How to get workitem based on modified date and tim

2020-07-26 13:59发布

I want to query RTC with modified date. My query is to check modified date is same as given date and time but the response that I am getting is based on given date and it is ignoring time.

Response:

Queried Date: 08/07/2015 15:44:09

Id: 2583 Modified date :2015-08-07 14:43:19.157

Id: 2582 Modified date :2015-08-07 14:43:19.419

Ideally, both the records should not be received in response as it is before given time.

Below is my code:

IQueryableAttributeFactory factory = QueryableAttributes.getFactory( IWorkItem.ITEM_TYPE ); 

IQueryableAttribute recAttr1 = factory.findAttribute(projectArea, IItem.MODIFIED_PROPERTY, auditableClient, null ); 
IQueryableAttribute recAttr2 = factory.findAttribute(projectArea, IWorkItem.TYPE_PROPERTY, auditableClient, null );     

Date date = new Date();
date.setDate(date.getDate()-6);
DateFormat df = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
String reportDate = df.format(date);
System.out.println("Date: "+reportDate);
Timestamp timeStamp = new Timestamp(date.getTime()); 

AttributeExpression recExpr1 = new AttributeExpression(recAttr1, AttributeOperation.EQUALS, timeStamp ); 

Term term= new Term(Operator.AND); 
term.add(recExpr1); 

IQueryClient queryClient = (IQueryClient) teamRepository.getClientLibrary(IQueryClient.class); 
IQueryResult<IResolvedResult<IWorkItem>> result = queryClient.getResolvedExpressionResults(projectArea, (Expression)term, IWorkItem.FULL_PROFILE); 
System.out.println("This is total number: "+result.getResultSize(monitor).getTotal()+"\n");                 

while(result.hasNext(null)){ 
    IResolvedResult<IWorkItem> resolvedWorkItem = result.next(null); 
    IWorkItem workItem = resolvedWorkItem.getItem();
    Date date1 = resolvedWorkItem.getItem().modified(); 
    System.out.println("Id: "+workItem.getId());
    System.out.println("Modified date :"+date1.toString()+"\n"); 
}   

Can I get result not only based on date but also on time?

I strongly feel that the back-end logic of RTC is completely ignoring time and querying database only based on date.

1条回答
对你真心纯属浪费
2楼-- · 2020-07-26 14:21

I have the exact same problem. I thought maybe the results were cached somewhere, but that wasn't it.

I haven't found a way to do this via RTC query, but it should be possible to filter out these records in your code after RTC query returned. Save the time you used to perform the search, then use that to skip any records by doing:

if (workItem.modified().getTime() < lastModified)
  continue;

I know this isn't ideal, but at least there's a way to get the desired set to work with.

查看更多
登录 后发表回答