List of usage examples for org.joda.time DateTime plusHours
public DateTime plusHours(int hours)
From source file:com.github.terma.gigaspacewebconsole.provider.executor.gigaspace.TimestampPreprocessor.java
License:Apache License
private String timestampString(Matcher matcher, final DateTime timestamp) { final int sign = matcher.group(1).equals("-") ? -1 : 1; final int quantity = sign * Integer.parseInt(matcher.group(2)); final String type = matcher.group(3); DateTime updatedTimestamp;/*from w ww.j a va 2 s . com*/ switch (type) { case "h": updatedTimestamp = timestamp.plusHours(quantity); break; case "d": updatedTimestamp = timestamp.plusDays(quantity); break; case "w": updatedTimestamp = timestamp.plusWeeks(quantity); break; default: throw new IllegalArgumentException(); } return Long.toString(updatedTimestamp.getMillis()); }
From source file:com.google.android.apps.paco.ServerCommunication.java
License:Open Source License
private void setNextWakeupTime() { DateTime nextServerCommunicationTime = new DateTime(userPrefs.getNextServerCommunicationServiceAlarmTime()); if (isInFuture(nextServerCommunicationTime)) { return;/* w ww . jav a2 s .co m*/ } DateTime nextCommTime = nextServerCommunicationTime.plusHours(24); if (nextCommTime.isBeforeNow() || nextCommTime.isEqualNow()) { nextCommTime = new DateTime().plusHours(24); } Intent ultimateIntent = new Intent(context, ServerCommunicationService.class); ultimateIntent.setData(CONTENT_URI); PendingIntent intent = PendingIntent.getService(context.getApplicationContext(), 0, ultimateIntent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.cancel(intent); alarmManager.set(AlarmManager.RTC_WAKEUP, nextCommTime.getMillis(), intent); userPrefs.setNextServerCommunicationServiceAlarmTime(nextCommTime.getMillis()); Log.i(PacoConstants.TAG, "Created alarm for ServerCommunicationService. Time: " + nextCommTime.toString()); }
From source file:com.google.samples.apps.iosched.explore.ExploreSessionsFragment.java
License:Open Source License
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { DateTimeFormatter formatter = DateTimeFormat.forPattern("E dd.MMMM yyyy"); DateTime dateToUse = null; DateTime startDate = null;/*from ww w. java 2s. co m*/ DateTime endDate = null; if (mSessionDate != null) { dateToUse = formatter.parseDateTime(mSessionDate); startDate = dateToUse.plusHours(0); endDate = dateToUse.plusHours(23); } switch (id) { case ExploreSessionsQuery.NORMAL_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.NORMAL_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case ExploreSessionsQuery.SEARCH_TOKEN: return new CursorLoader(getActivity(), mCurrentUri, ExploreSessionsQuery.SEARCH_PROJECTION, mSessionDate != null ? ScheduleContract.Sessions.STARTING_AT_TIME_INTERVAL_SELECTION : null, mSessionDate != null ? new String[] { startDate.getMillis() + "", endDate.getMillis() + "" } : null, ScheduleContract.Sessions.SORT_BY_TYPE_THEN_TIME); case TAG_METADATA_TOKEN: return TagMetadata.createCursorLoader(getActivity()); default: return null; } }
From source file:com.indeed.imhotep.builder.tsv.TsvConverter.java
License:Apache License
public static ShardInfo.DateTimeRange parseDateTime(String shardId) { try {/* w w w . j a va 2 s .com*/ if (shardId.length() > 16) { final DateTime start = yyyymmddhh.parseDateTime(shardId.substring(5, 16)); final DateTime end = yyyymmddhh.parseDateTime(shardId.substring(17, 28)); return new ShardInfo.DateTimeRange(start, end); } else if (shardId.length() > 13) { final DateTime start = yyyymmddhh.parseDateTime(shardId.substring(5, 16)); final DateTime end = start.plusHours(1); return new ShardInfo.DateTimeRange(start, end); } else { final DateTime start = yyyymmdd.parseDateTime(shardId.substring(5, 13)); final DateTime end = start.plusDays(1); return new ShardInfo.DateTimeRange(start, end); } } catch (Exception e) { throw new RuntimeException("Failed to get time range from file name: " + shardId, e); } }
From source file:com.indeed.imhotep.web.TopTermsCache.java
License:Apache License
private Map<String, Map<String, List<String>>> updateTopTermsFromImhotep() { final Map<String, Map<String, List<String>>> newDatasetToFieldToTerms = Maps.newHashMap(); final DateTime startTime = DateTime.now().minusDays(DAYS_DELAY).withTimeAtStartOfDay().plusHours(12); final DateTime endTime = startTime.plusHours(1); for (final DatasetMetadata datasetMetadata : imhotepMetadataCache.getDatasets().values()) { final String dataset = datasetMetadata.getName(); long started = System.currentTimeMillis(); final Map<String, List<String>> fieldToTerms = Maps.newHashMap(); final ImhotepSession imhotepSession; try {/* ww w .j ava 2s . c o m*/ final ImhotepClient.SessionBuilder sessionBuilder = client .sessionBuilder(dataset, startTime, endTime).username("IQL: topterms"); if (sessionBuilder.getChosenShards().size() == 0) { log.info("Index " + dataset + " has no shards for midday " + DAYS_DELAY + " days ago"); continue; } imhotepSession = sessionBuilder.build(); } catch (Exception e) { log.warn("Failed to create a session for " + dataset + " " + startTime + " - " + endTime); continue; } for (FieldMetadata fieldMetadata : datasetMetadata.getFields().values()) { if (fieldMetadata.getType() != FieldType.String) { continue; // we are trying to get some values for enum like string fields. can skip the random integer values } final String field = fieldMetadata.getName(); final List<TermCount> termCounts = imhotepSession.approximateTopTerms(field, false, TERMS_TO_CACHE); if (termCounts.size() == 0) { log.debug(dataset + "." + field + " has no terms"); } final List<String> terms = Lists.newArrayList(); for (TermCount termCount : termCounts) { terms.add(termCount.getTerm().getTermStringVal()); } fieldToTerms.put(field, terms); } if (fieldToTerms.size() > 0) { newDatasetToFieldToTerms.put(dataset, fieldToTerms); } long tookSeconds = (System.currentTimeMillis() - started) / 1000; if (tookSeconds > 1) { log.debug("TopTerms for " + dataset + " loaded in " + tookSeconds + "s"); } } return newDatasetToFieldToTerms; }
From source file:com.marand.thinkmed.medications.administration.impl.AdministrationTaskCreatorImpl.java
License:Open Source License
private Pair<DateTime, TherapyDoseDto> getNextAdministrationTimeWithDoseForFrequencyBetweenDoses( final AdministrationTaskCreateActionEnum action, final DateTime therapyStart, final DateTime fromTime, final HourMinuteDto administrationTime, final TherapyDoseDto dose, final int hoursBetweenDoses, final boolean fromTimeIncluded) { DateTime foundTime; if (action == AdministrationTaskCreateActionEnum.PRESET_TIME_ON_NEW_PRESCRIPTION) { foundTime = fromTime.withTimeAtStartOfDay().plusHours(administrationTime.getHour()) .plusMinutes(administrationTime.getMinute()); if (hoursBetweenDoses >= 24) { while (foundTime.isBefore(fromTime) || (foundTime.equals(fromTime) && !fromTimeIncluded)) { foundTime = foundTime.plusDays(1); }//ww w . ja v a2s .c om return Pair.of(foundTime, dose); } } else { foundTime = therapyStart; } while (foundTime.isBefore(fromTime) || (foundTime.equals(fromTime) && !fromTimeIncluded)) { foundTime = foundTime.plusHours(hoursBetweenDoses); } return Pair.of(foundTime, dose); }
From source file:com.marand.thinkmed.medications.process.impl.TherapyTaskCreatorImpl.java
License:Open Source License
private DateTime getNextAdministrationTime(final DateTime fromTime, final List<HourMinuteDto> possibleAdministrations, final DosingFrequencyDto dosingFrequency) { if (dosingFrequency.getType() == DosingFrequencyTypeEnum.ONCE_THEN_EX) { return fromTime; }/*from w w w. j a va2 s. c o m*/ if (dosingFrequency.getType() == DosingFrequencyTypeEnum.BETWEEN_DOSES) { final Integer betweenDoses = dosingFrequency.getValue(); return fromTime.plusHours(betweenDoses); } if (!possibleAdministrations.isEmpty()) { return getNextAdministrationTime(fromTime, possibleAdministrations); } throw new IllegalArgumentException("Cannot calculate next administration timestamp for dosingFrequency: " + dosingFrequency + " and possibleAdministrations size: " + possibleAdministrations.size()); }
From source file:com.ning.arecibo.collector.persistent.TimelineLoadGenerator.java
License:Apache License
/** * This method simulates adding a ton of timelines, in more-or-less the way they would be added in real life. *///from w w w. ja v a 2 s . c o m private void insertManyTimelines() throws Exception { final List<TimelineChunk> timelineChunkList = new ArrayList<TimelineChunk>(); DateTime startTime = new DateTime().minusDays(1); DateTime endTime = startTime.plusHours(1); final int sampleCount = 120; // 1 hours worth for (int i = 0; i < 12; i++) { for (int hostId : hostIds) { for (int categoryId : categoriesForHostId.get(hostId)) { final List<DateTime> dateTimes = new ArrayList<DateTime>(sampleCount); for (int sc = 0; sc < sampleCount; sc++) { dateTimes.add(startTime.plusSeconds(sc * 30)); } final byte[] timeBytes = timelineCoder.compressDateTimes(dateTimes); for (int sampleKindId : categorySampleKindIds.get(categoryId)) { final TimelineChunk timelineChunk = makeTimelineChunk(hostId, sampleKindId, startTime, endTime, timeBytes, sampleCount); addChunkAndMaybeSave(timelineChunkList, timelineChunk); } } } if (timelineChunkList.size() > 0) { defaultTimelineDAO.bulkInsertTimelineChunks(timelineChunkList); } log.info("After hour %d, inserted %d TimelineChunk rows", i, timelineChunkIdCounter.get()); startTime = endTime; endTime = endTime.plusHours(1); } }
From source file:com.ning.billing.meter.timeline.TimelineLoadGenerator.java
License:Apache License
/** * This method simulates adding a ton of timelines, in more-or-less the way they would be added in real life. *///from w w w.ja v a 2s . c o m private void insertManyTimelines() throws Exception { final List<TimelineChunk> timelineChunkList = new ArrayList<TimelineChunk>(); DateTime startTime = new DateTime().minusDays(1); DateTime endTime = startTime.plusHours(1); final int sampleCount = 120; // 1 hours worth for (int i = 0; i < 12; i++) { for (final int hostId : hostIds) { for (final int categoryId : categoriesForHostId.get(hostId)) { final List<DateTime> dateTimes = new ArrayList<DateTime>(sampleCount); for (int sc = 0; sc < sampleCount; sc++) { dateTimes.add(startTime.plusSeconds(sc * 30)); } final byte[] timeBytes = timelineCoder.compressDateTimes(dateTimes); for (final int sampleKindId : categorySampleKindIds.get(categoryId)) { final TimelineChunk timelineChunk = makeTimelineChunk(hostId, sampleKindId, startTime, endTime, timeBytes, sampleCount); addChunkAndMaybeSave(timelineChunkList, timelineChunk); } } } if (timelineChunkList.size() > 0) { defaultTimelineDAO.bulkInsertTimelineChunks(timelineChunkList, internalCallContext); } log.info("After hour %d, inserted %d TimelineChunk rows", i, timelineChunkIdCounter.get()); startTime = endTime; endTime = endTime.plusHours(1); } }
From source file:com.nissatech.proasense.eventplayer.partnerconfigurations.HellaConfiguration.java
/** * {@inheritDoc}/*from w ww . ja va 2 s .co m*/ */ @Override public BoundStatement generateQuery(DateTime startTime, DateTime endTime, List<String> variables, CassandraClient client) { DateTime roundedStartTime = startTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); //to be sure we have the complete hour List<String> inKeys = new ArrayList<String>(); int hoursBetween = Hours.hoursBetween(roundedStartTime, endTime).getHours(); for (int i = 0; i < hoursBetween; i++) { long milliKeyPart = roundedStartTime.plusHours(i).getMillis(); for (String variable : variables) { inKeys.add(variable + "|" + milliKeyPart); } } //the ? in the prepared query is out of parenthesis for a reason. This is a deviation from the standard when using the IN keyword String query = "select * from hella_variables where type_hour_stamp in ? order by variable_timestamp"; BoundStatement statement = client.prepareStatement(query); statement.bind(inKeys); return statement; }