List of usage examples for org.joda.time DateTime withTimeAtStartOfDay
public DateTime withTimeAtStartOfDay()
From source file:de.dbaelz.onofftracker.helpers.ActionHelper.java
License:Apache License
public long countActionsForDate(DateTime date, Action.ActionType type) { return countActionsBetween(date.withTimeAtStartOfDay(), date.withHourOfDay(23).withMinuteOfHour(59).withSecondOfMinute(59), type); }
From source file:de.dbaelz.onofftracker.helpers.ActionHelper.java
License:Apache License
public ActionsInterval getActionsIntervalToday(String title) { DateTime endDate = DateTime.now(); DateTime startDate = endDate.withTimeAtStartOfDay(); return new ActionsInterval(title, startDate, endDate, countActionsBetween(startDate, endDate, Action.ActionType.SCREENON), countActionsBetween(startDate, endDate, Action.ActionType.SCREENOFF), countActionsBetween(startDate, endDate, Action.ActionType.UNLOCKED)); }
From source file:es.usc.citius.servando.calendula.fragments.DailyAgendaFragment.java
License:Open Source License
public void addEmptyHours(List<DailyAgendaItemStub> stubs, DateTime min, DateTime max) { min = min.withTimeAtStartOfDay(); max = max.withTimeAtStartOfDay().plusDays(1); // end of the day // add empty hours if there is not an item with the same hour for (DateTime start = min; start.isBefore(max); start = start.plusHours(1)) { boolean exact = false; for (DailyAgendaItemStub item : items) { if (start.equals(item.dateTime())) { exact = true;/*from ww w . j a v a 2s . c o m*/ break; } } Interval hour = new Interval(start, start.plusHours(1)); if (!exact || hour.contains(DateTime.now())) { stubs.add(new DailyAgendaItemStub(start.toLocalDate(), start.toLocalTime())); } if (start.getHourOfDay() == 0) { DailyAgendaItemStub spacer = new DailyAgendaItemStub(start.toLocalDate(), start.toLocalTime()); spacer.isSpacer = true; stubs.add(spacer); } } }
From source file:es.usc.citius.servando.calendula.persistence.Schedule.java
License:Open Source License
public List<DateTime> hourlyItemsAt(DateTime d) { DateTime date = d.withTimeAtStartOfDay(); // get schedule occurrences for the current day return rrule.occurrencesBetween(date, date.plusDays(1), startDateTime()); }
From source file:es.usc.citius.servando.calendula.scheduling.DailyAgenda.java
License:Open Source License
public void setupForToday(Context ctx, final boolean force) { final SharedPreferences settings = ctx.getSharedPreferences(PREFERENCES_NAME, 0); final Long lastDate = settings.getLong(PREF_LAST_DATE, 0); final DateTime now = DateTime.now(); Log.d(TAG, "Setup daily agenda. Last updated: " + new DateTime(lastDate).toString("dd/MM - kk:mm")); Interval today = new Interval(now.withTimeAtStartOfDay(), now.withTimeAtStartOfDay().plusDays(1)); // we need to update daily agenda if (!today.contains(lastDate) || force) { // Start transaction try {/* w w w .ja va 2s . c o m*/ TransactionManager.callInTransaction(DB.helper().getConnectionSource(), new Callable<Object>() { @Override public Object call() throws Exception { if (!force) { LocalDate yesterday = now.minusDays(1).toLocalDate(); LocalDate tomorrow = now.plusDays(1).toLocalDate(); // delete items older than yesterday DB.dailyScheduleItems().removeOlderThan(yesterday); // delete items beyond tomorrow (only possible when changing date) DB.dailyScheduleItems().removeBeyond(tomorrow); } else { DB.dailyScheduleItems().removeAll(); } // and add new ones createDailySchedule(now); // Save last date to prefs SharedPreferences.Editor editor = settings.edit(); editor.putLong(PREF_LAST_DATE, now.getMillis()); editor.commit(); return null; } }); } catch (SQLException e) { if (!force) { Log.e(TAG, "Error setting up daily agenda. Retrying with force = true", e); // setup with force, destroy current daily agenda but continues working setupForToday(ctx, true); } else { Log.e(TAG, "Error setting up daily agenda", e); } } // Update alarms AlarmScheduler.instance().updateAllAlarms(ctx); CalendulaApp.eventBus().post(new AgendaUpdatedEvent()); } else { Log.d(TAG, "No need to update daily schedule (" + DailyScheduleItem.findAll().size() + " items found for today)"); } }
From source file:femr.business.services.system.EncounterService.java
License:Open Source License
/** * {@inheritDoc}// w ww.j a v a 2s . c om */ @Override public ServiceResponse<List<PatientEncounterItem>> retrieveCurrentDayPatientEncounters(int tripID) { ServiceResponse<List<PatientEncounterItem>> response = new ServiceResponse<>(); List<PatientEncounterItem> patientEncounterItems = new ArrayList<>(); //gets dates for today and tommorrow DateTime today = DateTime.now(); today = today.withTimeAtStartOfDay(); DateTime tommorrow = today; tommorrow = tommorrow.plusDays(1); //query todays patients ExpressionList<PatientEncounter> query = QueryProvider.getPatientEncounterQuery().where() .ge("date_of_triage_visit", today).le("date_of_triage_visit", tommorrow) .eq("mission_trip_id", tripID); try { List<PatientItem> patientItems = null; List<? extends IPatientEncounter> patient = patientEncounterRepository.find(query); for (IPatientEncounter patient1 : patient) { patientEncounterItems.add(itemModelMapper.createPatientEncounterItem(patient1)); } response.setResponseObject(patientEncounterItems); } catch (Exception ex) { response.addError("", ex.getMessage()); } return response; }
From source file:fi.craplab.roameo.ui.view.ExportDataDialog.java
License:Open Source License
private void setStartDate(DateTime dateTime) { mStartDate = dateTime.withTimeAtStartOfDay(); mStartDateTextView.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(mStartDate.toDate())); }
From source file:fi.craplab.roameo.ui.view.ExportDataDialog.java
License:Open Source License
private void setEndDate(DateTime dateTime) { // set end date time to 23:59:59 mEndDate = dateTime.withTimeAtStartOfDay().plusDays(1).minusSeconds(1); mEndDateTextView.setText(DateFormat.getDateInstance(DateFormat.MEDIUM).format(mEndDate.toDate())); }
From source file:google.registry.model.rde.RdeNamingUtils.java
License:Open Source License
/** Returns date as a hyphened string with ISO-8601 ordering, e.g. {@code 1984-12-18}. */ private static String formatDate(DateTime date) { checkArgument(date.withTimeAtStartOfDay().equals(date), "Not midnight: %s", date); return DATE_FORMATTER.print(date); }
From source file:google.registry.model.translators.CommitLogRevisionsTranslatorFactory.java
License:Open Source License
/** * Add a reference to the current commit log to the resource's revisions map. * * <p>This method also prunes the revisions map. It guarantees to keep enough data so that floor * will work going back N days. It does this by making sure one entry exists before that duration, * and pruning everything after it. The size of the map is guaranteed to never exceed N+2. * * <p>We store a maximum of one entry per day. It will be the last transaction that happened on * that day.//from ww w. j av a2 s. co m * * @see google.registry.config.RegistryConfig#getCommitLogDatastoreRetention() */ @Override ImmutableSortedMap<DateTime, Key<CommitLogManifest>> transformBeforeSave( ImmutableSortedMap<DateTime, Key<CommitLogManifest>> revisions) { DateTime now = ofy().getTransactionTime(); DateTime threshold = now.minus(getCommitLogDatastoreRetention()); DateTime preThresholdTime = firstNonNull(revisions.floorKey(threshold), START_OF_TIME); return new ImmutableSortedMap.Builder<DateTime, Key<CommitLogManifest>>(Ordering.natural()) .putAll(revisions.subMap(preThresholdTime, true, now.withTimeAtStartOfDay(), false)) .put(now, ofy().getCommitLogManifestKey()).build(); }