List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:com.serotonin.mango.vo.report.ReportVO.java
License:Open Source License
public ReportVO() { // Default the specific date fields. DateTime dt = DateUtils.truncateDateTime(new DateTime(), Common.TimePeriods.DAYS); toYear = dt.getYear();/*from w w w.j a v a 2s.c om*/ toMonth = dt.getMonthOfYear(); toDay = dt.getDayOfMonth(); toHour = dt.getHourOfDay(); toMinute = dt.getMinuteOfHour(); dt = DateUtils.minus(dt, Common.TimePeriods.DAYS, 1); fromYear = dt.getYear(); fromMonth = dt.getMonthOfYear(); fromDay = dt.getDayOfMonth(); fromHour = dt.getHourOfDay(); fromMinute = dt.getMinuteOfHour(); }
From source file:com.serotonin.mango.web.dwr.BaseDwr.java
License:Open Source License
public Map<String, Object> getDateRangeDefaults(int periodType, int period) { Map<String, Object> result = new HashMap<String, Object>(); // Default the specific date fields. DateTime dt = new DateTime(); result.put("toYear", dt.getYear()); result.put("toMonth", dt.getMonthOfYear()); result.put("toDay", dt.getDayOfMonth()); result.put("toHour", dt.getHourOfDay()); result.put("toMinute", dt.getMinuteOfHour()); result.put("toSecond", 0); dt = DateUtils.minus(dt, periodType, period); result.put("fromYear", dt.getYear()); result.put("fromMonth", dt.getMonthOfYear()); result.put("fromDay", dt.getDayOfMonth()); result.put("fromHour", dt.getHourOfDay()); result.put("fromMinute", dt.getMinuteOfHour()); result.put("fromSecond", 0); return result; }
From source file:com.snapdeal.scm.alerts.task.AlertScheduledTask.java
License:Open Source License
@Scheduled(cron = "${alert.task.cron}") public void alertJob() { DateTime currentTime = new DateTime(); List<AlertInstance> alerts = repo.findByTimeBetween(currentTime.getHourOfDay()); logger.info("Alerts to be Q for processing : " + alerts); alerts.forEach(alert -> {/*from ww w . j a v a 2s .c o m*/ alertProducer.send(alert.getAlertId()); }); }
From source file:com.splicemachine.db.iapi.types.SQLTime.java
License:Apache License
public void setValue(DateTime value) throws StandardException { setValue(computeEncodedTime(value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute())); }
From source file:com.splicemachine.db.iapi.types.SQLTimestamp.java
License:Apache License
private static int computeEncodedTime(DateTime value) throws StandardException { return SQLTime.computeEncodedTime(value.getHourOfDay(), value.getMinuteOfHour(), value.getSecondOfMinute()); }
From source file:com.splicemachine.derby.utils.SpliceDateFunctions.java
License:Apache License
/** * Implements the trunc_date function/*w ww .j a v a 2 s. c om*/ */ public static Timestamp TRUNC_DATE(Timestamp source, String field) throws SQLException { if (source == null || field == null) return null; DateTime dt = new DateTime(source); field = field.toLowerCase(); String lowerCaseField = field.toLowerCase(); if ("microseconds".equals(lowerCaseField)) { int nanos = source.getNanos(); nanos = nanos - nanos % 1000; source.setNanos(nanos); return source; } else if ("milliseconds".equals(lowerCaseField)) { int nanos = source.getNanos(); nanos = nanos - nanos % 1000000; source.setNanos(nanos); return source; } else if ("second".equals(lowerCaseField)) { source.setNanos(0); return source; } else if ("minute".equals(lowerCaseField)) { DateTime modified = dt.minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("hour".equals(lowerCaseField)) { DateTime modified = dt.minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("day".equals(lowerCaseField)) { DateTime modified = dt.minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour()) .minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("week".equals(lowerCaseField)) { DateTime modified = dt.minusDays(dt.getDayOfWeek()).minusHours(dt.getHourOfDay()) .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("month".equals(lowerCaseField)) { DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1) .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour()) .minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("quarter".equals(lowerCaseField)) { int month = dt.getMonthOfYear(); DateTime modified = dt; if ((month + 1) % 3 == 1) { modified = dt.minusMonths(2); } else if ((month + 1) % 3 == 0) { modified = dt.minusMonths(1); } DateTime fin = modified.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1) .minusHours(dt.getHourOfDay()).minusMinutes(dt.getMinuteOfHour()) .minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(fin.getMillis()); ret.setNanos(0); return ret; } else if ("year".equals(lowerCaseField)) { DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1) .minusHours(dt.getHourOfDay()).minusMonths(dt.getMonthOfYear() - 1) .minusMinutes(dt.getMinuteOfHour()).minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("decade".equals(lowerCaseField)) { DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1) .minusYears(dt.getYear() % 10).minusHours(dt.getHourOfDay()) .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour()) .minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("century".equals(lowerCaseField)) { DateTime modified = dt.minusDays(dt.get(DateTimeFieldType.dayOfMonth()) - 1) .minusHours(dt.getHourOfDay()).minusYears(dt.getYear() % 100) .minusMonths(dt.getMonthOfYear() - 1).minusMinutes(dt.getMinuteOfHour()) .minusSeconds(dt.getSecondOfMinute()); Timestamp ret = new Timestamp(modified.getMillis()); ret.setNanos(0); return ret; } else if ("millennium".equals(lowerCaseField)) { int newYear = dt.getYear() - dt.getYear() % 1000; //noinspection deprecation (converstion from joda to java.sql.Timestamp did not work for millennium < 2000) return new Timestamp(newYear - 1900, Calendar.JANUARY, 1, 0, 0, 0, 0); } else { throw new SQLException(String.format("invalid time unit '%s'", field)); } }
From source file:com.sqewd.os.maracache.api.utils.TimeUtils.java
License:Apache License
/** * Get the time bucket for the input date based on the Time Unit and Unit multiplier specified. * * @param dt - Date time to bucket. * @param unit - Time Unit// w w w. ja v a 2 s. c om * @param multiplier - Unit multiplier. * @return */ public static DateTime bucket(DateTime dt, TimeUnit unit, int multiplier) { DateTime w = null; switch (unit) { case MILLISECONDS: int ms = (dt.getMillisOfSecond() / multiplier) * multiplier; w = dt.secondOfMinute().roundFloorCopy().plusMillis(ms); break; case SECONDS: int s = (dt.getSecondOfMinute() / multiplier) * multiplier; w = dt.minuteOfHour().roundFloorCopy().plusSeconds(s); break; case MINUTES: int m = (dt.getMinuteOfHour() / multiplier) * multiplier; w = dt.hourOfDay().roundFloorCopy().plusMinutes(m); break; case HOURS: int h = (dt.getHourOfDay() / multiplier) * multiplier; w = dt.dayOfYear().roundFloorCopy().plusHours(h); break; case DAYS: int d = (dt.getDayOfYear() / multiplier) * multiplier; // Need to subtract (1) as the start offset i if (dt.getDayOfYear() % multiplier == 0) { d -= 1; } w = dt.yearOfCentury().roundFloorCopy().plusDays(d); break; } return w; }
From source file:com.tmathmeyer.sentinel.ui.DatePicker.java
License:Open Source License
/** * Sets date and time of DatePicker to specified value * //from ww w . j a va2 s. co m * @param previous the DateTime object from which to obtain values */ public void setDateTime(DateTime previous) { this.date.setValue(previous.toString(dateFmt)); this.time.setValue(previous.toString(timeFmt)); if (previous.getHourOfDay() >= 12) { this.AMPM.setSelectedIndex(1); } else { this.AMPM.setSelectedIndex(0); } }
From source file:com.tmathmeyer.sentinel.ui.DatePicker.java
License:Open Source License
/** * Sets time of DatePicker to specified value * //from w ww . j a va 2 s . c o m * @param previous the DateTime object from which to obtain values */ public void setTime(DateTime previous) { this.time.setValue(previous.toString(timeFmt)); if (previous.getHourOfDay() >= 12) { this.AMPM.setSelectedIndex(1); } else { this.AMPM.setSelectedIndex(0); } }
From source file:com.tmathmeyer.sentinel.ui.views.day.collisiondetection.DayItem.java
License:Open Source License
public String formatTime(DateTime when) { String ret;/*from ww w.j ava 2 s . com*/ boolean pm = when.getHourOfDay() >= 12; if (when.getHourOfDay() == 0) ret = "12"; else if (when.getHourOfDay() > 12) ret = Integer.toString(when.getHourOfDay() - 12); else ret = Integer.toString(when.getHourOfDay()); if (when.getMinuteOfHour() != 0) { ret += ":"; if (when.getMinuteOfHour() < 10) ret += "0"; ret += Integer.toString(when.getMinuteOfHour()); } if (pm) ret += "p"; return ret; }