Example usage for org.joda.time DateTime minusHours

List of usage examples for org.joda.time DateTime minusHours

Introduction

In this page you can find the example usage for org.joda.time DateTime minusHours.

Prototype

public DateTime minusHours(int hours) 

Source Link

Document

Returns a copy of this datetime minus the specified number of hours.

Usage

From source file:org.mythtv.service.dvr.v25.RecordedHelperV25.java

License:Open Source License

private void processProgramGroups(final Context context, final LocationProfile locationProfile,
        Program[] programs) throws RemoteException, OperationApplicationException {
    Log.v(TAG, "processProgramGroups : enter");

    if (null == context)
        throw new RuntimeException("RecordedHelperV25 is not initialized");

    Map<String, ProgramGroup> programGroups = new TreeMap<String, ProgramGroup>();
    for (Program program : programs) {

        if (null != program.getRecording()) {

            if (null != program.getRecording().getRecGroup()
                    && !"livetv".equalsIgnoreCase(program.getRecording().getRecGroup())
                    && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) {
                String cleaned = ArticleCleaner.clean(program.getTitle());
                if (!programGroups.containsKey(cleaned)) {

                    ProgramGroup programGroup = new ProgramGroup();
                    programGroup.setTitle(program.getTitle());
                    programGroup.setCategory(program.getCategory());
                    programGroup.setInetref(program.getInetref());
                    programGroup.setSort(0);

                    programGroups.put(cleaned, programGroup);
                }//  www.ja  va 2s.  c o  m

            }

        }

    }

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    Log.v(TAG, "processProgramGroups : adding 'All' program group in programGroups");
    ProgramGroup all = new ProgramGroup(null, "All", "All", "All", "", 1);
    programGroups.put(all.getProgramGroup(), all);

    String[] programGroupProjection = new String[] { ProgramGroupConstants._ID };
    String programGroupSelection = ProgramGroupConstants.FIELD_PROGRAM_GROUP + " = ?";

    programGroupSelection = appendLocationHostname(context, locationProfile, programGroupSelection, null);

    for (String key : programGroups.keySet()) {
        Log.v(TAG, "processProgramGroups : processing programGroup '" + key + "'");

        ProgramGroup programGroup = programGroups.get(key);

        ContentValues programValues = convertProgramGroupToContentValues(locationProfile, programGroup);
        Cursor programGroupCursor = context.getContentResolver().query(ProgramGroupConstants.CONTENT_URI,
                programGroupProjection, programGroupSelection, new String[] { key }, null);
        if (programGroupCursor.moveToFirst()) {

            Long id = programGroupCursor
                    .getLong(programGroupCursor.getColumnIndexOrThrow(ProgramGroupConstants._ID));
            ops.add(ContentProviderOperation
                    .newUpdate(ContentUris.withAppendedId(ProgramGroupConstants.CONTENT_URI, id))
                    .withValues(programValues).withYieldAllowed(true).build());

        } else {

            ops.add(ContentProviderOperation.newInsert(ProgramGroupConstants.CONTENT_URI)
                    .withValues(programValues).withYieldAllowed(true).build());
        }
        programGroupCursor.close();
        count++;

        if (count > 100) {
            Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : remove deleted program groups");
    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    String deleteProgramGroupSelection = ProgramGroupConstants.FIELD_LAST_MODIFIED_DATE + " < ?";
    String[] deleteProgramGroupArgs = new String[] { String.valueOf(lastModified.getMillis()) };

    deleteProgramGroupSelection = appendLocationHostname(context, locationProfile, deleteProgramGroupSelection,
            ProgramGroupConstants.TABLE_NAME);

    ops.add(ContentProviderOperation.newDelete(ProgramGroupConstants.CONTENT_URI)
            .withSelection(deleteProgramGroupSelection, deleteProgramGroupArgs).withYieldAllowed(true).build());

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : exit");
}

From source file:org.mythtv.service.dvr.v25.RecordingRuleHelperV25.java

License:Open Source License

private int load(final Context context, final LocationProfile locationProfile,
        final org.mythtv.services.api.v025.beans.RecRule[] recordingRules)
        throws RemoteException, OperationApplicationException {
    Log.d(TAG, "load : enter");

    if (null == context)
        throw new RuntimeException("RecordingRuleHelperV25 is not initialized");

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    for (org.mythtv.services.api.v025.beans.RecRule recordingRule : recordingRules) {

        processRecordingRule(context, locationProfile, ops, recordingRule);
        count++;//from   w w  w .java2s  .c o  m

        if (count > BATCH_COUNT_LIMIT) {
            Log.i(TAG, "load : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);

            count = 0;
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying final batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    deleteRecordingRules(context, locationProfile, ops, lastModified);

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying delete batch for transactions");

        processBatch(context, ops, processed, count);
    }

    //      Log.v( TAG, "load : exit" );
    return processed;
}

From source file:org.mythtv.service.dvr.v26.RecordedHelperV26.java

License:Open Source License

private void processProgramGroups(final Context context, final LocationProfile locationProfile,
        Program[] programs) throws RemoteException, OperationApplicationException {
    Log.v(TAG, "processProgramGroups : enter");

    if (null == context)
        throw new RuntimeException("RecordedHelperV26 is not initialized");

    Map<String, ProgramGroup> programGroups = new TreeMap<String, ProgramGroup>();
    for (Program program : programs) {

        if (null != program.getRecording()) {

            if (null != program.getRecording().getRecGroup()
                    && !"livetv".equalsIgnoreCase(program.getRecording().getRecGroup())
                    && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) {
                String cleaned = ArticleCleaner.clean(program.getTitle());
                if (!programGroups.containsKey(cleaned)) {

                    ProgramGroup programGroup = new ProgramGroup();
                    programGroup.setTitle(program.getTitle());
                    programGroup.setCategory(program.getCategory());
                    programGroup.setInetref(program.getInetref());
                    programGroup.setSort(0);

                    programGroups.put(cleaned, programGroup);
                }//from  w w w.  j a v a 2s .  c o  m

            }

        }

    }

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    Log.v(TAG, "processProgramGroups : adding 'All' program group in programGroups");
    ProgramGroup all = new ProgramGroup(null, "All", "All", "All", "", 1);
    programGroups.put(all.getProgramGroup(), all);

    String[] programGroupProjection = new String[] { ProgramGroupConstants._ID };
    String programGroupSelection = ProgramGroupConstants.FIELD_PROGRAM_GROUP + " = ?";

    programGroupSelection = appendLocationHostname(context, locationProfile, programGroupSelection, null);

    for (String key : programGroups.keySet()) {
        Log.v(TAG, "processProgramGroups : processing programGroup '" + key + "'");

        ProgramGroup programGroup = programGroups.get(key);

        ContentValues programValues = convertProgramGroupToContentValues(locationProfile, programGroup);
        Cursor programGroupCursor = context.getContentResolver().query(ProgramGroupConstants.CONTENT_URI,
                programGroupProjection, programGroupSelection, new String[] { key }, null);
        if (programGroupCursor.moveToFirst()) {

            Long id = programGroupCursor
                    .getLong(programGroupCursor.getColumnIndexOrThrow(ProgramGroupConstants._ID));
            ops.add(ContentProviderOperation
                    .newUpdate(ContentUris.withAppendedId(ProgramGroupConstants.CONTENT_URI, id))
                    .withValues(programValues).withYieldAllowed(true).build());

        } else {

            ops.add(ContentProviderOperation.newInsert(ProgramGroupConstants.CONTENT_URI)
                    .withValues(programValues).withYieldAllowed(true).build());
        }
        programGroupCursor.close();
        count++;

        if (count > 100) {
            Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : remove deleted program groups");
    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    String deleteProgramGroupSelection = ProgramGroupConstants.FIELD_LAST_MODIFIED_DATE + " < ?";
    String[] deleteProgramGroupArgs = new String[] { String.valueOf(lastModified.getMillis()) };

    deleteProgramGroupSelection = appendLocationHostname(context, locationProfile, deleteProgramGroupSelection,
            ProgramGroupConstants.TABLE_NAME);

    ops.add(ContentProviderOperation.newDelete(ProgramGroupConstants.CONTENT_URI)
            .withSelection(deleteProgramGroupSelection, deleteProgramGroupArgs).withYieldAllowed(true).build());

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : exit");
}

From source file:org.mythtv.service.dvr.v26.RecordingRuleHelperV26.java

License:Open Source License

private int load(final Context context, final LocationProfile locationProfile,
        final org.mythtv.services.api.v026.beans.RecRule[] recordingRules)
        throws RemoteException, OperationApplicationException {
    Log.d(TAG, "load : enter");

    if (null == context)
        throw new RuntimeException("RecordingRuleHelperV26 is not initialized");

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    for (org.mythtv.services.api.v026.beans.RecRule recordingRule : recordingRules) {

        processRecordingRule(context, locationProfile, ops, recordingRule);
        count++;/*from   w  w  w  .  j a v a2 s .c  o m*/

        if (count > BATCH_COUNT_LIMIT) {
            Log.i(TAG, "load : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);

            count = 0;
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying final batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    deleteRecordingRules(context, locationProfile, ops, lastModified);

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying delete batch for transactions");

        processBatch(context, ops, processed, count);
    }

    //      Log.v( TAG, "load : exit" );
    return processed;
}

From source file:org.mythtv.service.dvr.v27.RecordedHelperV27.java

License:Open Source License

private void processProgramGroups(final Context context, final LocationProfile locationProfile,
        Program[] programs) throws RemoteException, OperationApplicationException {
    Log.v(TAG, "processProgramGroups : enter");

    if (null == context)
        throw new RuntimeException("RecordedHelperV27 is not initialized");

    Map<String, ProgramGroup> programGroups = new TreeMap<String, ProgramGroup>();
    for (Program program : programs) {

        if (null != program.getRecording()) {

            if (null != program.getRecording().getRecGroup()
                    && !"livetv".equalsIgnoreCase(program.getRecording().getRecGroup())
                    && !"deleted".equalsIgnoreCase(program.getRecording().getRecGroup())) {
                String cleaned = ArticleCleaner.clean(program.getTitle());
                if (!programGroups.containsKey(cleaned)) {

                    ProgramGroup programGroup = new ProgramGroup();
                    programGroup.setTitle(program.getTitle());
                    programGroup.setCategory(program.getCategory());
                    programGroup.setInetref(program.getInetref());
                    programGroup.setSort(0);

                    programGroups.put(cleaned, programGroup);
                }/*w w  w  .j  a v  a  2  s  .c  o m*/

            }

        }

    }

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    Log.v(TAG, "processProgramGroups : adding 'All' program group in programGroups");
    ProgramGroup all = new ProgramGroup(null, "All", "All", "All", "", 1);
    programGroups.put(all.getProgramGroup(), all);

    String[] programGroupProjection = new String[] { ProgramGroupConstants._ID };
    String programGroupSelection = ProgramGroupConstants.FIELD_PROGRAM_GROUP + " = ?";

    programGroupSelection = appendLocationHostname(context, locationProfile, programGroupSelection, null);

    for (String key : programGroups.keySet()) {
        Log.v(TAG, "processProgramGroups : processing programGroup '" + key + "'");

        ProgramGroup programGroup = programGroups.get(key);

        ContentValues programValues = convertProgramGroupToContentValues(locationProfile, programGroup);
        Cursor programGroupCursor = context.getContentResolver().query(ProgramGroupConstants.CONTENT_URI,
                programGroupProjection, programGroupSelection, new String[] { key }, null);
        if (programGroupCursor.moveToFirst()) {

            Long id = programGroupCursor
                    .getLong(programGroupCursor.getColumnIndexOrThrow(ProgramGroupConstants._ID));
            ops.add(ContentProviderOperation
                    .newUpdate(ContentUris.withAppendedId(ProgramGroupConstants.CONTENT_URI, id))
                    .withValues(programValues).withYieldAllowed(true).build());

        } else {

            ops.add(ContentProviderOperation.newInsert(ProgramGroupConstants.CONTENT_URI)
                    .withValues(programValues).withYieldAllowed(true).build());
        }
        programGroupCursor.close();
        count++;

        if (count > 100) {
            Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : remove deleted program groups");
    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    String deleteProgramGroupSelection = ProgramGroupConstants.FIELD_LAST_MODIFIED_DATE + " < ?";
    String[] deleteProgramGroupArgs = new String[] { String.valueOf(lastModified.getMillis()) };

    deleteProgramGroupSelection = appendLocationHostname(context, locationProfile, deleteProgramGroupSelection,
            ProgramGroupConstants.TABLE_NAME);

    ops.add(ContentProviderOperation.newDelete(ProgramGroupConstants.CONTENT_URI)
            .withSelection(deleteProgramGroupSelection, deleteProgramGroupArgs).withYieldAllowed(true).build());

    if (!ops.isEmpty()) {
        Log.v(TAG, "processProgramGroups : applying batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    Log.v(TAG, "processProgramGroups : exit");
}

From source file:org.mythtv.service.dvr.v27.RecordingRuleHelperV27.java

License:Open Source License

private int load(final Context context, final LocationProfile locationProfile,
        final org.mythtv.services.api.v027.beans.RecRule[] recordingRules)
        throws RemoteException, OperationApplicationException {
    Log.d(TAG, "load : enter");

    if (null == context)
        throw new RuntimeException("RecordingRuleHelperV27 is not initialized");

    int processed = -1;
    int count = 0;

    ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();

    for (org.mythtv.services.api.v027.beans.RecRule recordingRule : recordingRules) {

        processRecordingRule(context, locationProfile, ops, recordingRule);
        count++;//from w  w w .j  a  va2s .c o  m

        if (count > BATCH_COUNT_LIMIT) {
            Log.i(TAG, "load : applying batch for '" + count + "' transactions");

            processBatch(context, ops, processed, count);

            count = 0;
        }

    }

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying final batch for '" + count + "' transactions");

        processBatch(context, ops, processed, count);
    }

    ops = new ArrayList<ContentProviderOperation>();

    DateTime lastModified = new DateTime();
    lastModified = lastModified.minusHours(1);

    deleteRecordingRules(context, locationProfile, ops, lastModified);

    if (!ops.isEmpty()) {
        Log.v(TAG, "load : applying delete batch for transactions");

        processBatch(context, ops, processed, count);
    }

    //      Log.v( TAG, "load : exit" );
    return processed;
}

From source file:org.n52.sos.ds.hibernate.testdata.IoosHibernateTestDataManager.java

License:Open Source License

private static void insertObservation(Set<ObservationConstellation> obsConsts,
        OmObservationConstellation omObsConst, DateTime obsEndTime, FeatureOfInterest feature, String unit,
        Map<String, Codespace> codespaceCache, Map<String, Unit> unitCache, Session session)
        throws OwsExceptionReport {
    for (int j = 0; j < NUM_OBS_PER_SENSOR; j++) {
        OmObservation obs = new OmObservation();
        obs.setObservationConstellation(omObsConst);

        double obsValue = randomInRange(5.0, 32.0, 3);
        DateTime obsTime = obsEndTime.minusHours(j);
        QuantityValue quantityValue = new QuantityValue(obsValue, unit);
        obs.setValue(new SingleObservationValue<Double>(new TimeInstant(obsTime), quantityValue));
        seriesObservationDAO.insertObservationSingleValue(obsConsts, feature, obs, codespaceCache, unitCache,
                session);//from  www .j av  a 2s  .co m
    }
    session.flush();
    session.clear();
}

From source file:org.openhab.binding.sagercaster.internal.SagerCasterBinding.java

License:Open Source License

protected HistoricItem getPreviousValue(Item theItem) {
    DateTime now = new DateTime();
    AbstractInstant earlier = now.minusHours(6);
    if (persistenceService == null) {
        return PersistenceExtensions.historicState(theItem, earlier);
    } else {/*  w ww  .j  a v  a 2s .c  o m*/
        return PersistenceExtensions.historicState(theItem, earlier, persistenceService);
    }
}

From source file:org.openmrs.module.appointmentschedulingui.fragment.controller.MiniPatientAppointmentsFragmentController.java

License:Mozilla Public License

public void controller(@RequestParam("patientId") Patient patient, FragmentModel model,
        @SpringBean CoreAppsProperties coreAppsProperties, @SpringBean AppointmentService appointmentService) {

    DateTime curDate = new DateTime(new Date());
    Date date48HrsAgo = new Date(curDate.minusHours(48).withTimeAtStartOfDay().getMillis());
    List<AppointmentStatus> statuses = AppointmentStatus.getNotCancelledAppointmentStatuses();
    List<Appointment> patientAppointments = appointmentService.getAppointmentsByConstraints(date48HrsAgo, null,
            null, null, null, patient, statuses);
    List<AppointmentRequest> patientAppointmentRequests = appointmentService
            .getAppointmentRequestsByConstraints(patient, null, null,
                    AppointmentRequest.AppointmentRequestStatus.PENDING);
    model.addAttribute("patientAppointments", patientAppointments);
    model.addAttribute("patientAppointmentRequests", patientAppointmentRequests);
    model.addAttribute("timeFormatter", new SimpleDateFormat("h:mm a", Context.getLocale()));
    model.addAttribute("dashboardUrl", coreAppsProperties.getDashboardUrl());
}

From source file:org.richfaces.fragment.calendar.TimeEditor.java

License:Open Source License

public DateTime getTime() {
    int seconds = (getSecondsSpinner() != null ? getSecondsSpinner().getValue() : defaultSeconds);
    int minutes = (getMinutesSpinner() != null ? getMinutesSpinner().getValue() : defaultMinutes);
    int hours = (getHoursSpinner() != null ? getHoursSpinner().getValue() : defaultHours);
    DateTime result = new DateTime().withHourOfDay(hours).withMinuteOfHour(minutes).withSecondOfMinute(seconds);
    TimeSignSpinner tss = getTimeSignSpinner();
    if (tss != null) {
        switch (tss.getValue()) {
        case AM:/*from ww  w . ja  v  a 2 s .  co m*/
            if (result.getHourOfDay() == 12) {//12:xx am -> 00:xx
                result = result.minusHours(12);
            }
            break;
        case PM:
            if (result.getHourOfDay() != 12) {
                result = result.plusHours(12);
            }
            break;
        default:
            throw new IllegalArgumentException("Unknown switch");
        }
    }
    return result;
}