List of usage examples for org.joda.time DateTime withMinuteOfHour
public DateTime withMinuteOfHour(int minute)
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./*from w w w. j a v 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.classbooker.entity.Reservation.java
private Calendar changeDateToCalendar(DateTime reservationDate) { return reservationDate.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0) .toCalendar(Locale.getDefault()); }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Given an epoch seconds and a granularity, this method gives you the first second in the next partition as epoch seconds. * @param epochSeconds/*from ww w. jav a2 s . c om*/ * @param granularity * @return */ public static long getNextPartitionFirstSecond(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); DateTime nextPartitionFirstSecond = null; switch (granularity) { case PARTITION_YEAR: nextPartitionFirstSecond = dateTime.plusYears(1).withMonthOfYear(1).withDayOfMonth(1).withHourOfDay(0) .withMinuteOfHour(0).withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_MONTH: nextPartitionFirstSecond = dateTime.plusMonths(1).withDayOfMonth(1).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_DAY: nextPartitionFirstSecond = dateTime.plusDays(1).withHourOfDay(0).withMinuteOfHour(0) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_HOUR: nextPartitionFirstSecond = dateTime.plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); DateTime nextPartForMin = dateTime.plusMinutes(approxMinutesPerChunk); int startOfPartitionForMin = (nextPartForMin.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; nextPartitionFirstSecond = nextPartForMin.withMinuteOfHour(startOfPartitionForMin) .withSecondOfMinute(0); return nextPartitionFirstSecond.getMillis() / 1000; default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Given an epoch seconds and a granularity, this method gives you the last second in the previous partition as epoch seconds. * @param epochSeconds/*from w w w . ja v a2 s.c om*/ * @param granularity * @return */ public static long getPreviousPartitionLastSecond(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); DateTime previousPartitionLastSecond = null; switch (granularity) { case PARTITION_YEAR: previousPartitionLastSecond = dateTime.minusYears(1).withMonthOfYear(12).withDayOfMonth(31) .withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_MONTH: previousPartitionLastSecond = dateTime.withDayOfMonth(1).minusDays(1).withHourOfDay(23) .withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_DAY: previousPartitionLastSecond = dateTime.minusDays(1).withHourOfDay(23).withMinuteOfHour(59) .withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_HOUR: previousPartitionLastSecond = dateTime.minusHours(1).withMinuteOfHour(59).withSecondOfMinute(59); return previousPartitionLastSecond.getMillis() / 1000; case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); int startOfPartition_Min = (dateTime.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; previousPartitionLastSecond = dateTime.withMinuteOfHour(startOfPartition_Min).withSecondOfMinute(0) .minusSeconds(1); return previousPartitionLastSecond.getMillis() / 1000; default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.everit.jira.settings.dto.TimeTrackerUserSettings.java
License:Apache License
/** * Gets the default start time.//from w w w .j a va 2 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 www .j a v a 2 s .c o 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; }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Concat DateTime date and Date time to a DateTime date based on the originalDate param. * * @param originalDate/*from w w w .ja v a 2 s .c o m*/ * The date. * @param time * The time. * @return The concated date time. */ public static DateTime stringToDateAndTime(final DateTime originalDate, final Date time) { DateTime date; try { date = originalDate.withHourOfDay(time.getHours()); date = date.withMinuteOfHour(time.getMinutes()); } catch (IllegalArgumentException e) { throw new WorklogException(WorklogComponent.PropertiesKey.DATE_PARSE, originalDate + " " + time); } return date; }
From source file:org.graylog2.system.traffic.TrafficCounterService.java
License:Open Source License
private static DateTime getDayBucket(DateTime observationTime) { return observationTime.withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0); }
From source file:org.jruby.CompatVersion.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime(); DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes = null; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); }//from w w w . j a v a2 s. c o m int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L + s); } else { p &= ~(1 << 31); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); dt = dt.withZone(getLocalTimeZone(runtime)); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); return time; }
From source file:org.jruby.RubyTime.java
License:LGPL
protected static RubyTime s_mload(IRubyObject recv, RubyTime time, IRubyObject from) { Ruby runtime = recv.getRuntime();//from w w w .j a va 2 s . co m DateTime dt = new DateTime(DateTimeZone.UTC); byte[] fromAsBytes; fromAsBytes = from.convertToString().getBytes(); if (fromAsBytes.length != 8) { throw runtime.newTypeError("marshaled time format differ"); } int p = 0; int s = 0; for (int i = 0; i < 4; i++) { p |= ((int) fromAsBytes[i] & 0xFF) << (8 * i); } for (int i = 4; i < 8; i++) { s |= ((int) fromAsBytes[i] & 0xFF) << (8 * (i - 4)); } boolean utc = false; if ((p & (1 << 31)) == 0) { dt = dt.withMillis(p * 1000L); time.setUSec((s & 0xFFFFF) % 1000); } else { p &= ~(1 << 31); utc = ((p >>> 30 & 0x1) == 0x1); dt = dt.withYear(((p >>> 14) & 0xFFFF) + 1900); dt = dt.withMonthOfYear(((p >>> 10) & 0xF) + 1); dt = dt.withDayOfMonth(((p >>> 5) & 0x1F)); dt = dt.withHourOfDay((p & 0x1F)); dt = dt.withMinuteOfHour(((s >>> 26) & 0x3F)); dt = dt.withSecondOfMinute(((s >>> 20) & 0x3F)); // marsaling dumps usec, not msec dt = dt.withMillisOfSecond((s & 0xFFFFF) / 1000); time.setUSec((s & 0xFFFFF) % 1000); } time.setDateTime(dt); if (!utc) time.localtime(); from.getInstanceVariables().copyInstanceVariablesInto(time); // pull out nanos, offset, zone IRubyObject nano_num = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_num"); IRubyObject nano_den = (IRubyObject) from.getInternalVariables().getInternalVariable("nano_den"); IRubyObject offsetVar = (IRubyObject) from.getInternalVariables().getInternalVariable("offset"); IRubyObject zoneVar = (IRubyObject) from.getInternalVariables().getInternalVariable("zone"); if (nano_num != null && nano_den != null) { long nanos = nano_num.convertToInteger().getLongValue() / nano_den.convertToInteger().getLongValue(); time.nsec += nanos; } int offset = 0; if (offsetVar != null && offsetVar.respondsTo("to_int")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { offset = offsetVar.convertToInteger().getIntValue() * 1000; } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } String zone = ""; if (zoneVar != null && zoneVar.respondsTo("to_str")) { IRubyObject oldExc = runtime.getGlobalVariables().get("$!"); // Save $! try { zone = zoneVar.convertToString().toString(); } catch (RaiseException typeError) { runtime.getGlobalVariables().set("$!", oldExc); // Restore $! } } time.dt = dt.withZone(getTimeZoneWithOffset(runtime, zone, offset)); return time; }