List of usage examples for org.joda.time DateTime withMillisOfDay
public DateTime withMillisOfDay(int millis)
From source file:com.google.android.apps.paco.EsmGenerator2.java
License:Open Source License
public List<DateTime> generateForSchedule(DateTime startDate, SignalSchedule schedule) { this.schedule = schedule; this.periodStartDate = adjustStartDateToBeginningOfPeriod(startDate); times = new ArrayList<DateTime>(); if (schedule.getEsmFrequency() == null || schedule.getEsmFrequency() == 0) { return times; }/*from ww w . j a v a2 s . com*/ List<Integer> schedulableDays; switch (schedule.getEsmPeriodInDays()) { case SignalSchedule.ESM_PERIOD_DAY: if (!schedule.getEsmWeekends() && TimeUtil.isWeekend(periodStartDate)) { return times; } else { schedulableDays = Arrays.asList(1); } break; case SignalSchedule.ESM_PERIOD_WEEK: schedulableDays = getPeriodDaysForWeek(); break; case SignalSchedule.ESM_PERIOD_MONTH: schedulableDays = getPeriodDaysForMonthOf(periodStartDate); break; default: throw new IllegalStateException("Cannot get here."); } Minutes dayLengthIntervalInMinutes = Minutes .minutesIn(new Interval(schedule.getEsmStartHour(), schedule.getEsmEndHour())); Minutes totalMinutesInPeriod = dayLengthIntervalInMinutes.multipliedBy(schedulableDays.size()); Minutes sampleBlockTimeInMinutes = totalMinutesInPeriod.dividedBy(schedule.getEsmFrequency()); Minutes timeoutInMinutes = Minutes.minutes(schedule.getMinimumBuffer()); Random rand = new Random(); for (int signal = 0; signal < schedule.getEsmFrequency(); signal++) { int candidateTimeInBlock; DateTime candidateTime; int periodAttempts = 1000; do { candidateTimeInBlock = rand.nextInt(sampleBlockTimeInMinutes.getMinutes()); // map candidatePeriod and candidateTime back onto days of period // note, sometimes a candidate period will map across days in period // because start and end hours make for non-contiguous days int totalMinutesToAdd = sampleBlockTimeInMinutes.getMinutes() * signal + candidateTimeInBlock; int daysToAdd = totalMinutesToAdd / dayLengthIntervalInMinutes.getMinutes(); int minutesToAdd = 0; if (totalMinutesToAdd <= dayLengthIntervalInMinutes.getMinutes()) { // within one day minutesToAdd = totalMinutesToAdd; } else { minutesToAdd = totalMinutesToAdd % dayLengthIntervalInMinutes.getMinutes(); } DateTime plusDays = periodStartDate.plusDays(schedulableDays.get(daysToAdd) - 1); candidateTime = plusDays.withMillisOfDay(schedule.getEsmStartHour().intValue()) .plusMinutes(minutesToAdd); periodAttempts--; } while (periodAttempts > 0 && (!isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) || (!schedule.getEsmWeekends() && TimeUtil.isWeekend(candidateTime)))); if (isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) && (schedule.getEsmWeekends() || !TimeUtil.isWeekend(candidateTime))) { times.add(candidateTime); } } return times; }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private DateTime getFirstScheduledTimeOnDay(DateTime nextDay) { return nextDay.withMillisOfDay(schedule.getSignalTimes().get(0).getFixedTimeMillisFromMidnight()); }
From source file:com.pacoapp.paco.shared.scheduling.EsmGenerator2.java
License:Open Source License
public List<DateTime> generateForSchedule(DateTime startDate, Schedule schedule2) { this.schedule = schedule2; this.periodStartDate = adjustStartDateToBeginningOfPeriod(startDate); times = new ArrayList<DateTime>(); if (schedule2.getEsmFrequency() == null || schedule2.getEsmFrequency() == 0) { return times; }//w w w .j ava 2s. co m List<Integer> schedulableDays; switch (schedule2.getEsmPeriodInDays()) { case Schedule.ESM_PERIOD_DAY: if (!schedule2.getEsmWeekends() && TimeUtil.isWeekend(periodStartDate)) { return times; } else { schedulableDays = Arrays.asList(1); } break; case Schedule.ESM_PERIOD_WEEK: schedulableDays = getPeriodDaysForWeek(); break; case Schedule.ESM_PERIOD_MONTH: schedulableDays = getPeriodDaysForMonthOf(periodStartDate); break; default: throw new IllegalStateException("Cannot get here."); } Minutes dayLengthIntervalInMinutes = Minutes .minutesIn(new Interval(schedule2.getEsmStartHour(), schedule2.getEsmEndHour())); Minutes totalMinutesInPeriod = dayLengthIntervalInMinutes.multipliedBy(schedulableDays.size()); Minutes sampleBlockTimeInMinutes = totalMinutesInPeriod.dividedBy(schedule2.getEsmFrequency()); Minutes timeoutInMinutes = Minutes.minutes(schedule2.getMinimumBuffer()); Random rand = new Random(); for (int signal = 0; signal < schedule2.getEsmFrequency(); signal++) { int candidateTimeInBlock; DateTime candidateTime; int periodAttempts = 1000; do { candidateTimeInBlock = rand.nextInt(sampleBlockTimeInMinutes.getMinutes()); // map candidatePeriod and candidateTime back onto days of period // note, sometimes a candidate period will map across days in period // because start and end hours make for non-contiguous days int totalMinutesToAdd = sampleBlockTimeInMinutes.getMinutes() * signal + candidateTimeInBlock; int daysToAdd = totalMinutesToAdd / dayLengthIntervalInMinutes.getMinutes(); int minutesToAdd = 0; if (totalMinutesToAdd <= dayLengthIntervalInMinutes.getMinutes()) { // within one day minutesToAdd = totalMinutesToAdd; } else { minutesToAdd = totalMinutesToAdd % dayLengthIntervalInMinutes.getMinutes(); } DateTime plusDays = periodStartDate.plusDays(schedulableDays.get(daysToAdd) - 1); candidateTime = plusDays.withMillisOfDay(schedule2.getEsmStartHour().intValue()) .plusMinutes(minutesToAdd); periodAttempts--; } while (periodAttempts > 0 && (!isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) || (!schedule2.getEsmWeekends() && TimeUtil.isWeekend(candidateTime)))); if (isMinimalBufferedDistanceFromOtherTimes(candidateTime, timeoutInMinutes) && (schedule2.getEsmWeekends() || !TimeUtil.isWeekend(candidateTime))) { times.add(candidateTime); } } return times; }
From source file:com.quinsoft.zeidon.domains.DateDomain.java
License:Open Source License
@Override public Object convertExternalValue(Task task, AttributeInstance attributeInstance, AttributeDef attributeDef, String contextName, Object externalValue) { DateTime dt = (DateTime) super.convertExternalValue(task, attributeInstance, attributeDef, contextName, externalValue);/*from www. j a v a2 s.c o m*/ if (dt != null) dt = dt.withMillisOfDay(0); return dt; }
From source file:eu.europa.ec.fisheries.uvms.plugins.flux.util.DateUtil.java
License:Open Source License
/** * Creates a {@link Date} from a {@link String} * * @param input A {@link String} on the format "YYYYMMDD" * @return A {@link Date} representation of date, with time set to 00:00:00 * set according to UTC timezone./*from ww w .ja v a 2s . co m*/ * @throws {@link NumberFormatException} when the input parameter isn't as * expected. */ public static Date getTimeFromString(String input) { if (input != null && !input.trim().isEmpty()) { final String pattern = "(19|20){1}\\d{6}"; if (input.length() == 8 & input.matches(pattern)) { DateTime time = new DateTime(new Integer(input.substring(0, 4)).intValue() // year , new Integer(input.substring(4, 6)).intValue() // month , new Integer(input.substring(6, 8)).intValue() // day , 0 // hour , 0 // minute , DateTimeZone.UTC); time = time.withMillisOfDay(0); return new Date(time.getMillis()); } } throw new NumberFormatException("Provided string is not parsable for a date. Received: " + input); }
From source file:gr.cti.android.experimentation.controller.api.SmartphoneController.java
License:Open Source License
private TreeSet<UsageEntry> extractUsageTimes(final Set<Result> results) { final Map<String, Long> res = new TreeMap<>(); final SortedSet<Long> timestamps = results.stream().map(Result::getTimestamp) .collect(Collectors.toCollection(TreeSet::new)); DateTime start = null; DateTime lastDay = null;//from ww w . ja v a 2s . c om for (final Long timestamp : timestamps) { final DateTime curDateTime = new DateTime(timestamp); if (start == null) { start = new DateTime(timestamp); } else { if (start.withMillisOfDay(0).getMillis() == curDateTime.withMillisOfDay(0).getMillis()) { lastDay = new DateTime(timestamp); } else { if (lastDay != null) { long diff = (lastDay.getMillis() - start.getMillis()) / 1000 / 60; res.put(dfDay.format(lastDay.withMillisOfDay(0).getMillis()), diff); } start = null; lastDay = null; } } } return res.keySet().stream().map(dateKey -> new UsageEntry(dateKey, res.get(dateKey))) .collect(Collectors.toCollection(TreeSet::new)); }
From source file:io.viewserver.adapters.csv.CsvRecordWrapper.java
License:Apache License
public CsvRecordWrapper(DateTime startTime) { super();/*from w w w.jav a 2 s . co m*/ this.startTime = startTime; this.startDate = startTime.withMillisOfDay(0); }
From source file:org.callistasoftware.netcare.core.spi.impl.HealthPlanServiceImpl.java
License:Open Source License
@Override public ServiceResult<ScheduledActivity[]> filterReportedActivities(final CareUnit careUnit, final String personnummer, final Date start, final Date end) { getLog().info("Loading a filtered out list of reported activities belonging to care unit {}", careUnit.getHsaId());/* w ww . j a va 2 s. c om*/ final CareUnitEntity entity = this.careUnitRepository.findByHsaId(careUnit.getHsaId()); if (entity == null) { ServiceResultImpl.createFailedResult(new EntityNotFoundMessage(CareUnitEntity.class, -1L)); } final PatientEntity patient = patientRepository.findByCivicRegistrationNumber(personnummer); this.verifyReadAccess(entity); Date endDate = end; if (end != null) { final DateTime e = new DateTime(end); endDate = new Date(e.withMillisOfDay(0).plusDays(1).toDate().getTime()); } getLog().info("filtered reports: pnr: {}, start: {}, end: {}, unit: \"{}\"", new Object[] { personnummer, start, endDate, entity.getHsaId() }); final List<ScheduledActivityEntity> activities; if (StringUtils.hasText(personnummer)) { activities = this.scheduledActivityRepository.findByCareUnitPatientBetween(entity.getHsaId(), patient, start, endDate); } else { activities = this.scheduledActivityRepository.findByCareUnitBetween(entity.getHsaId(), start, endDate); } getLog().info("filter reports: found {} activities", activities.size()); return ServiceResultImpl.createSuccessResult(ScheduledActivityImpl.newFromEntities(activities), new ListEntitiesMessage(ScheduledActivityEntity.class, activities.size())); }
From source file:org.callistasoftware.netcare.core.spi.impl.ScheduleServiceImpl.java
License:Open Source License
@Override public ServiceResult<ScheduledActivity[]> load(final boolean includeReported, final boolean includeDue, Long start, Long end) { if (start == null || end == null) { start = new DateTime().withMillisOfDay(0).toDate().getTime(); end = new DateTime().withMillisOfDay(0).toDate().getTime(); }//from ww w . ja v a2 s .c om final DateTime s = new DateTime(start); final DateTime e = new DateTime(end); start = s.withMillisOfDay(0).toDate().getTime(); end = e.withMillisOfDay(0).plusDays(1).toDate().getTime(); final List<ScheduledActivityEntity> list = this.repo.findByPatientAndScheduledTimeBetween(getPatient(), new Date(start), new Date(end)); final List<ScheduledActivityEntity> filtered = new ArrayList<ScheduledActivityEntity>(); getLog().debug("Query found {} in interval {} - {}", new Object[] { list.size(), new Date(start), new Date(end) }); for (final ScheduledActivityEntity sae : list) { // Ensure read access sae.isReadAllowed(getPatient()); boolean dueCheck = sae.getReportedTime() == null && sae.getStatus().equals(ScheduledActivityStatus.OPEN) && sae.getScheduledTime().before(new Date(System.currentTimeMillis())); boolean reportCheck = sae.getReportedTime() != null && (sae.getStatus().equals(ScheduledActivityStatus.OPEN) || sae.getStatus().equals(ScheduledActivityStatus.REJECTED)); getLog().debug("due check: {}, report check: {}", dueCheck, reportCheck); if ((includeDue && dueCheck) || (includeReported && reportCheck)) { filtered.add(sae); } else { boolean openCheck = includeDue && sae.getReportedTime() == null && sae.getStatus().equals(ScheduledActivityStatus.OPEN); if (openCheck) { filtered.add(sae); } } } return ServiceResultImpl.createSuccessResult(ScheduledActivityImpl.newFromEntities(filtered), new GenericSuccessMessage()); }
From source file:org.vaadin.spring.samples.mvp.util.SSTimeUtil.java
License:Apache License
/** * Get Market start time for current day (i.e., today) * * @return an org.joda.time.DateTime instance representing the current day * at midnight// w w w . j av a2s. c o m */ public static DateTime getMarketStartDateTime() { // Current market date based on now DateTime dt = new DateTime(); dt = dt.withZone(marketTimeZone); dt = dt.withMillisOfDay(0); // Set to start of day return dt; }