List of usage examples for org.joda.time DateTime getMinuteOfHour
public int getMinuteOfHour()
From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java
License:Open Source License
/** Convert {@code millis} to a DateTime and {@link #encodeTime(long, long, long, TExecutionContext)}. */ public static int encodeTime(long millis, String tz) { DateTime dt = new DateTime(millis, DateTimeZone.forID(tz)); return encodeTime(dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute(), null); }
From source file:com.foundationdb.server.types.mcompat.mtypes.MDateAndTime.java
License:Open Source License
/** Decode {@code encodedTimestamp} using the {@code tz} timezone. */ public static long[] decodeTimestamp(long encodedTimestamp, String tz) { DateTime dt = new DateTime(encodedTimestamp * 1000L, DateTimeZone.forID(tz)); return new long[] { dt.getYear(), dt.getMonthOfYear(), dt.getDayOfMonth(), dt.getHourOfDay(), dt.getMinuteOfHour(), dt.getSecondOfMinute() }; }
From source file:com.francelabs.datafari.alerts.AlertsManager.java
License:Apache License
/** * Calculate the difference in minutes between the current date time and the * provided scheduled one, according to the frequency * * @param frequency//w w w. ja va 2 s . c o m * the frequency of the scheduled date time * @param scheduledDate * the initial scheduled date time that the user has typed in the * admin UI * @return the difference in minutes between the current date time and the * next scheduled one */ private long calculateDelays(final String frequency, final DateTime scheduledDate) { long diff = 0L; final Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); final DateTime currentDateTime = new DateTime(cal.getTime()); DateTime scheduledDateTimeUpdate; switch (frequency.toLowerCase()) { case "hourly": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is earlier than the scheduled one, simply calculate // the difference in minutes, otherwise create the next scheduled // date and calculate the difference if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.HOUR_OF_DAY, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } diff = Minutes.minutesBetween(currentDateTime, scheduledDateTimeUpdate).getMinutes(); break; case "daily": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, scheduledDate.getHourOfDay()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is earlier than the scheduled one, simply calculate // the difference in minutes, otherwise create the next scheduled // date and calculate the difference if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.DAY_OF_YEAR, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } diff = Minutes.minutesBetween(currentDateTime, scheduledDateTimeUpdate).getMinutes(); break; case "weekly": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.DAY_OF_WEEK, scheduledDate.getDayOfWeek() + 1); // +1 // = // diff // between // Joda // and // Calendar cal.set(Calendar.HOUR_OF_DAY, scheduledDate.getHourOfDay()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is earlier than the scheduled one, simply calculate // the difference in minutes, otherwise create the next scheduled // date and calculate the difference if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.WEEK_OF_YEAR, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } diff = Minutes.minutesBetween(currentDateTime, scheduledDateTimeUpdate).getMinutes(); break; default: break; } return diff; }
From source file:com.francelabs.datafari.servlets.admin.alertsAdmin.java
License:Apache License
private String getNextEvent(final String frequency, final String initialDate) { final DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy/HH:mm"); final DateTime scheduledDate = new DateTime(formatter.parseDateTime(initialDate)); final Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); cal.set(Calendar.SECOND, 0);//from ww w.java 2s. co m cal.set(Calendar.MILLISECOND, 0); final DateTime currentDateTime = new DateTime(cal.getTime()); DateTime scheduledDateTimeUpdate = new DateTime(cal.getTime()); switch (frequency.toLowerCase()) { case "hourly": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is later than the scheduled one then create the next // scheduled date if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.HOUR_OF_DAY, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } break; case "daily": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.HOUR_OF_DAY, scheduledDate.getHourOfDay()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is later than the scheduled one then create the next // scheduled date if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.DAY_OF_YEAR, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } break; case "weekly": // Create what would be the current scheduled date cal.setTime(new Date()); cal.set(Calendar.DAY_OF_WEEK, scheduledDate.getDayOfWeek() + 1); // +1 // = // diff // between // Joda // and // Calendar cal.set(Calendar.HOUR_OF_DAY, scheduledDate.getHourOfDay()); cal.set(Calendar.MINUTE, scheduledDate.getMinuteOfHour()); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); scheduledDateTimeUpdate = new DateTime(cal.getTime()); // Compare the current date with the current scheduled one, if the // current date is later than the scheduled one then create the next // scheduled date if (!currentDateTime.isBefore(scheduledDateTimeUpdate)) { cal.add(Calendar.WEEK_OF_YEAR, 1); scheduledDateTimeUpdate = new DateTime(cal.getTime()); } break; default: break; } return scheduledDateTimeUpdate.toString(formatter); }
From source file:com.github.autermann.matlab.value.MatlabDateTime.java
License:Open Source License
public double[] toArray() { DateTime utc = time.toDateTime(DateTimeZone.UTC); return new double[] { (double) utc.getYear(), (double) utc.getMonthOfYear(), (double) utc.getDayOfMonth(), (double) utc.getHourOfDay(), (double) utc.getMinuteOfHour(), (double) utc.getSecondOfMinute() + (double) utc.getMillisOfSecond() / 1000, }; }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime fiveMinutes(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); int minutes = dateTime.getMinuteOfHour(); return dateTime.withMinuteOfHour(minutes / 5 * 5); }
From source file:com.github.dbourdette.otto.source.TimeFrame.java
License:Apache License
private DateTime thirtyMinutes(DateTime dateTime) { dateTime = dateTime.withMillisOfSecond(0); dateTime = dateTime.withSecondOfMinute(0); if (dateTime.getMinuteOfHour() < 30) { return dateTime.withMinuteOfHour(0); } else {/*from w w w . j a v a 2s. c o m*/ return dateTime.withMinuteOfHour(30); } }
From source file:com.github.markserrano.jsonquery.jpa.util.DateTimeUtil.java
License:Apache License
public static Map<String, DateTime> getYesterdaySpan() { DateTime now = new DateTime(); DateTime from = now.minusDays(1).minusHours(now.getHourOfDay()).minusMinutes(now.getMinuteOfHour()) .minusSeconds(now.getSecondOfMinute()).minusMillis(now.getMillisOfSecond()); DateTime to = from.plusHours(23).plusMinutes(59).plusSeconds(59); Map<String, DateTime> map = new HashMap<String, DateTime>(); map.put("from", from); map.put("to", to); return map;/*ww w . jav a2 s . c o m*/ }
From source file:com.google.android.apps.paco.ExperimentScheduleActivity.java
License:Open Source License
private void showEsmScheduleConfiguration() { setContentView(R.layout.esm_schedule); TextView title = (TextView) findViewById(R.id.experimentNameSchedule); title.setText(experiment.getExperimentDAO().getTitle()); startHourField = (Button) findViewById(R.id.startHourTimePickerLabel); startHourField.setText(new DateMidnight().toDateTime() .withMillisOfDay(schedule.getEsmStartHour().intValue()).toString(TIME_FORMAT_STRING)); endHourField = (Button) findViewById(R.id.endHourTimePickerLabel); endHourField.setText(new DateMidnight().toDateTime().withMillisOfDay(schedule.getEsmEndHour().intValue()) .toString(TIME_FORMAT_STRING)); // TODO (bobevans): get rid of this duplication startHourField.setOnClickListener(new OnClickListener() { public void onClick(View v) { final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ExperimentScheduleActivity.this); unsetTimesViewParent();/*from w w w. j a va 2s. c o m*/ dialogBuilder.setView(timesScheduleLayout); final AlertDialog dialog = dialogBuilder.setTitle(R.string.start_time_title).create(); Long offset = schedule.getEsmStartHour(); DateTime startHour = new DateMidnight().toDateTime().withMillisOfDay(offset.intValue()); timePicker.setCurrentHour(startHour.getHourOfDay()); timePicker.setCurrentMinute(startHour.getMinuteOfHour()); dialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { schedule.setEsmStartHour(getHourOffsetFromPicker()); startHourField.setText(getTextFromPicker(schedule.getEsmStartHour().intValue())); } }); dialog.show(); } }); // endHourField.setOnClickListener(new OnClickListener() { public void onClick(View v) { final AlertDialog.Builder endHourDialogBuilder = new AlertDialog.Builder( ExperimentScheduleActivity.this); unsetTimesViewParent(); endHourDialogBuilder.setView(timesScheduleLayout); final AlertDialog endHourDialog = endHourDialogBuilder.setTitle(R.string.end_time_title).create(); Long offset = schedule.getEsmEndHour(); DateTime endHour = new DateMidnight().toDateTime().withMillisOfDay(offset.intValue()); timePicker.setCurrentHour(endHour.getHourOfDay()); timePicker.setCurrentMinute(endHour.getMinuteOfHour()); endHourDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save_button), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { schedule.setEsmEndHour(getHourOffsetFromPicker()); endHourField.setText(getTextFromPicker(schedule.getEsmEndHour().intValue())); } }); endHourDialog.show(); } }); }
From source file:com.google.android.apps.paco.SignalSchedule.java
License:Open Source License
public String getHourOffsetAsTimeString(Long esmEndHour2) { DateTime endHour = new DateMidnight().toDateTime().plus(esmEndHour2); String endHourString = endHour.getHourOfDay() + ":" + pad(endHour.getMinuteOfHour()); return endHourString; }