List of usage examples for org.joda.time DateTime withTimeAtStartOfDay
public DateTime withTimeAtStartOfDay()
From source file:com.onboard.service.collaboration.impl.StepServiceImpl.java
License:Apache License
@Override public Step updateSelective(Step item) { Step old = getById(item.getId());/*from w w w . jav a 2 s. co m*/ Date now = new Date(); item.setUpdatedTime(now); if (!item.getDueDate().equals(old.getDueDate())) { DateTime dt = new DateTime(item.getDueDate()); item.setDueDate(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate()); } if (item.getStatus() != null && !item.getStatus().equals(old.getStatus())) { if (item.getStatus().equals(IterationItemStatus.CLOSED.getValue())) { item.setCompletedTime(now); item.setCompleterId(sessionService.getCurrentUser().getId()); if (item.getAssigneeId() != null) { keywordService.addKeywordToUser(item, item.getAssigneeId()); } } } stepMapper.updateByPrimaryKeySelective(item); return item; }
From source file:com.onboard.service.collaboration.impl.StepServiceImpl.java
License:Apache License
@Override public List<Step> getCompletedStepsBetweenDates(Integer companyId, Date since, Date until) { Step sample = new Step(); sample.setCompanyId(companyId);/* w w w . j a v a 2s. c o m*/ sample.setStatus(IterationItemStatus.CLOSED.getValue()); StepExample example = new StepExample(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<Step> results = stepMapper.selectByExample(example); for (Step step : results) { step.setProject(projectService.getById(step.getProjectId())); } return results; }
From source file:com.onboard.service.collaboration.impl.TodoServiceImpl.java
License:Apache License
@Override public Todo create(Todo todo) { Date now = new Date(); todo.setCreated(now);//from www .ja v a2 s . co m todo.setUpdated(now); todo.setDeleted(false); todo.setCompleted(false); todo.setStatus(IterationItemStatus.TODO.getValue()); todo.setDoing(false); todo.setProjectTodoId(idInProjectService.getNextIdByProjectId(todo.getProjectId())); todo.setCreatorAvatar(sessionService.getCurrentUser().getAvatar()); todoMapper.insert(todo); if (todo.getAssigneeId() != null) { todo.setSubscribers(new ArrayList<User>(Arrays.asList(userService.getById(todo.getAssigneeId())))); } if (todo.getDueDate() != null) { DateTime dt = new DateTime(todo.getDueDate()); todo.setDueDate(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate()); } subscriberService.generateSubscribers(todo, userService.getById(todo.getCreatorId())); subscriberService.addSubscribers(todo); keywordService.generateOrUpdateKeywordsByIdentifiable(todo); return todo; }
From source file:com.onboard.service.collaboration.impl.TodoServiceImpl.java
License:Apache License
@Override public Todo updateTodoAssigneeAndDueDate(Todo todo) { Todo original = new Todo(todoMapper.selectByPrimaryKey(todo.getId())); if (todo.getDueDate() != null) { DateTime dt = new DateTime(todo.getDueDate()); original.setDueDate(dt.withTimeAtStartOfDay().plusDays(1).plusSeconds(-1).toDate()); } else {// w ww .j a va 2 s .com original.setDueDate(null); } original.setAssigneeId(todo.getAssigneeId()); // todocontent?todo???content??content if (todo.getContent() != null) { original.setContent(todo.getContent()); } todoMapper.updateByPrimaryKey(original); if (todo.getAssigneeId() != null) { Subscriber subscriber = new Subscriber(); subscriber.setCompanyId(original.getCompanyId()); subscriber.setSubscribeId(original.getId()); subscriber.setSubscribeType(todo.getType()); subscriber.setUserId(todo.getAssigneeId()); subscriberService.createSubscriber(subscriber); } return todo; }
From source file:com.onboard.service.collaboration.impl.TodoServiceImpl.java
License:Apache License
@Override public List<Todo> getCompletedTodoByTimeRangeProject(Date start, Date end, int projectId) { DateTime dt = new DateTime(start); start = dt.withTimeAtStartOfDay().toDate(); if (end == null) { dt = new DateTime(new Date()); } else {/*w w w . j a v a 2 s . co m*/ dt = new DateTime(end); } end = dt.withTimeAtStartOfDay().plusDays(1).toDate(); Todo todo = new Todo(false); todo.setProjectId(projectId); todo.setStatus(IterationItemStatus.CLOSED.getValue()); TodoExample example = new TodoExample(todo); Criteria criteria = example.getOredCriteria().get(0); if (criteria == null) { example.or().andUpdatedBetween(start, end); } else { criteria.andUpdatedBetween(start, end); } return todoMapper.selectByExample(example); }
From source file:com.onboard.service.collaboration.impl.TodoServiceImpl.java
License:Apache License
@Override public List<Todo> getCompletedTodosBetweenDates(Integer companyId, Date since, Date until) { Todo sample = new Todo(); sample.setCompanyId(companyId);/*from w w w. j a v a2 s . c o m*/ sample.setStatus("closed"); TodoExample example = new TodoExample(sample); DateTime dt = new DateTime(since); since = dt.withTimeAtStartOfDay().toDate(); dt = new DateTime(until); until = dt.withTimeAtStartOfDay().plusDays(1).toDate(); example.getOredCriteria().get(0).andUpdatedGreaterThanOrEqualTo(since).andUpdatedLessThan(until); List<Todo> results = todoMapper.selectByExample(example); for (Todo todo : results) { todo.setProject(projectService.getById(todo.getProjectId())); } return results; }
From source file:com.pandits.opensource.JodaTimeUtil.java
License:Open Source License
public Date retrogressToThisDayMidnight(Date date) { DateTime dateTime = createDateTime(date); return dateTime.withTimeAtStartOfDay().toDate(); }
From source file:com.pandits.opensource.JodaTimeUtil.java
License:Open Source License
public Date advanceToNextDayMidnight(Date date) { DateTime dateTime = createDateTime(date); DateTime nextDayMidnight = dateTime.withTimeAtStartOfDay().plusDays(1); return nextDayMidnight.toDate(); }
From source file:com.qcadoo.mes.basic.shift.Shift.java
License:Open Source License
private DateRange buildDateRangeFrom(final TimeRange timeRange, final Date date) { DateTime dateTime = new DateTime(date); DateTime midnight = dateTime.withTimeAtStartOfDay(); DateTime from;//from w w w . ja v a2s . c o m DateTime to; if (timeRange.startsDayBefore()) { if (dateTime.toLocalTime().isBefore(timeRange.getFrom())) { from = timeRange.getFrom().toDateTime(midnight.minusDays(1)); to = timeRange.getTo().toDateTime(midnight); } else { from = timeRange.getFrom().toDateTime(midnight); to = timeRange.getTo().toDateTime(midnight.plusDays(1)); } } else { from = timeRange.getFrom().toDateTime(midnight); to = timeRange.getTo().toDateTime(midnight); } return new DateRange(from.toDate(), to.toDate()); }
From source file:com.ro.ssc.app.client.service.impl.DataProviderImplHelper.java
public static List<DailyData> getListPerDay(Map<String, User> userData, LocalTime time, Map<String, Map<String, ShiftData>> shiftData, Set<String> excludedGates, String userName, DateTime iniDate, DateTime endDate) { List<DailyData> result = new ArrayList(); Collections.sort(userData.get(userName).getEvents(), (c1, c2) -> c1.getEventDateTime().compareTo(c2.getEventDateTime())); Map<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> eventsPerDay; Map<DateTime, List<Event>> wrongPerDay; Set<String> usedDates = new HashSet<>(); String userId = userData.get(userName).getUserId().trim(); if (Configuration.IS_EXPIRED.getAsBoolean()) { eventsPerDay = splitPerDay(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } else {/* w ww.java2 s .co m*/ eventsPerDay = splitPerDay(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(0), iniDate, endDate); wrongPerDay = splitPerDayWrong(time, applyExcludeLogic2(excludedGates, userData.get(userName).getEvents()).get(1), iniDate, endDate); } for (DateTime date = iniDate.withTimeAtStartOfDay(); date .isBefore(endDate.plusDays(1).withTimeAtStartOfDay()); date = date.plusDays(1)) { final DateTime currentDateAsDateTime = date; for (Map.Entry<Pair<DateTime, DateTime>, List<Pair<Event, Event>>> entry : eventsPerDay.entrySet()) { if (entry.getKey().getKey().withTimeAtStartOfDay().isEqual(currentDateAsDateTime)) { Long duration = 0l; for (Pair<Event, Event> pair : entry.getValue()) { duration = duration + pair.getValue().getEventDateTime().getMillis() - pair.getKey().getEventDateTime().getMillis(); } Long pause = entry.getKey().getValue().getMillis() - entry.getKey().getKey().getMillis() - duration; Long overtime = 0l; Long latetime = 0l; Long earlytime = 0l; if (shiftData.containsKey(userId)) { final Map<String, ShiftData> shiftDataMapForUser = shiftData.get(userId); if (shiftDataMapForUser.containsKey(currentDateAsDateTime.toString(dtf3))) { ShiftData shiftDataInCurrentDate = shiftDataMapForUser .get(currentDateAsDateTime.toString(dtf3)); if (shiftDataInCurrentDate.getShiftId().equals("0")) { if (shiftDataInCurrentDate.isHasOvertime()) { overtime = duration; } } else { LocalTime officialStart = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime .from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (shiftDataInCurrentDate.isHasOvertime()) { if (pause > dailyPause) { overtime = duration - dailyHours + dailyPause; } else { overtime = duration + pause - dailyHours; duration = duration - (dailyPause - pause) > 0 ? duration - (dailyPause - pause) : 0; pause = dailyPause; } log.debug(userName + " data " + currentDateAsDateTime.toString(dtf3) + " overtime " + overtime); } else { if (duration < dailyHours - dailyPause) { overtime = duration - dailyHours + dailyPause; } } earlytime = entry.getKey().getValue().getSecondOfDay() < officialEnd.toSecondOfDay() ? 1000 * (officialEnd.toSecondOfDay() - entry.getKey().getValue().getSecondOfDay()) : 0l; latetime = entry.getKey().getKey().getSecondOfDay() > officialStart.toSecondOfDay() ? 1000 * (entry.getKey().getKey().getSecondOfDay() - officialStart.toSecondOfDay()) : 0l; } } } result.add(new DailyData(userId, date, entry.getKey().getKey().toString(dtf), entry.getKey().getValue().toString(dtf), earlytime, duration, duration, pause, overtime, latetime, wrongPerDay.get(currentDateAsDateTime))); usedDates.add(currentDateAsDateTime.toString(dtf3)); } } } for (String day : getNeededPresence(userData, shiftData, userName, iniDate, endDate)) { if (!usedDates.contains(day)) { ShiftData shiftDataInCurrentDate = shiftData.get(userId).get(day); LocalTime officialStart = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftStartHour())); LocalTime officialEnd = LocalTime.from(dtf4.parse(shiftDataInCurrentDate.getShiftEndHour())); long dailyPause = Long.valueOf(shiftDataInCurrentDate.getShiftBreakTime()) * 1000 * 60l; long dailyHours = officialEnd.isAfter(officialStart) ? 1000 * (officialEnd.toSecondOfDay() - officialStart.toSecondOfDay()) : 1000 * (officialEnd.toSecondOfDay() + (24 * 60 * 60 - officialStart.toSecondOfDay())); if (wrongPerDay.containsKey(DateTime.parse(day, dtf3))) { if (wrongPerDay.get(DateTime.parse(day, dtf3)).size() > 0) { String ev = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getEventDateTime() .toString(dtf); Boolean isIn = wrongPerDay.get(DateTime.parse(day, dtf3)).get(0).getAddr().contains("In"); result.add(new DailyData(userId, DateTime.parse(day, dtf3), isIn == true ? ev : "", isIn == false ? ev : "", 0, 0, 0, 0, dailyPause - dailyHours, 0, wrongPerDay.get(DateTime.parse(day, dtf3)))); } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } else { result.add(new DailyData(userId, DateTime.parse(day, dtf3), "", "", 0, 0, 0, 0, dailyPause - dailyHours, 0, new ArrayList<>())); } } } return result; }