Example usage for org.joda.time LocalDateTime minus

List of usage examples for org.joda.time LocalDateTime minus

Introduction

In this page you can find the example usage for org.joda.time LocalDateTime minus.

Prototype

public LocalDateTime minus(ReadablePeriod period) 

Source Link

Document

Returns a copy of this datetime with the specified period taken away.

Usage

From source file:ee.ut.soras.ajavtV2.mudel.ajavaljend.arvutus.TimeMLDateTimePoint.java

License:Open Source License

public void addToField(Granulaarsus field, Period period, int direction) {
    if (field.compareByCoarseRank(Granulaarsus.WEEK_OF_YEAR) == -1) {
        // ---- paev, tund, minut
        LocalDateTime ajaFookus = getAsLocalDateTime();
        try {//from   ww w.  j  a v a  2  s. c o m
            if (direction > 0) {
                ajaFookus = ajaFookus.plus(period);
            } else {
                ajaFookus = ajaFookus.minus(period);
            }
            this.functionOtherThanSetUsed = true;
        } catch (Exception e) {
            // Erindi korral jaabki muutmata
        }
        this.underlyingTime = ajaFookus.toLocalTime();
        this.underlyingDate = ajaFookus.toLocalDate();
        if (field.compareByCoarseRank(Granulaarsus.DAY_OF_MONTH) == 0) {
            this.dateModified = true;
            updateTimeRepresentation(Granulaarsus.HOUR_OF_DAY, null, false, ADD_TYPE_OPERATION);
        } else {
            updateTimeRepresentation(Granulaarsus.MINUTE, null, false, ADD_TYPE_OPERATION);
        }
        if (dateModified) {
            updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        }
    } else {
        // ---- nadal, kuu, aasta, sajand
        try {
            if (direction > 0) {
                this.underlyingDate = (this.underlyingDate).plus(period);
            } else {
                this.underlyingDate = (this.underlyingDate).minus(period);
            }
            this.functionOtherThanSetUsed = true;
            this.dateModified = true;
        } catch (Exception e) {
            // Erindi korral jaabki muutmata
        }
        if (field == Granulaarsus.MONTH || field == Granulaarsus.WEEK_OF_YEAR) {
            updateDateRepresentation(Granulaarsus.DAY_OF_MONTH, null, false, ADD_TYPE_OPERATION);
        }
        if (field == Granulaarsus.YEAR) {
            updateDateRepresentation(Granulaarsus.MONTH, null, false, ADD_TYPE_OPERATION);
        }
        if (field == Granulaarsus.CENTURY_OF_ERA) {
            updateDateRepresentation(Granulaarsus.YEAR, null, false, ADD_TYPE_OPERATION);
        }
    }
}

From source file:org.apache.gobblin.data.management.copy.TimeAwareRecursiveCopyableDataset.java

License:Apache License

@Override
protected List<FileStatus> getFilesAtPath(FileSystem fs, Path path, PathFilter fileFilter) throws IOException {
    DateTimeFormatter formatter = DateTimeFormat.forPattern(datePattern);
    LocalDateTime endDate = currentTime;
    LocalDateTime startDate = endDate.minus(this.lookbackPeriod);

    DateRangeIterator dateRangeIterator = new DateRangeIterator(startDate, endDate, isPatternHourly);
    List<FileStatus> fileStatuses = Lists.newArrayList();
    while (dateRangeIterator.hasNext()) {
        Path pathWithDateTime = new Path(path, dateRangeIterator.next().toString(formatter));
        fileStatuses.addAll(super.getFilesAtPath(fs, pathWithDateTime, fileFilter));
    }/*  ww  w  . j av  a  2  s  .c om*/
    return fileStatuses;
}

From source file:org.openmrs.module.referencedemodata.ReferenceDemoDataActivator.java

License:Open Source License

private Visit createDemoVisit(Patient patient, List<VisitType> visitTypes, Location location,
        boolean shortVisit) {
    LocalDateTime visitStart = LocalDateTime.now().minus(Period.days(randomBetween(0, 365 * 2)).withHours(3)); // past 2 years
    if (!shortVisit) {
        visitStart = visitStart.minus(Period.days(ADMISSION_DAYS_MAX + 1)); // just in case the start is today, back it up a few days.
    }// ww w .j  a v  a  2s  .  c o  m
    Visit visit = new Visit(patient, randomArrayEntry(visitTypes), visitStart.toDate());
    visit.setLocation(location);
    LocalDateTime vitalsTime = visitStart.plus(Period.minutes(randomBetween(1, 60)));
    visit.addEncounter(createDemoVitalsEncounter(patient, vitalsTime.toDate()));
    LocalDateTime visitNoteTime = visitStart.plus(Period.minutes(randomBetween(60, 120)));
    visit.addEncounter(createVisitNote(patient, visitNoteTime.toDate(), location));
    if (shortVisit) {
        LocalDateTime visitEndTime = visitNoteTime.plus(Period.minutes(30));
        visit.setStopDatetime(visitEndTime.toDate());
    } else {
        // admit now and discharge a few days later
        Location admitLocation = Context.getLocationService().getLocation("Inpatient Ward");
        visit.addEncounter(createEncounter("Admission", patient, visitNoteTime.toDate(), admitLocation));
        LocalDateTime dischargeDateTime = visitNoteTime
                .plus(Period.days(randomBetween(ADMISSION_DAYS_MIN, ADMISSION_DAYS_MAX)));
        visit.addEncounter(createEncounter("Discharge", patient, dischargeDateTime.toDate(), admitLocation));
        visit.setStopDatetime(dischargeDateTime.toDate());
    }
    return visit;
}