Example usage for org.joda.time DateTime withTimeAtStartOfDay

List of usage examples for org.joda.time DateTime withTimeAtStartOfDay

Introduction

In this page you can find the example usage for org.joda.time DateTime withTimeAtStartOfDay.

Prototype

public DateTime withTimeAtStartOfDay() 

Source Link

Document

Returns a copy of this datetime with the time set to the start of the day.

Usage

From source file:com.onboard.service.activity.impl.ActivityServiceImpl.java

License:Apache License

@Override
public List<Activity> getActivitiesByCompanyAndDates(Integer companyId, Date since, Date until) {
    Activity activity = new Activity();
    activity.setCompanyId(companyId);//from   w w  w. j  a v  a 2s.  c  om
    ActivityExample example = new ActivityExample(activity);

    DateTime dt = new DateTime(since);
    since = dt.withTimeAtStartOfDay().toDate();
    dt = new DateTime(until);
    until = dt.withTimeAtStartOfDay().plusDays(1).toDate();
    example.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(since).andCreatedLessThan(until);
    example.setOrderByClause("id desc");

    return activityMapper.selectByExample(example);
}

From source file:com.onboard.service.collaboration.impl.BugServiceImpl.java

License:Apache License

@Override
public Bug updateSelective(Bug item) {
    Bug bug = bugMapper.selectByPrimaryKey(item.getId());
    if (!item.getDueTime().equals(bug.getDueTime())) {
        DateTime dt = new DateTime(item.getDueTime());
        item.setDueTime(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate());
    }//from w ww .  j ava 2s.co  m
    if (bug.getStatus() != 0 && item.getStatus() == 0) {
        item.setCompletedTime(new Date());
    }
    bugMapper.updateByPrimaryKeySelective(item);
    return item;
}

From source file:com.onboard.service.collaboration.impl.BugServiceImpl.java

License:Apache License

@Override
public List<Bug> getCompletedBugsBetweenDates(Integer companyId, Date since, Date until) {
    Bug sample = new Bug();
    sample.setCompanyId(companyId);//from w  w w.  jav a  2 s  .c om
    sample.setStatus(0);
    BugExample example = new BugExample(sample);

    DateTime dt = new DateTime(since);
    since = dt.withTimeAtStartOfDay().toDate();
    dt = new DateTime(until);
    until = dt.withTimeAtStartOfDay().plusDays(1).toDate();

    example.getOredCriteria().get(0).andCompletedTimeGreaterThanOrEqualTo(since)
            .andCompletedTimeLessThan(until);
    List<Bug> results = bugMapper.selectByExample(example);

    for (Bug bug : results) {
        bug.setProject(projectService.getById(bug.getProjectId()));
    }
    return results;
}

From source file:com.onboard.service.collaboration.impl.BugServiceImpl.java

License:Apache License

@Override
public Long getCompletedBugAveDurationByProjectIdDateBackByMonth(Integer projectId, Integer months) {
    Bug sample = new Bug();
    sample.setProjectId(projectId);/*from www .  j a v  a2  s.c  om*/
    sample.setStatus(0);
    BugExample example = new BugExample(sample);

    DateTime dt = new DateTime(new Date());
    Date since = dt.withTimeAtStartOfDay().plusMonths(-months).toDate();
    Date until = dt.withTimeAtStartOfDay().plusDays(1).toDate();

    example.getOredCriteria().get(0).andCompletedTimeGreaterThanOrEqualTo(since)
            .andCompletedTimeLessThan(until);
    List<Bug> results = bugMapper.selectByExample(example);
    int length = results.size();
    if (length < MIN_BUG_NUMBER)
        return 0L;
    else {
        Long result = 0L;
        for (Bug bug : results) {
            result += bug.getCompletedTime().getTime() - bug.getCreatedTime().getTime();
        }
        return result / length;
    }
}

From source file:com.onboard.service.collaboration.impl.BugServiceImpl.java

License:Apache License

@Override
public Long getCompletedBugThirdQuarterDurationByProjectIdDateBackByMonth(Integer projectId, Integer months) {
    Bug sample = new Bug();
    sample.setProjectId(projectId);//from   w ww. j  ava2  s . c  o m
    sample.setStatus(0);
    BugExample example = new BugExample(sample);

    DateTime dt = new DateTime(new Date());
    Date since = dt.withTimeAtStartOfDay().plusMonths(-months).toDate();
    Date until = dt.withTimeAtStartOfDay().plusDays(1).toDate();

    example.getOredCriteria().get(0).andCompletedTimeGreaterThanOrEqualTo(since)
            .andCompletedTimeLessThan(until);
    List<Bug> results = bugMapper.selectByExample(example);
    int length = results.size();
    if (length < MIN_BUG_NUMBER)
        return 0L;
    else {
        int k = length * 3 / 4 - 1;
        long[] arr = new long[length];
        int i = 0;
        for (Bug bug : results) {
            arr[i] += bug.getCompletedTime().getTime() - bug.getCreatedTime().getTime();
            i++;
        }
        Arrays.sort(arr);
        return arr[k];
    }
}

From source file:com.onboard.service.collaboration.impl.CommentServiceImpl.java

License:Apache License

@Override
public List<Comment> getCommentsByCompanyIdBetweenDates(int companyId, Date since, Date until) {
    Comment comment = new Comment();
    comment.setCompanyId(companyId);//from  w  w  w  . j a  va2s  .c  om
    CommentExample commentExmaple = new CommentExample(comment);

    DateTime dt = new DateTime(since);
    since = dt.withTimeAtStartOfDay().toDate();
    dt = new DateTime(until);
    until = dt.withTimeAtStartOfDay().plusDays(1).toDate();

    commentExmaple.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(since).andCreatedLessThan(until);
    return commentMapper.selectByExample(commentExmaple);
}

From source file:com.onboard.service.collaboration.impl.DiscussionServiceImpl.java

License:Apache License

@Override
public List<Discussion> getDiscussionsByCompanyIdBetweenDates(int companyId, Date since, Date until) {
    Discussion discussion = new Discussion();
    discussion.setCompanyId(companyId);// ww  w  . j  ava 2  s .com
    DiscussionExample discussionExmaple = new DiscussionExample(discussion);

    DateTime dt = new DateTime(since);
    since = dt.withTimeAtStartOfDay().toDate();
    dt = new DateTime(until);
    until = dt.withTimeAtStartOfDay().plusDays(1).toDate();

    discussionExmaple.getOredCriteria().get(0).andCreatedGreaterThanOrEqualTo(since).andCreatedLessThan(until);
    return discussionMapper.selectByExample(discussionExmaple);
}

From source file:com.onboard.service.collaboration.impl.IterationServiceImpl.java

License:Apache License

@Override
protected Iteration fillItemBeforeCreate(Iteration item) {
    if (item.getEndTime() != null) {
        DateTime dt = new DateTime(item.getEndTime());
        item.setEndTime(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate());
    }/*from   ww  w. j  a v  a2s  .co  m*/
    item.setStatus(Iteration.IterationStatus.CREATED.getValue());
    item.setCreatorId(sessionService.getCurrentUser().getId());
    item.setCreatorAvatar(sessionService.getCurrentUser().getAvatar());
    item.setCreatorName(sessionService.getCurrentUser().getUsername());
    return item;
}

From source file:com.onboard.service.collaboration.impl.IterationServiceImpl.java

License:Apache License

@Override
public Iteration updateSelective(Iteration item) {
    if (item == null || item.getId() == null) {
        return null;
    }//from w  w  w.jav  a2  s  . co  m
    Iteration original = iterationMapper.selectByPrimaryKey(item.getId());
    if (item.getEndTime() != null) {
        DateTime dt = new DateTime(item.getEndTime());
        item.setEndTime(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate());
    }
    if (isCompleteIteration(original, item)) {
        // 
        item.setEndTime(new Date());
        addNewIterationForProject(item, projectService.getById(original.getProjectId()));
    }
    item.setUpdated(new Date());
    iterationMapper.updateByPrimaryKeySelective(item);
    return item;
}

From source file:com.onboard.service.collaboration.impl.IterationServiceImpl.java

License:Apache License

@Override
public Iteration addNewIterationForProject(Project project) {
    DateTime now = DateTime.now();
    Iteration iteration = new Iteration();
    iteration.setCompanyId(project.getCompanyId());
    iteration.setDeleted(false);//  w  w w  . ja  v  a2s. c  o m
    iteration.setCreated(new Date());
    iteration.setUpdated(new Date());
    iteration.setCreatorId(-1);
    iteration.setEndTime(now.withTimeAtStartOfDay().plusDays(7).plusSeconds(-1).toDate());
    iteration.setProjectId(project.getId());
    iteration.setStartTime(now.withTimeAtStartOfDay().toDate());
    iteration.setStatus(IterationStatus.CREATED.getValue());
    iteration.setCreatorAvatar(sessionService.getCurrentUser().getAvatar());
    iteration.setCreatorId(sessionService.getCurrentUser().getId());
    iteration.setCreatorName(sessionService.getCurrentUser().getName());
    iterationMapper.insert(iteration);
    return iteration;
}