List of usage examples for org.joda.time LocalDateTime getHourOfDay
public int getHourOfDay()
From source file:ch.icclab.cyclops.util.DateTimeUtil.java
License:Open Source License
/** * Generates the 1 hr time range (from and to) by computing the present server time * * @return dateTime A string consisting of from and to dateTime entries *//*from w w w .j a v a 2 s . c o m*/ public String[] getRange() { String from, to; String sMonth = null; String sDay = null; String stHour = null; String sHour = null; String sMin = null; String sSec = null; int year, month, day, hour, min, sec, tHour; String[] dateTime = new String[2]; LocalDateTime currentDate = LocalDateTime.now(); year = currentDate.getYear(); month = currentDate.getMonthOfYear(); if (month <= 9) { sMonth = "0" + month; } else { sMonth = month + ""; } day = currentDate.getDayOfMonth(); if (day <= 9) { sDay = "0" + day; } else { sDay = day + ""; } hour = currentDate.getHourOfDay(); if (hour <= 9) { sHour = "0" + hour; } else { sHour = hour + ""; } min = currentDate.getMinuteOfHour(); if (min <= 9) { sMin = "0" + min; } else { sMin = min + ""; } sec = currentDate.getSecondOfMinute(); if (sec <= 9) { sSec = "0" + sec; } else { sSec = sec + ""; } to = year + "-" + sMonth + "-" + sDay + "T" + sHour + ":" + sMin + ":" + sSec + "Z"; Date dateTo = getDate(to); //Converting to in UTC to = getString(dateTo); long sensuFrequency = Loader.getSettings().getSchedulerSettings().getSchedulerFrequency(); long fromTimestamp = dateTo.getTime() - sensuFrequency * 1000; Date fromDate = new Date(fromTimestamp); from = getString(fromDate); dateTime[0] = to; dateTime[1] = from; return dateTime; }
From source file:cherry.goods.util.JodaTimeUtil.java
License:Apache License
/** * @param ldtm ???{@link LocalDateTime}/* ww w.j a va2 s . c o m*/ * @return ?????{@link Calendar}(?)???????? */ public static Calendar getCalendar(LocalDateTime ldtm) { Calendar cal = Calendar.getInstance(); cal.set(ldtm.getYear(), ldtm.getMonthOfYear() - 1, ldtm.getDayOfMonth(), ldtm.getHourOfDay(), ldtm.getMinuteOfHour(), ldtm.getSecondOfMinute()); cal.set(MILLISECOND, ldtm.getMillisOfSecond()); return cal; }
From source file:com.axelor.apps.hr.service.timesheet.TimesheetServiceImpl.java
License:Open Source License
public String computeFullName(Timesheet timesheet) { User timesheetUser = timesheet.getUser(); LocalDateTime createdOn = timesheet.getCreatedOn(); if (timesheetUser != null && createdOn != null) { return timesheetUser.getFullName() + " " + createdOn.getDayOfMonth() + "/" + createdOn.getMonthOfYear() + "/" + timesheet.getCreatedOn().getYear() + " " + createdOn.getHourOfDay() + ":" + createdOn.getMinuteOfHour(); } else if (timesheetUser != null) { return timesheetUser.getFullName() + " N" + timesheet.getId(); } else {/* ww w.jav a 2 s.co m*/ return "N" + timesheet.getId(); } }
From source file:com.battlelancer.seriesguide.util.TimeTools.java
License:Apache License
/** * If the release time is within the hour past midnight (0:00 until 0:59) moves the date one day * into the future (currently US shows only). * * <p> This is based on late night shows being commonly listed as releasing the day before if * they air past midnight (e.g. "Monday night at 0:35" actually is Tuesday 0:35). * * <p>Example: https://thetvdb.com/?tab=series&id=292421 * * <p>See also: https://forums.thetvdb.com/viewtopic.php?t=22791 *//* w w w.ja v a 2s.co m*/ private static LocalDateTime handleHourPastMidnight(@Nullable String country, LocalDateTime localDateTime) { // Example: if (ISO3166_1_UNITED_STATES.equals(country) && localDateTime.getHourOfDay() == 0) { return localDateTime.plusDays(1); } return localDateTime; }
From source file:com.ephemeraldreams.gallyshuttle.ui.events.PrepareAlarmReminderEvent.java
License:Apache License
private void setAlarmCalendar() { LocalDateTime alarmDateTime = DateUtils.parseToLocalDateTime(time); alarmDateTime = alarmDateTime.minusMinutes(prefReminderLength); hour = alarmDateTime.getHourOfDay(); minute = alarmDateTime.getMinuteOfHour(); }
From source file:com.ephemeraldreams.gallyshuttle.ui.MainFragment.java
License:Apache License
private void setScheduleId() { LocalDateTime now = LocalDateTime.now(); int hour = now.getHourOfDay(); int minute = now.getMinuteOfHour(); if (hour >= 21 || (hour == 0 && minute <= 15)) { scheduleId = R.array.late_night_stations; } else {/*from w ww .ja v a 2s . co m*/ int day = now.getDayOfWeek(); switch (day) { case SATURDAY: case SUNDAY: scheduleId = R.array.weekend_stations; break; default: scheduleId = R.array.continuous_stations; break; } } }
From source file:com.ephemeraldreams.gallyshuttle.ui.MainFragment.java
License:Apache License
/** * Calculate time difference in milliseconds between now and next available shuttle arrival time. * * @param stationId Station id to get times from. * @return Duration between now and next arrival time in milliseconds. *//* w w w . j a v a 2 s . c o m*/ private long calculateTimeFromNowToNextArrivalAtStation(int stationId) { List<String> times = schedule.getTimes(stationId); LocalDateTime now = LocalDateTime.now(); arrivalTime = null; LocalDateTime stationTime; for (String time : times) { stationTime = DateUtils.parseToLocalDateTime(time); Timber.d(stationTime.toString()); //Workaround midnight exception case where station time was converted to midnight of current day instead of next day. if (stationTime.getHourOfDay() == 0 && now.getHourOfDay() != 0) { stationTime = stationTime.plusDays(1); } if (now.isBefore(stationTime)) { arrivalTime = stationTime; break; } } if (arrivalTime == null) { arrivalTimeTextView.setText(getString(R.string.arrival_not_available_message)); return -1; } else { arrivalTimeTextView.setText(String.format(getString(R.string.until_arrival_time_message), DateUtils.formatTime(arrivalTime))); Duration duration = new Duration(now.toDateTime(), arrivalTime.toDateTime()); long milliseconds = duration.getMillis(); Timber.d("Now: " + DateUtils.formatTime(now)); Timber.d("Arrival: " + DateUtils.formatTime(arrivalTime)); Timber.d("Time difference between now and arrival: " + DateUtils.convertMillisecondsToTime(milliseconds)); return milliseconds; } }
From source file:com.google.gerrit.server.config.ScheduleConfig.java
License:Apache License
private static long initialDelay(Config rc, String section, String subsection, String keyStartTime, DateTime now, long interval) { long delay = MISSING_CONFIG; String start = rc.getString(section, subsection, keyStartTime); try {/*from w w w . j a va2s .c om*/ if (start != null) { DateTimeFormatter formatter; MutableDateTime startTime = now.toMutableDateTime(); try { formatter = ISODateTimeFormat.hourMinute(); LocalTime firstStartTime = formatter.parseLocalTime(start); startTime.hourOfDay().set(firstStartTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartTime.getMinuteOfHour()); } catch (IllegalArgumentException e1) { formatter = DateTimeFormat.forPattern("E HH:mm").withLocale(Locale.US); LocalDateTime firstStartDateTime = formatter.parseLocalDateTime(start); startTime.dayOfWeek().set(firstStartDateTime.getDayOfWeek()); startTime.hourOfDay().set(firstStartDateTime.getHourOfDay()); startTime.minuteOfHour().set(firstStartDateTime.getMinuteOfHour()); } startTime.secondOfMinute().set(0); startTime.millisOfSecond().set(0); long s = startTime.getMillis(); long n = now.getMillis(); delay = (s - n) % interval; if (delay <= 0) { delay += interval; } } else { log.info(MessageFormat.format("{0} schedule parameter \"{0}.{1}\" is not configured", section, keyStartTime)); } } catch (IllegalArgumentException e2) { log.error(MessageFormat.format("Invalid {0} schedule parameter \"{0}.{1}\"", section, keyStartTime), e2); delay = INVALID_CONFIG; } return delay; }
From source file:com.gs.fw.common.mithra.databasetype.SybaseIqNativeDatabaseType.java
License:Apache License
@Override public Timestamp getTimestampFromResultSet(ResultSet rs, int pos, TimeZone timeZone) throws SQLException { Timestamp localTs = rs.getTimestamp(pos); if (localTs == null) { return null; }//from w w w . j av a2s .c o m LocalDateTime ldt = new LocalDateTime(localTs.getTime()); Calendar utcCal = getCalendarInstance(); utcCal.set(Calendar.YEAR, ldt.getYear()); utcCal.set(Calendar.MONTH, ldt.getMonthOfYear() - 1); utcCal.set(Calendar.DAY_OF_MONTH, ldt.getDayOfMonth()); utcCal.set(Calendar.HOUR_OF_DAY, ldt.getHourOfDay()); utcCal.set(Calendar.MINUTE, ldt.getMinuteOfHour()); utcCal.set(Calendar.SECOND, ldt.getSecondOfMinute()); utcCal.set(Calendar.MILLISECOND, ldt.getMillisOfSecond()); Timestamp utcTs = new Timestamp(utcCal.getTimeInMillis()); return MithraTimestamp.zConvertTimeForReadingWithUtcCalendar(utcTs, timeZone); }
From source file:com.gs.fw.common.mithra.util.Time.java
License:Apache License
public static Time withSqlTime(java.sql.Time sqlTime) { if (sqlTime == null) return null; LocalDateTime localDateTime = new LocalDateTime(sqlTime.getTime()); return Time.withMillis(localDateTime.getHourOfDay(), localDateTime.getMinuteOfHour(), localDateTime.getSecondOfMinute(), localDateTime.getMillisOfSecond()); }