List of usage examples for org.joda.time DateTime toDateTime
public DateTime toDateTime()
this
. From source file:app.action.generate.ProjectsAction.java
public String index() throws Exception { fairy = Fairy.create();/* w ww . ja v a 2 s.co m*/ // ** GENERATE PROJECTS ** // List<Lecturer> lecturers = DB.getInstance().createNamedQuery("Lecturer.findAll").getResultList(); List<Student> students = DB.getInstance().createNamedQuery("Student.findAll").getResultList(); List<Specialization> specs = DB.getInstance().createNamedQuery("Specialization.findAll").getResultList(); for (int i = 0; i < 50; i++) { Project p = new Project(); p.setLecturerId(lecturers.get(ThreadLocalRandom.current().nextInt(0, lecturers.size()))); p.setSpecId(specs.get(ThreadLocalRandom.current().nextInt(0, specs.size()))); p.setProjectTitle(fairy.textProducer().sentence()); StringBuilder content = new StringBuilder(); int randPara = ThreadLocalRandom.current().nextInt(2, 6); for (int j = 0; j < randPara; j++) { content.append(fairy.textProducer().paragraph() + "\n\n"); } p.setProjectDescription(content.toString()); DateTime duedate = fairy.dateProducer().randomDateBetweenTwoDates(DateTime.now().minusWeeks(1), DateTime.now().plusWeeks(5)); p.setDueDate(duedate.toDate()); p.setStartDate(fairy.dateProducer() .randomDateBetweenTwoDates(DateTime.now().minusWeeks(6), DateTime.now().minusWeeks(1)) .toDate()); if (duedate.isAfterNow()) { String status = PROJECT_STATUS[ThreadLocalRandom.current().nextInt(2, 5)]; DateTime subDate = fairy.dateProducer().randomDateBetweenTwoDates(duedate.minusWeeks(1), duedate.toDateTime()); if (status.equals("EVALUATED")) { p.setStudentId(students.get(ThreadLocalRandom.current().nextInt(0, students.size()))); p.setEvaComment(fairy.textProducer().latinSentence()); p.setProjectGrade(PROJECT_GRADE[ThreadLocalRandom.current().nextInt(0, PROJECT_GRADE.length)]); p.setSubDate(subDate.toDate()); } else if (status.equals("SUBMITTED")) { p.setStudentId(students.get(ThreadLocalRandom.current().nextInt(0, students.size()))); p.setSubDate(subDate.toDate()); } } else { String status = PROJECT_STATUS[ThreadLocalRandom.current().nextInt(0, 2)]; if (status.equals("ASSIGNED")) { p.setStudentId(students.get(ThreadLocalRandom.current().nextInt(0, students.size()))); } } // roughly 10% chance a project is inactive: if (ThreadLocalRandom.current().nextInt(1, 11) == 5) { p.setProjectActive(false); } DB.getInstance().persist(p); } return SUCCESS; }
From source file:auditonlybank.util.DateUtils.java
License:Apache License
public static Timestamp parseFull(String dateTimeString) { DateTime dateTime = DATE_TIME_FORMATTER_FULL.parseDateTime(dateTimeString); return new Timestamp(dateTime.toDateTime().getMillis()); }
From source file:auditonlybank.util.DateUtils.java
License:Apache License
public static Timestamp parse(String dateTimeString) { DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); return new Timestamp(dateTime.toDateTime().getMillis()); }
From source file:bitemporalbank.web.CustomerResource.java
License:Apache License
private Timestamp parse(String dateTimeString) { DateTime dateTime = DATE_TIME_FORMATTER.parseDateTime(dateTimeString); return new Timestamp(dateTime.toDateTime().getMillis()); }
From source file:br.com.caelum.vraptor.converter.jodatime.DateTimeConverter.java
License:Open Source License
public DateTime convert(String value, Class<? extends DateTime> type, ResourceBundle bundle) { try {//from w w w . j av a2s .c o m DateTime out = new LocaleBasedJodaTimeConverter(localization).convert(value, shortDateTime()); if (out == null) { return null; } return out.toDateTime(); } catch (Exception e) { throw new ConversionError(MessageFormat.format(bundle.getString("is_not_a_valid_datetime"), value)); } }
From source file:com.bl.rekweb.ku.group2.web.controller.MainController.java
License:Open Source License
private Date jodaToSQLDate(DateTime dateTime) { return new Date(dateTime.toDateTime().getMillis()); }
From source file:com.esofthead.mycollab.common.service.ibatis.TimelineTrackingServiceImpl.java
License:Open Source License
@Override public Map<String, List<GroupItem>> findTimelineItems(String fieldGroup, List<String> groupVals, Date start, Date end, TimelineTrackingSearchCriteria criteria) { try {//from w ww .j a v a2 s . c om DateTime startDate = new DateTime(start); final DateTime endDate = new DateTime(end); if (startDate.isAfter(endDate)) { throw new UserInvalidInputException("Start date must be greater than end date"); } List<Date> dates = boundDays(startDate, endDate.minusDays(1)); Map<String, List<GroupItem>> items = new HashMap<>(); criteria.setFieldgroup(StringSearchField.and(fieldGroup)); List<GroupItem> cacheTimelineItems = timelineTrackingCachingMapperExt.findTimelineItems(groupVals, dates, criteria); DateTime calculatedDate = startDate.toDateTime(); if (cacheTimelineItems.size() > 0) { GroupItem item = cacheTimelineItems.get(cacheTimelineItems.size() - 1); String dateValue = item.getGroupname(); calculatedDate = DateTime.parse(dateValue, DateTimeFormat.forPattern("yyyy-MM-dd")); for (GroupItem map : cacheTimelineItems) { String groupVal = map.getGroupid(); Object obj = items.get(groupVal); if (obj == null) { List<GroupItem> itemLst = new ArrayList<>(); itemLst.add(map); items.put(groupVal, itemLst); } else { List<GroupItem> itemLst = (List<GroupItem>) obj; itemLst.add(map); } } } dates = boundDays(calculatedDate.plusDays(1), endDate); if (dates.size() > 0) { boolean isValidForBatchSave = true; final String type = criteria.getType().getValue(); SetSearchField<Integer> extraTypeIds = criteria.getExtraTypeIds(); Integer tmpExtraTypeId = null; if (extraTypeIds != null) { if (extraTypeIds.getValues().size() == 1) { tmpExtraTypeId = extraTypeIds.getValues().iterator().next(); } else { isValidForBatchSave = false; } } final Integer extraTypeId = tmpExtraTypeId; final List<Map> timelineItems = timelineTrackingMapperExt.findTimelineItems(groupVals, dates, criteria); if (isValidForBatchSave) { final Integer sAccountId = (Integer) criteria.getSaccountid().getValue(); final String itemFieldGroup = criteria.getFieldgroup().getValue(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); final List<Map> filterCollections = new ArrayList<>( Collections2.filter(timelineItems, new Predicate<Map>() { @Override public boolean apply(Map input) { String dateStr = (String) input.get("groupname"); DateTime dt = formatter.parseDateTime(dateStr); return !dt.equals(endDate); } })); jdbcTemplate.batchUpdate( "INSERT INTO `s_timeline_tracking_cache`(type, fieldval,extratypeid,sAccountId," + "forDay, fieldgroup,count) VALUES(?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement preparedStatement, int i) throws SQLException { Map item = filterCollections.get(i); preparedStatement.setString(1, type); String fieldVal = (String) item.get("groupid"); preparedStatement.setString(2, fieldVal); preparedStatement.setInt(3, extraTypeId); preparedStatement.setInt(4, sAccountId); String dateStr = (String) item.get("groupname"); DateTime dt = formatter.parseDateTime(dateStr); preparedStatement.setDate(5, new java.sql.Date(dt.toDate().getTime())); preparedStatement.setString(6, itemFieldGroup); int value = ((BigDecimal) item.get("value")).intValue(); preparedStatement.setInt(7, value); } @Override public int getBatchSize() { return filterCollections.size(); } }); } for (Map map : timelineItems) { String groupVal = (String) map.get("groupid"); GroupItem item = new GroupItem(); item.setValue(((BigDecimal) map.get("value")).doubleValue()); item.setGroupid((String) map.get("groupid")); item.setGroupname((String) map.get("groupname")); Object obj = items.get(groupVal); if (obj == null) { List<GroupItem> itemLst = new ArrayList<>(); itemLst.add(item); items.put(groupVal, itemLst); } else { List<GroupItem> itemLst = (List<GroupItem>) obj; itemLst.add(item); } } } return items; } catch (Exception e) { LOG.error("Error", e); return null; } }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private SignalTimeHolder getNextTimeForFixedType(SignalTime signalTime, List<SignalTimeHolder> previousTimes, DateTime nowMidnight) { if (previousTimes.size() == 0 || signalTime.getMissedBasisBehavior() == SignalTimeDAO.MISSED_BEHAVIOR_USE_SCHEDULED_TIME) { return new SignalTimeHolder(null, null, nowMidnight.toDateTime().plusMillis(signalTime.getFixedTimeMillisFromMidnight()), signalTime); } else if (signalTime.getMissedBasisBehavior() == SignalTimeDAO.MISSED_BEHAVIOR_SKIP && previousEventHasResponse(previousTimes)) { return new SignalTimeHolder(null, null, nowMidnight.toDateTime().plusMillis(signalTime.getFixedTimeMillisFromMidnight()), signalTime); } else {// www. j ava2s .c om return createNullSignalTimeHolder(signalTime); } }
From source file:com.money.manager.ex.sync.SyncSchedulerBroadcastReceiver.java
License:Open Source License
private void startHeartbeat(Context context, AlarmManager alarmManager, PendingIntent pendingIntent) { SyncManager sync = new SyncManager(context); if (!sync.isSyncEnabled()) return;/*from w ww .j av a 2 s . com*/ // get frequency in minutes. SyncPreferences preferences = new SyncPreferences(context); int minutes = preferences.getSyncInterval(); // If the period is 0, do not schedule the alarm. if (minutes <= 0) return; DateTime now = DateTime.now(); int secondsInMinute = 60; Timber.d("Scheduling synchronisation at: %s, repeat every %s minutes", now.toString(), minutes); // Schedule the alarm for synchronization. Run immediately and then in the given interval. alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, now.toDateTime().getMillis(), minutes * secondsInMinute * 1000, pendingIntent); }
From source file:com.mycollab.common.service.impl.TimelineTrackingServiceImpl.java
License:Open Source License
@Override public Map<String, List<GroupItem>> findTimelineItems(String fieldGroup, List<String> groupVals, Date start, Date end, TimelineTrackingSearchCriteria criteria) { try {//from w w w. j a v a2 s . c o m DateTime startDate = new DateTime(start); final DateTime endDate = new DateTime(end); if (startDate.isAfter(endDate)) { throw new UserInvalidInputException("Start date must be greaterThan than end date"); } List<Date> dates = boundDays(startDate, endDate.minusDays(1)); Map<String, List<GroupItem>> items = new HashMap<>(); criteria.setFieldgroup(StringSearchField.and(fieldGroup)); List<GroupItem> cacheTimelineItems = timelineTrackingCachingMapperExt.findTimelineItems(groupVals, dates, criteria); DateTime calculatedDate = startDate.toDateTime(); if (cacheTimelineItems.size() > 0) { GroupItem item = cacheTimelineItems.get(cacheTimelineItems.size() - 1); String dateValue = item.getGroupname(); calculatedDate = DateTime.parse(dateValue, DateTimeFormat.forPattern("yyyy-MM-dd")); for (GroupItem map : cacheTimelineItems) { String groupVal = map.getGroupid(); Object obj = items.get(groupVal); if (obj == null) { List<GroupItem> itemLst = new ArrayList<>(); itemLst.add(map); items.put(groupVal, itemLst); } else { List<GroupItem> itemLst = (List<GroupItem>) obj; itemLst.add(map); } } } dates = boundDays(calculatedDate.plusDays(1), endDate); if (dates.size() > 0) { boolean isValidForBatchSave = true; final Set<String> types = criteria.getTypes().getValues(); SetSearchField<Integer> extraTypeIds = criteria.getExtraTypeIds(); Integer tmpExtraTypeId = null; if (extraTypeIds != null) { if (extraTypeIds.getValues().size() == 1) { tmpExtraTypeId = extraTypeIds.getValues().iterator().next(); } else { isValidForBatchSave = false; } } final Integer extraTypeId = tmpExtraTypeId; final List<Map> timelineItems = timelineTrackingMapperExt.findTimelineItems(groupVals, dates, criteria); if (isValidForBatchSave) { final Integer sAccountId = (Integer) criteria.getSaccountid().getValue(); final String itemFieldGroup = criteria.getFieldgroup().getValue(); JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource); final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd"); final List<Map> filterCollections = new ArrayList<>( Collections2.filter(timelineItems, input -> { String dateStr = (String) input.get("groupname"); DateTime dt = formatter.parseDateTime(dateStr); return !dt.equals(endDate); })); jdbcTemplate.batchUpdate( "INSERT INTO `s_timeline_tracking_cache`(type, fieldval,extratypeid,sAccountId," + "forDay, fieldgroup,count) VALUES(?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() { @Override public void setValues(PreparedStatement preparedStatement, int i) throws SQLException { Map item = filterCollections.get(i); // preparedStatement.setString(1, types); String fieldVal = (String) item.get("groupid"); preparedStatement.setString(2, fieldVal); preparedStatement.setInt(3, extraTypeId); preparedStatement.setInt(4, sAccountId); String dateStr = (String) item.get("groupname"); DateTime dt = formatter.parseDateTime(dateStr); preparedStatement.setDate(5, new java.sql.Date(dt.toDate().getTime())); preparedStatement.setString(6, itemFieldGroup); int value = ((BigDecimal) item.get("value")).intValue(); preparedStatement.setInt(7, value); } @Override public int getBatchSize() { return filterCollections.size(); } }); } for (Map map : timelineItems) { String groupVal = (String) map.get("groupid"); GroupItem item = new GroupItem(); item.setValue(((BigDecimal) map.get("value")).doubleValue()); item.setGroupid((String) map.get("groupid")); item.setGroupname((String) map.get("groupname")); Object obj = items.get(groupVal); if (obj == null) { List<GroupItem> itemLst = new ArrayList<>(); itemLst.add(item); items.put(groupVal, itemLst); } else { List<GroupItem> itemLst = (List<GroupItem>) obj; itemLst.add(item); } } } return items; } catch (Exception e) { LOG.error("Error", e); return null; } }