Example usage for org.joda.time Duration getStandardDays

List of usage examples for org.joda.time Duration getStandardDays

Introduction

In this page you can find the example usage for org.joda.time Duration getStandardDays.

Prototype

public long getStandardDays() 

Source Link

Document

Gets the length of this duration in days assuming that there are the standard number of milliseconds in a day.

Usage

From source file:au.com.scds.chats.dom.call.Call.java

License:Apache License

public String validateUpdateTimes(DateTime start, DateTime end) {
    if (start.isAfter(end)) {
        return "End Time is before Start Time";
    }//from   ww  w  . ja v  a2  s . c o  m
    Duration duration = new Duration(getStartDateTime(), getEndDateTime());
    if (duration.getStandardDays() > 0) {
        return "End Time is not on the same date as Start Time";
    }
    return null;
}

From source file:ch.eitchnet.android.util.JodaHelper.java

License:Open Source License

public static String toDays(Duration duration) {
    Duration tmp = duration;
    double days = tmp.getStandardDays();
    if (days >= Integer.MAX_VALUE)
        throw new RuntimeException("Buffer overflow for number of days in duration: " + tmp);
    tmp = tmp.minus(Days.days((int) days).toStandardDuration());
    double hours = tmp.getStandardHours();
    if (hours >= Integer.MAX_VALUE)
        throw new RuntimeException("Buffer overflow for number of hours in duration: " + tmp);

    return Double.toString(days + (hours / 24));
}

From source file:classes.ManipulaDatas.java

public static long calculaAtraso(String dataVenc, String dataFim) {
    long calculo = 0;

    try {//from w ww  .j a v a 2  s.c o  m
        java.text.SimpleDateFormat df = new java.text.SimpleDateFormat("dd/MM/yyyy"); // criando um modelo de datas
        java.util.Date d1 = df.parse(dataVenc); //passando os valores das Strings para objetos do tipo Date
        java.util.Date d2 = df.parse(dataFim);

        DateTime dtf2 = new DateTime(d2);
        DateTime dtv2 = new DateTime(d1);

        Duration d = new Duration(dtf2, dtv2);
        long dias = (d.getStandardDays()) * -1;

        calculo = dias;
        calc_datas = calculo; //variavel global que armazena o conteudo do calculo

    } catch (ParseException ex) {
        Logger.getLogger(ManipulaDatas.class.getName()).log(Level.SEVERE, null, ex);
    }

    return calc_datas;
}

From source file:co.edu.uelbosque.sistemas.swiii.c3.historiaclinica.entities.Medico.java

private void setNacimiento(Calendar nacimiento) {
    Calendar ahora = Calendar.getInstance();
    long hoy = ahora.getTimeInMillis();
    long dias = hoy - nacimiento.getTimeInMillis();
    Duration d = new Duration(dias);
    this.dias = (int) d.getStandardDays();
    Period period = new Period(nacimiento.getTimeInMillis(), hoy, PeriodType.months());
    this.meses = period.getMonths();
    this.nacimiento = nacimiento;
}

From source file:com.bytestemplar.subgeniuswatchface.BT_SubgeniusWatchface.java

License:Apache License

private String getXDayCountdown() {
    DateTime today = DateTime.now();//from  w  w  w.  j  av  a  2s.  c om
    //DateTime today = new DateTime( 1998, 7, 6, 4, 20, 32, 0 );
    DateTime xday = new DateTime(today.getYear(), 7, 5, 7, 0, 0, 0);

    if (today.isAfter(xday)) {
        xday = new DateTime(today.getYear() + 1, 7, 5, 7, 0, 0, 0);
    }

    Duration dur = new Duration(today, xday);

    StringBuilder sb = new StringBuilder();

    if (dur.getStandardDays() > 0) {
        sb.append(dur.getStandardDays());
        sb.append(" Day");
        if (dur.getStandardDays() > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long hours = dur.getStandardHours() % 24;
    if (hours > 0) {
        sb.append(hours);
        sb.append(" Hour");
        if (hours > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long mins = dur.getStandardMinutes() % 60;
    if (mins > 0) {
        sb.append(mins);
        sb.append(" Minute");
        if (mins > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    long secs = dur.getStandardSeconds() % 60;
    if (secs > 0) {
        sb.append(secs);
        sb.append(" Second");
        if (secs > 1) {
            sb.append("s");
        }
        sb.append("\n");
    }

    sb.append("Until X-Day!");

    return sb.toString();
}

From source file:com.esofthead.mycollab.common.service.ibatis.TimelineTrackingServiceImpl.java

License:Open Source License

private List<Date> boundDays(DateTime start, DateTime end) {
    Duration duration = new Duration(start, end);
    long days = duration.getStandardDays();
    List<Date> dates = new ArrayList<>();
    //Will try to get from cache values from the end date to (startdate - 1)
    for (int i = 0; i <= days; i++) {
        dates.add(start.plusDays(i).toDate());
    }/*from   w w  w.j av a  2  s . co  m*/
    return dates;
}

From source file:com.pushinginertia.commons.ui.TimePeriod.java

License:Open Source License

public TimePeriod(final Duration duration) {
    ValidateAs.notNull(duration, "duration");
    final long days = duration.getStandardDays();

    // about 30.4 days in a month
    // N days: if dayCount <= 31
    // N weeks: if 31 < dayCount <= 61 and
    // N months: if 61 < dayCount
    final StringBuilder key = new StringBuilder("TimePeriod.");
    if (days < 1) {
        final long minutes = duration.getStandardMinutes();
        if (minutes < 60) {
            quantity = minutes;/*from   w ww  .  j av  a 2  s .co m*/
            key.append("Minute");
        } else {
            quantity = duration.getStandardHours();
            key.append("Hour");
        }
    } else if (days <= 31) {
        quantity = days;
        key.append("Day");
    } else if (days <= 61) {
        quantity = MathUtils.integerDivisionRound(days, 7);
        key.append("Week");
    } else {
        quantity = MathUtils.integerDivisionRound(days, 30);
        key.append("Month");
    }
    if (quantity != 1)
        key.append('s');
    descriptorResourceKey = key.toString();
}

From source file:com.spotify.helios.cli.Output.java

License:Apache License

public static String humanDuration(final Duration dur) {
    final Period p = dur.toPeriod().normalizedStandard();

    if (dur.getStandardSeconds() == 0) {
        return "0 seconds";
    } else if (dur.getStandardSeconds() < 60) {
        return format("%d second%s", p.getSeconds(), p.getSeconds() > 1 ? "s" : "");
    } else if (dur.getStandardMinutes() < 60) {
        return format("%d minute%s", p.getMinutes(), p.getMinutes() > 1 ? "s" : "");
    } else if (dur.getStandardHours() < 24) {
        return format("%d hour%s", p.getHours(), p.getHours() > 1 ? "s" : "");
    } else {/*ww w. ja v  a  2  s  .  co  m*/
        return format("%d day%s", dur.getStandardDays(), dur.getStandardDays() > 1 ? "s" : "");
    }
}

From source file:com.squarespace.template.plugins.PluginDateUtils.java

License:Apache License

public static void humanizeDate(long instantMs, long baseMs, String tzId, boolean showSeconds,
        StringBuilder buf) {//from w  ww .  j  av  a  2s. com
    DateTimeZone timeZone = DateTimeZone.forID(tzId);
    int offset = timeZone.getOffset(instantMs);
    Duration delta = new Duration(baseMs - instantMs + offset);

    int days = (int) delta.getStandardDays();
    int years = (int) Math.floor(days / 365.0);
    if (years > 0) {
        humanizeDatePlural(years, DatePartType.YEAR, buf);
        return;
    }
    int months = (int) Math.floor(days / 30.0);
    if (months > 0) {
        humanizeDatePlural(months, DatePartType.MONTH, buf);
        return;
    }
    int weeks = (int) Math.floor(days / 7.0);
    if (weeks > 0) {
        humanizeDatePlural(weeks, DatePartType.WEEK, buf);
        return;
    }
    if (days > 0) {
        humanizeDatePlural(days, DatePartType.DAY, buf);
        return;
    }
    int hours = (int) delta.getStandardHours();
    if (hours > 0) {
        humanizeDatePlural(hours, DatePartType.HOUR, buf);
        return;
    }
    int mins = (int) delta.getStandardMinutes();
    if (mins > 0) {
        humanizeDatePlural(mins, DatePartType.MINUTE, buf);
        return;
    }
    int secs = (int) delta.getStandardSeconds();
    if (showSeconds) {
        humanizeDatePlural(secs, DatePartType.SECOND, buf);
        return;
    }
    buf.append("less than a minute ago");
}

From source file:de.fatalix.bookery.App.java

License:Open Source License

public void userLoggedIn(@Observes(notifyObserver = Reception.IF_EXISTS) UserLoggedInEvent event) {
    AppUser user = userService.updateLastLogin(event.getUsername());

    if (user.getLastLogin() != null) {
        DateTime dtLastLogin = new DateTime(user.getLastLogin());
        DateTime dtCurrentLogin = new DateTime(user.getCurrentLogin());
        Duration duration = new Duration(dtLastLogin, dtCurrentLogin);
        String sinceLastLogin = "";
        if (duration.getStandardDays() > 0) {
            long days = duration.getStandardDays();
            if (days == 1) {
                sinceLastLogin = days + " day";
            } else {
                sinceLastLogin = days + " days";
            }/*from  www  . ja  v  a 2 s .  com*/
        } else if (duration.getStandardHours() > 0) {
            long hours = duration.getStandardHours();
            if (hours == 1) {
                sinceLastLogin = hours + " hour";
            } else {
                sinceLastLogin = hours + " hours";
            }
        } else if (duration.getStandardMinutes() > 0) {
            long minutes = duration.getStandardMinutes();
            if (minutes == 1) {
                sinceLastLogin = minutes + " minute";
            } else {
                sinceLastLogin = minutes + " minutes";
            }
        } else {
            long seconds = duration.getStandardSeconds();
            if (seconds == 1) {
                sinceLastLogin = seconds + " second";
            } else {
                sinceLastLogin = seconds + " seconds";
            }
        }
        Notification.show("Welcome back " + event.getUsername() + " after " + sinceLastLogin + ".");
    } else {
        Notification.show("Welcome " + event.getUsername());
    }

    logger.info("User " + event.getUsername() + " logged in.");
    getNavigator().navigateTo(HomeView.id);
    appLayout.getAppHeader().setLoginName(SecurityUtils.getSubject().getPrincipal().toString());
    appLayout.getAppHeader().setVisible(isLoggedIn());

}