Example usage for org.joda.time Days daysBetween

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

Introduction

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

Prototype

public static Days daysBetween(ReadablePartial start, ReadablePartial end) 

Source Link

Document

Creates a Days representing the number of whole days between the two specified partial datetimes.

Usage

From source file:managers.Config.java

public static String returnMessage(String firstName, String rollNo, String title, String acc_no,
        String issue_date, String due_date, String return_date) {
    LocalDate returnDate = new LocalDate(return_date);
    LocalDate issueDate = new LocalDate(issue_date);
    String message = "Dear " + firstName + " (Roll No. : " + rollNo + ")"
            + "\nThe following book was issued by you at NIT Delhi Library on " + issue_date
            + "\n\nBook Title : " + title + "\nBook Accession Number : " + acc_no
            + "\nIssue Date(yyyy-mm-dd) : " + issue_date + "\nReturn Date(yyyy-mm-dd) : " + return_date
            + "\nDue Date(yyyy-mm-dd) : " + due_date + "\n\nThe book has been returned by you on  "
            + return_date + " after keeping it for " + Days.daysBetween(issueDate, returnDate).getDays()
            + " days" + "\nAs students are allowed to keep books for " + Config.studentIssueDuration
            + " days after issue " + "\nNo of days exceeded : " + Config.daysExceeded(return_date, due_date)
            + "\nRate for calculating fine : Rs." + Config.ChARGEPERDAY + "per day" + "\nFine : "
            + daysExceeded(return_date, due_date) * Config.ChARGEPERDAY
            + "\n\nIf you did not return this book, please contact the librarian as soon as possible."
            + "\nRegards" + "\nNIT Delhi Library"
            + "\n\n This is a system generated mail.Do not reply. Contact the library for any other details";
    return message;
}

From source file:mbsystem.controller.BookListController.java

/**
 * Get a list of latest books/*from   w w  w.j  ava2 s. c  o m*/
 *
 * @return latest books
 */
public List<Book> getLatestBooks() {
    List<Book> latestBooks = new ArrayList<>();
    try {
        DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        Date today = new Date();
        LocalDate localToday = LocalDate.fromDateFields(today);
        for (Book b : allBooks) {
            // the publishDate is stored as String in database
            String pubDateString = b.getPublishDate();
            // parse the string
            Date pubDate = df.parse(pubDateString);
            LocalDate localPubDate = LocalDate.fromDateFields(pubDate);
            // calculate the days since book published
            int publishedDays = Days.daysBetween(localPubDate, localToday).getDays();
            // if published within one year
            if (publishedDays < 365) {
                latestBooks.add(b);
            }
        }
    } catch (ParseException e) {
        System.out.println("Invalid date format.");
    }
    return latestBooks;
}

From source file:me.vertretungsplan.parser.WebUntisParser.java

License:Mozilla Public License

/**
 * find out if there's a holiday currently and if so, also display substitutions after it
 *
 * @return/*from ww w .  j  a v a  2  s . co m*/
 * @throws JSONException
 * @throws CredentialInvalidException
 * @throws IOException
 */
private int getDaysToAdd() throws JSONException, CredentialInvalidException, IOException {
    final LocalDate today = LocalDate.now();
    int daysToAdd = 0;
    try {
        //
        JSONArray holidays = getHolidays();
        for (int i = 0; i < holidays.length(); i++) {
            LocalDate startDate = DATE_FORMAT
                    .parseLocalDate(String.valueOf(holidays.getJSONObject(i).getInt("startDate")));
            LocalDate endDate = DATE_FORMAT
                    .parseLocalDate(String.valueOf(holidays.getJSONObject(i).getInt("endDate")));
            if (!startDate.isAfter(today.plusDays(6)) && !endDate.isBefore(today)) {
                if (startDate.isBefore(today)) {
                    daysToAdd += Days.daysBetween(today, endDate).getDays() + 1;
                } else {
                    daysToAdd += Days.daysBetween(startDate, endDate).getDays() + 2;
                }
            }
        }
    } catch (UnauthorizedException ignored) {

    }
    return daysToAdd;
}

From source file:mekhq.campaign.universe.NewsItem.java

License:Open Source License

/** Finalize this news item's date according to its precision, using the supplied seed */
public void finalizeDate(long seed) {
    if ((null == date) || (null == datePrecision) || (datePrecision == Precision.DAY)) {
        return;/*from   w  w  w. ja va 2 s.co  m*/
    }
    Random rnd = new Random(seed + date.getMillis());
    int maxRandomDays = 0;
    switch (datePrecision) {
    case MONTH:
        maxRandomDays = Days.daysBetween(date, date.plusMonths(1)).getDays();
        break;
    case YEAR:
        maxRandomDays = Days.daysBetween(date, date.plusYears(1)).getDays();
        break;
    case DECADE:
        maxRandomDays = Days.daysBetween(date, date.plusYears(10)).getDays();
        break;
    default:
        return;
    }
    date = date.plusDays(rnd.nextInt(maxRandomDays));
    datePrecision = Precision.DAY;
}

From source file:model.Emprestimo.java

private void calculaDiasAtraso() {
    int i = Days.daysBetween(dataDevolucao, devolucaoEfetiva).getDays();
    if (i <= 0) {
        this.diasAtraso = 0;
    } else {//from w w  w .  j a v  a  2s .c o m
        this.diasAtraso = i;
    }
}

From source file:models.AbstractBaseTrans.java

License:Open Source License

@Override
@Transient// w w  w  .j a  va2  s .  c  om
public String checkEditingConstraints() {
    if (!CacheUtils.isSpecialUser()) {
        AdminUserGroup group = CacheUtils.getUser().userGroup;
        if (id != null && group.editingTimeout > 0) {
            org.joda.time.DateTime today = new org.joda.time.DateTime(new Date());
            org.joda.time.DateTime insertAtDT = new org.joda.time.DateTime(insertAt);
            Days days = Days.daysBetween(insertAtDT, today);

            if (days.getDays() > group.editingTimeout) {
                return Messages.get("editing_timeout.alert", group.editingTimeout);
            }
        }

        org.joda.time.DateTime today = new org.joda.time.DateTime(new Date());
        org.joda.time.DateTime transDateDT = new org.joda.time.DateTime(transDate);
        Days days = Days.daysBetween(transDateDT, today);
        if (days.getDays() != 0 && !group.hasEditDifDate) {
            return Messages.get("editing_difdate.alert");
        }
    }

    if (isUsedForElse("trans_no", transNo)) {
        return Messages.get("trans.no") + " " + Messages.get("not.unique", transNo);
    }

    return super.checkEditingConstraints();
}

From source file:models.DeputadoFederalExercicio.java

License:Open Source License

/**
 * O clculo do nmero de dias  feito at hoje, se em aberto, ou at o dia final real
 * @return//w w  w. j a  v  a2 s  .  c o m
 */
public int getNumDays() {
    int days = 0;
    if (dataFim != null) {
        days = Days.daysBetween(new DateTime(dataInicio), new DateTime(dataFim)).getDays();
    } else {
        days = Days.daysBetween(new DateTime(dataInicio), new DateTime(new Date())).getDays();
    }

    return days;
}

From source file:models.JWeek.java

License:Apache License

/**
  * Gets the JiVitA week.//from   w  w w  .  j av  a  2  s  .co m
  *
  * @return the JiVitA week
  */
public int getJWeek() {
    Days days = Days.daysBetween(jivitaEpoch, new DateTime(this));
    double dDays = (double) days.getDays();
    double weeks = Math.ceil(dDays / 7.0d);
    return (int) weeks;
}

From source file:module.mission.domain.Mission.java

License:Open Source License

public int calculateNumberOfNights() {
    final LocalDate startDate = getDaparture().toLocalDate();
    final LocalDate endDate = getArrival().toLocalDate();
    return Days.daysBetween(startDate, endDate).getDays();
}

From source file:module.mission.domain.Mission.java

License:Open Source License

public int getDurationInDays() {
    return Days.daysBetween(getDaparture(), getArrival()).getDays();
}