List of usage examples for org.joda.time DateTime withHourOfDay
public DateTime withHourOfDay(int hour)
From source file:fr.ybonnel.model.ScoreWithHistory.java
License:Apache License
private void aggregateOneTypeOfScore(DateTime now, Iterator<Score> itScores) { Set<String> hoursKept = new HashSet<>(); while (itScores.hasNext()) { Score score = itScores.next();/*from w w w . j a v a 2 s .com*/ DateTime dateTimeOfScore = new DateTime(score.getTimeOfScore()); String hourOfScore = dateTimeOfScore.toString("yyyyMMddHH"); String hoursForPast1Day = dateTimeOfScore.withHourOfDay((dateTimeOfScore.getHourOfDay() / 4) * 4) .toString("yyyyMMddHH"); if (dateTimeOfScore.compareTo(now.minusHours(2)) < 0 && hoursKept.contains(hourOfScore) || dateTimeOfScore.compareTo(now.minusDays(1)) < 0 && hoursKept.contains(hoursForPast1Day)) { itScores.remove(); } else { hoursKept.add(hourOfScore); hoursKept.add(hoursForPast1Day); } } }
From source file:fulldatechart.FullDateChart.java
License:Open Source License
public static void main(String[] args) throws IOException, ParseException, ValidationException { if (args.length != 2) { System.out.println("Usage: .../fulldatechart.jar /path/to/myfinds.gpx <myuserid>"); System.exit(1);/*from w w w . ja v a 2 s .co m*/ } File f = new File(args[0]); String ownerId = args[1]; DateTimeFormatter fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZoneUTC(); System.out.println("Parsing: " + f); Document document = Jsoup.parse(f, "UTF-8"); Set<Slot> dates = new HashSet<Slot>(); for (int i = 1; i <= 366; i++) { dates.add(new Slot(new DateTime().withYear(2012).withTimeAtStartOfDay().withDayOfYear(i))); } for (Element elem : document.select("groundspeak|date")) { Elements siblings = elem.siblingElements(); String type = siblings.select("groundspeak|type").text(); if ((type.equals("Found it") || type.equals("Attended")) && siblings.select("groundspeak|finder").attr("id").equals(ownerId)) { DateTime dt = fmt.parseDateTime(elem.text()); /* * This seems to be necessary to get all log dates to conform to * what's displayed on geocaching.com. Certain logs which have a * date between 0000 and 0600 should really belong to the * previous day. */ dt = dt.minusHours(6); dates.remove(new Slot(dt)); } } Calendar cal = new Calendar(); cal.getProperties().add(new ProdId("-//JesperEs/fulldatechart 1.0//EN")); cal.getProperties().add(Version.VERSION_2_0); cal.getProperties().add(CalScale.GREGORIAN); UidGenerator ug = new UidGenerator("1"); List<Slot> list = new ArrayList<Slot>(); list.addAll(dates); Collections.sort(list); for (Slot slot : list) { DateTime dt = slot.getNextOccurrence(); System.out.format("Next occurrence of empty slot: %s -> %s\n", slot, dt); VEvent event = new VEvent(new Date(dt.withHourOfDay(19).toDate()), "Cache-day"); event.getProperties().add(ug.generateUid()); cal.getComponents().add(event); } File output = new File("fulldatechart.ics"); FileOutputStream fout = new FileOutputStream(output); try { CalendarOutputter out = new CalendarOutputter(); out.output(cal, fout); System.out.println("Calendar written to " + output.getAbsolutePath()); } finally { fout.close(); } }
From source file:io.apiman.manager.api.core.metrics.AbstractMetricsAccessor.java
License:Apache License
/** * Based on the given interval, create a "floor" value relative to the * given date. This basically means zero'ing out certain fields (different * fields based on the interval type) and returning the modified date. * @param date//from ww w.ja va2s . c o m * @param interval */ protected static DateTime floor(DateTime date, HistogramIntervalType interval) { DateTime rval = date.withMillisOfSecond(0); switch (interval) { case day: rval = rval.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case hour: rval = rval.withMinuteOfHour(0).withSecondOfMinute(0); break; case minute: rval = rval.withSecondOfMinute(0); break; case month: rval = rval.withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); break; case week: rval = rval.withDayOfWeek(DateTimeConstants.MONDAY).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); break; } return rval; }
From source file:nc.noumea.mairie.organigramme.core.utility.DateUtil.java
License:Open Source License
public static DateTime debutJournee(DateTime d) { return d.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
From source file:net.sourceforge.fenixedu.domain.EnrolmentEvaluation.java
License:Open Source License
@Override public void setExamDateYearMonthDay(YearMonthDay evaluationDateYearMonthDay) { if (evaluationDateYearMonthDay != null) { final Enrolment enrolment = getEnrolment(); final Thesis thesis = enrolment.getThesis(); if (thesis != null) { DateTime newDateTime = evaluationDateYearMonthDay.toDateTimeAtMidnight(); final DateTime dateTime = thesis.getDiscussed(); if (dateTime != null) { newDateTime = newDateTime.withHourOfDay(dateTime.getHourOfDay()); newDateTime = newDateTime.withMinuteOfHour(dateTime.getMinuteOfHour()); }/*from www . j a v a2 s . c o m*/ thesis.setDiscussed(newDateTime); } } super.setExamDateYearMonthDay(evaluationDateYearMonthDay); }
From source file:op.tools.SYSCalendar.java
License:Open Source License
public static DateTime midOfDay(LocalDate d) { DateTime dt = d.toDateTimeAtCurrentTime(); return dt.withHourOfDay(12).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
From source file:org.bensteele.jirrigate.Irrigator.java
License:Open Source License
/** * Returns the time and date the next irrigation is due based on the watering_days and * watering_start_time. It does not take into account whether or not any of the {@link Controller} * are active./*w ww .jav a 2 s . c o m*/ * * @return The time and date of the next irrigation for any controller under this irrigator's * control. */ protected DateTime nextIrrigationAt() { DateTime dt = new DateTime(); for (int i = 0; i < 7; i++) { for (final int dayOfWeek : wateringDays) { if (dayOfWeek == (dt.getDayOfWeek())) { // If it's the first run then we may match the same day we are currently on, in this case // we need to check that we don't report a time in the past. Validate that the hour and // minute right now are not past the scheduled watering time. If it's not the first run // then it's ok to let through. if (i != 0 || (i == 0 && dt.toLocalTime().isBefore(wateringStartTime))) { // Reset the hour to 0 and increment until we match the watering hour. dt = dt.withHourOfDay(0); while (dt.getHourOfDay() < wateringStartTime.getHourOfDay()) { dt = dt.plusHours(1); } // Reset the minute to 0 and increment until we match the watering minute. dt = dt.withMinuteOfHour(0); while (dt.getMinuteOfHour() < wateringStartTime.getMinuteOfHour()) { dt = dt.plusMinutes(1); } return dt; } } } dt = dt.plusDays(1); } return null; }
From source file:org.epics.archiverappliance.common.TimeUtils.java
public static long getStartOfCurrentDayInEpochSeconds() { DateTime now = new DateTime(DateTimeZone.UTC); DateTime startofCurrentDay = now.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0); return startofCurrentDay.getMillis() / 1000; }
From source file:org.everit.jira.settings.dto.TimeTrackerUserSettings.java
License:Apache License
/** * Gets the default start time./*from w ww . java2 s.c o m*/ */ public String getDefaultStartTime() { String savedDefaultStartTime = pluginSettingsKeyValues.get(UserSettingKey.DEFAULT_START_TIME); if (savedDefaultStartTime == null) { DateTime dateTime = new DateTime(TimetrackerUtil.getLoggedUserTimeZone()); dateTime = dateTime.withHourOfDay(DateTimeConverterUtil.HOUR_EIGHT); dateTime = dateTime.withMinuteOfHour(0); dateTime = dateTime.withSecondOfMinute(0); return DateTimeConverterUtil.dateTimeToString(DateTimeConverterUtil.convertDateTimeToDate(dateTime)); } Date date; try { date = DateTimeConverterUtil.stringTimeToDateTimeWithFixFormat(savedDefaultStartTime); } catch (ParseException e) { // we save defautl start time with HH:mm format. We parse with this format at now. Not // possible to throw exception. throw new RuntimeException("Cannot be parse default start time."); } return DateTimeConverterUtil.dateTimeToString(date); }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Return a Calendar with time set by the start of the given day. * * @param date/*from ww w. j a v a2 s.co m*/ * The time to set the calendar * @return The calendar which represents the start of the day */ public static DateTime setDateToDayStart(final DateTime date) { DateTime dateStartOfTheDay = date.withHourOfDay(0); dateStartOfTheDay = dateStartOfTheDay.withMinuteOfHour(0); dateStartOfTheDay = dateStartOfTheDay.withSecondOfMinute(0); dateStartOfTheDay = dateStartOfTheDay.withMillisOfSecond(0); return dateStartOfTheDay; }