Example usage for org.joda.time Days getDays

List of usage examples for org.joda.time Days getDays

Introduction

In this page you can find the example usage for org.joda.time Days getDays.

Prototype

public int getDays() 

Source Link

Document

Gets the number of days that this period represents.

Usage

From source file:be.fedict.hsm.admin.webapp.CertificateView.java

License:Open Source License

public int getDaysLeft() {
    DateTime notAfter = new DateTime(this.certificate.getNotAfter());
    DateTime now = new DateTime();
    Days days = Days.daysBetween(new DateMidnight(now), new DateMidnight(notAfter));
    return days.getDays();
}

From source file:bench.buf_field.MainTradeDate.java

License:BSD License

public static void main(final String... args) {

    log.debug("init");

    {//  www .  jav a  2  s.co m

        final BenchEmpty message = BenchEmpty.newBuilder().build();

        log.debug("empty size : {}", message.getSerializedSize());

    }

    {

        final int value = 1;

        final BenchTradeDate32 message = BenchTradeDate32.newBuilder().setTradeDate(value).build();

        final int size = message.getSerializedSize();

        log.debug(" '1' value : {} size : {}", value, size);

    }

    {

        final LocalDate dateOne = new LocalDate(1970, 1, 1);
        final LocalDate dateTwo = new LocalDate();
        // log.debug("date range : {} {} ", dateOne, dateTwo);

        final Days daysRange = Days.daysBetween(dateOne, dateTwo);

        final int value = daysRange.getDays();

        final BenchTradeDate32 message = BenchTradeDate32.newBuilder().setTradeDate(value).build();

        final int size = message.getSerializedSize();

        log.debug(" 'since' value : {} size : {}", value, size);

    }

    {

        final int value = 20120104; // 2012-01-04

        final BenchTradeDate32 message = BenchTradeDate32.newBuilder().setTradeDate(value).build();

        final int size = message.getSerializedSize();

        log.debug(" 'fix days' value : {} size : {}", value, size);

    }

    {

        final long value = System.currentTimeMillis();

        final BenchTradeDate64 message = BenchTradeDate64.newBuilder().setTradeDate(value).build();

        final int size = message.getSerializedSize();

        log.debug(" 'millisUTC' value : {} size : {}", value, size);

    }

    {

        final long value = 20120104081231000L; // 2012-01-04 08:12:31 000

        final BenchTradeDate64 message = BenchTradeDate64.newBuilder().setTradeDate(value).build();

        final int size = message.getSerializedSize();

        log.debug(" 'fix millis' value : {} size : {}", value, size);

    }

    {

        log.debug("############################");

        final int yearBase = 1970;

        log.debug(" base : {}", yearBase);

        for (int yearThis = 2010; yearThis < 2020; yearThis++) {

            final LocalDate dateOne = new LocalDate(yearBase, 1, 1);
            final LocalDate dateTwo = new LocalDate(yearThis, 1, 1);
            // log.debug("date range : {} {} ", dateOne, dateTwo);

            final Days daysRange = Days.daysBetween(dateOne, dateTwo);

            final int value = daysRange.getDays();

            final BenchTradeDate32 message = BenchTradeDate32.newBuilder().setTradeDate(value).build();

            final int size = message.getSerializedSize();

            log.debug(" this : {} ; size : {} ;", yearThis, size);

        }

    }

    log.debug("done");

}

From source file:ca.barrenechea.ticker.utils.TimeUtils.java

License:Apache License

public static TimeSpan getSpan(long start, long end) {
    if (end <= start) {
        return new TimeSpan(0, 0, 0);
    }/*www .  j  av a2  s.c  o  m*/

    Interval interval = new Interval(start, end);

    Days days = Days.daysIn(interval);
    Hours hours = Hours.hoursIn(interval).minus(days.toStandardHours());
    Minutes minutes = Minutes.minutesIn(interval).minus(days.toStandardMinutes())
            .minus(hours.toStandardMinutes());

    return new TimeSpan(days.getDays(), hours.getHours(), minutes.getMinutes());
}

From source file:com.axelor.apps.organisation.web.TrainingController.java

License:Open Source License

public void computeDuration(ActionRequest request, ActionResponse response) {

    Training training = request.getContext().asType(Training.class);

    if (training.getEndDate() != null && training.getStartDate() != null) {
        Days d = Days.daysBetween(training.getStartDate(), training.getEndDate());
        response.setValue("duration", d.getDays());
    } else {//from w w  w .j  av  a 2  s .c  om
        response.setValue("duration", null);
    }
}

From source file:com.barchart.feed.ddf.resolver.provider.Status.java

License:BSD License

boolean isPending() {

    if (!wasRunSuccess) {
        return true;
    }//from  www . j a v  a 2  s .c om

    final DateTime previous = new DateTime(lastRunTime);

    final DateTime current = new DateTime(DateTimeZone.UTC);

    final Days days = Days.daysBetween(previous, current);

    final int count = days.getDays();

    if (count > 1) {
        return true;
    }

    return false;

}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffDate.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//* w  w w .  j av  a 2  s .  c om*/
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    java.util.Date startDate = null;
    java.util.Date endDate = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startDate = (java.util.Date) inputValues[1];
        startCal = Calendar.getInstance();
        startCal.setTime(startDate);

        endDate = (java.util.Date) inputValues[2];
        endCal = Calendar.getInstance();
        endCal.setTime(endDate);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), 0, 0, 0, 0);

        if (datePart.equalsIgnoreCase("second")) {
            Seconds seconds = Seconds.secondsBetween(startDateTime, endDateTime);
            dateLength = seconds.getSeconds();
        }

        if (datePart.equalsIgnoreCase("minute")) {
            Minutes minutes = Minutes.minutesBetween(startDateTime, endDateTime);
            dateLength = minutes.getMinutes();
        }

        if (datePart.equalsIgnoreCase("hour")) {
            Hours hours = Hours.hoursBetween(startDateTime, endDateTime);
            dateLength = hours.getHours();
        }

        if (datePart.equalsIgnoreCase("day")) {
            Days days = Days.daysBetween(startDateTime, endDateTime);
            dateLength = days.getDays();
        }

        if (datePart.equalsIgnoreCase("week")) {
            Weeks weeks = Weeks.weeksBetween(startDateTime, endDateTime);
            dateLength = weeks.getWeeks();
        }

        if (datePart.equalsIgnoreCase("month")) {
            Months months = Months.monthsBetween(startDateTime, endDateTime);
            dateLength = months.getMonths();
        }

        if (datePart.equalsIgnoreCase("year")) {
            Years years = Years.yearsBetween(startDateTime, endDateTime);
            dateLength = years.getYears();
        }

        result = new Long(dateLength);
    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.cisco.dvbu.ps.utils.date.DateDiffTimestamp.java

License:Open Source License

/**
 * Called to invoke the stored procedure.  Will only be called a
 * single time per instance.  Can throw CustomProcedureException or
 * SQLException if there is an error during invoke.
 *//*from   ww w . ja  va 2 s. co m*/
public void invoke(Object[] inputValues) throws CustomProcedureException, SQLException {
    Timestamp startTimestamp = null;
    Timestamp endTimestamp = null;
    Calendar startCal = null;
    Calendar endCal = null;
    DateTime startDateTime = null;
    DateTime endDateTime = null;
    String datePart = null;
    long dateLength = 0;

    try {
        result = null;
        if (inputValues[0] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[1] == null) {
            result = new Long(dateLength);
            return;
        }

        if (inputValues[2] == null) {
            result = new Long(dateLength);
            return;
        }

        datePart = (String) inputValues[0];
        startTimestamp = (Timestamp) inputValues[1];
        // long startMilliseconds = startTimestamp.getTime() +
        // (startTimestamp.getNanos() / 1000000);
        long startMilliseconds = startTimestamp.getTime()
                + (startTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);
        startCal = Calendar.getInstance();
        startCal.setTimeInMillis(startMilliseconds);

        endTimestamp = (Timestamp) inputValues[2];
        // long endMilliseconds = endTimestamp.getTime() +
        // (endTimestamp.getNanos() / 1000000);
        long endMilliseconds = endTimestamp.getTime() + (endTimestamp.getNanos() % 1000000L >= 500000L ? 1 : 0);

        endCal = Calendar.getInstance();
        endCal.setTimeInMillis(endMilliseconds);

        startDateTime = new DateTime(startCal.get(Calendar.YEAR), startCal.get(Calendar.MONTH) + 1,
                startCal.get(Calendar.DAY_OF_MONTH), startCal.get(Calendar.HOUR_OF_DAY),
                startCal.get(Calendar.MINUTE), startCal.get(Calendar.SECOND),
                startCal.get(Calendar.MILLISECOND));
        endDateTime = new DateTime(endCal.get(Calendar.YEAR), endCal.get(Calendar.MONTH) + 1,
                endCal.get(Calendar.DAY_OF_MONTH), endCal.get(Calendar.HOUR_OF_DAY),
                endCal.get(Calendar.MINUTE), endCal.get(Calendar.SECOND), endCal.get(Calendar.MILLISECOND));

        Interval interval = new Interval(startDateTime, endDateTime);

        if (datePart.equalsIgnoreCase("second") || datePart.equalsIgnoreCase("ss")) {
            Seconds seconds = Seconds.secondsIn(interval);
            dateLength = seconds.getSeconds();
        } else if (datePart.equalsIgnoreCase("minute") || datePart.equalsIgnoreCase("mi")) {
            Minutes minutes = Minutes.minutesIn(interval);
            dateLength = minutes.getMinutes();
        } else if (datePart.equalsIgnoreCase("hour") || datePart.equalsIgnoreCase("hh")) {
            Hours hours = Hours.hoursIn(interval);
            dateLength = hours.getHours();
        } else if (datePart.equalsIgnoreCase("day") || datePart.equalsIgnoreCase("dd")) {
            Days days = Days.daysIn(interval);
            dateLength = days.getDays();
        } else if (datePart.equalsIgnoreCase("week") || datePart.equalsIgnoreCase("wk")) {
            Weeks weeks = Weeks.weeksIn(interval);
            dateLength = weeks.getWeeks();
        } else if (datePart.equalsIgnoreCase("month") || datePart.equalsIgnoreCase("mm")) {
            Months months = Months.monthsIn(interval);
            dateLength = months.getMonths();
        } else if (datePart.equalsIgnoreCase("year") || datePart.equalsIgnoreCase("yy")) {
            Years years = Years.yearsIn(interval);
            dateLength = years.getYears();
        } else if (datePart.equalsIgnoreCase("millisecond") || datePart.equalsIgnoreCase("ms")) {
            dateLength = (endTimestamp.getTime() - startTimestamp.getTime()); // millis
        } else if (datePart.equalsIgnoreCase("microsecond") || datePart.equalsIgnoreCase("mcs")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000L // micros
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()) / 1000; // nanos/1000
        } else if (datePart.equalsIgnoreCase("nanosecond") || datePart.equalsIgnoreCase("ns")) {
            dateLength = ((endTimestamp.getTime() - startTimestamp.getTime()) / 1000) // seconds
                    * 1000000000L // nanos
                    + (endTimestamp.getNanos() - startTimestamp.getNanos()); // nanos
        } else {
            throw new IllegalArgumentException(datePart);
        }

        result = new Long(dateLength);

    } catch (Throwable t) {
        throw new CustomProcedureException(t);
    }
}

From source file:com.datastax.driver.extras.codecs.joda.LocalDateCodec.java

License:Apache License

@Override
public ByteBuffer serialize(LocalDate value, ProtocolVersion protocolVersion) {
    if (value == null)
        return null;
    Days days = daysBetween(EPOCH, value);
    int unsigned = fromSignedToUnsignedInt(days.getDays());
    return cint().serializeNoBoxing(unsigned, protocolVersion);
}

From source file:com.divudi.bean.pharmacy.ReportsTransfer.java

public void fillMovingWithStock() {
    String sql;/* w  w  w .j  av  a 2 s .c o  m*/
    Map m = new HashMap();
    m.put("i", institution);
    m.put("t1", BillType.PharmacyTransferIssue);
    m.put("t2", BillType.PharmacyPre);
    m.put("fd", fromDate);
    m.put("td", toDate);
    BillItem bi = new BillItem();

    sql = "select bi.item, abs(SUM(bi.pharmaceuticalBillItem.qty)), "
            + "abs(SUM(bi.pharmaceuticalBillItem.stock.itemBatch.purcahseRate * bi.pharmaceuticalBillItem.qty)), "
            + "SUM(bi.pharmaceuticalBillItem.stock.itemBatch.retailsaleRate * bi.qty)) "
            + "FROM BillItem bi where bi.retired=false and  bi.bill.department.institution=:i and "
            + "(bi.bill.billType=:t1 or bi.bill.billType=:t2) and "
            + "bi.bill.billDate between :fd and :td group by bi.item "
            + "order by  SUM(bi.pharmaceuticalBillItem.qty) desc";
    List<Object[]> objs = getBillItemFacade().findAggregates(sql, m);
    movementRecordsQty = new ArrayList<>();
    for (Object[] obj : objs) {
        StockReportRecord r = new StockReportRecord();
        r.setItem((Item) obj[0]);
        r.setQty((Double) obj[1]);
        Days daysBetween = Days.daysBetween(LocalDate.fromDateFields(fromDate),
                LocalDate.fromDateFields(toDate));
        int ds = daysBetween.getDays();
        r.setPurchaseValue((Double) (r.getQty() / ds));
        //            r.setRetailsaleValue((Double) obj[2]);
        r.setStockQty(getPharmacyBean().getStockQty(r.getItem(), institution));
        movementRecordsQty.add(r);
    }
}

From source file:com.divudi.bean.store.StoreReportsTransfer.java

public void fillMovingWithStock() {
    String sql;//from  ww w  .  j  a v  a2s .  c o  m
    Map m = new HashMap();
    m.put("i", institution);
    m.put("t1", BillType.StoreTransferIssue);
    m.put("t2", BillType.StorePre);
    m.put("fd", fromDate);
    m.put("td", toDate);
    BillItem bi = new BillItem();

    sql = "select bi.item, abs(SUM(bi.pharmaceuticalBillItem.qty)), "
            + "abs(SUM(bi.pharmaceuticalBillItem.stock.itemBatch.purcahseRate * bi.pharmaceuticalBillItem.qty)), "
            + "SUM(bi.pharmaceuticalBillItem.stock.itemBatch.retailsaleRate * bi.qty)) "
            + "FROM BillItem bi where bi.retired=false and  bi.bill.department.institution=:i and "
            + "(bi.bill.billType=:t1 or bi.bill.billType=:t2) and "
            + "bi.bill.billDate between :fd and :td group by bi.item "
            + "order by  SUM(bi.pharmaceuticalBillItem.qty) desc";
    List<Object[]> objs = getBillItemFacade().findAggregates(sql, m);
    movementRecordsQty = new ArrayList<>();
    for (Object[] obj : objs) {
        StockReportRecord r = new StockReportRecord();
        r.setItem((Item) obj[0]);
        r.setQty((Double) obj[1]);
        Days daysBetween = Days.daysBetween(LocalDate.fromDateFields(fromDate),
                LocalDate.fromDateFields(toDate));
        int ds = daysBetween.getDays();
        r.setPurchaseValue((Double) (r.getQty() / ds));
        //            r.setRetailsaleValue((Double) obj[2]);
        r.setStockQty(getStoreBean().getStockQty(r.getItem(), institution));
        movementRecordsQty.add(r);
    }
}