Example usage for org.joda.time Weeks Weeks

List of usage examples for org.joda.time Weeks Weeks

Introduction

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

Prototype

private Weeks(int weeks) 

Source Link

Document

Creates a new instance representing a number of weeks.

Usage

From source file:griffon.plugins.jodatime.editors.WeeksPropertyEditor.java

License:Apache License

private Weeks parse(Number number) {
    return Weeks.weeks(abs(number.intValue()));
}

From source file:griffon.plugins.jodatime.JodatimeExtension.java

License:Apache License

public static Weeks toWeeks(Number number) {
    return Weeks.weeks(abs(number.intValue()));
}

From source file:griffon.plugins.scaffolding.atoms.WeeksValue.java

License:Apache License

@Override
public void setValue(Object value) {
    if (value == null || value instanceof Weeks) {
        super.setValue(value);
    } else if (value instanceof Number) {
        super.setValue(Weeks.weeks(abs(((Number) value).intValue())));
    } else {//from  www.j  a v  a  2  s.  c om
        throw new IllegalArgumentException("Invalid value " + value);
    }
}

From source file:influent.server.utilities.ResultFormatter.java

License:MIT License

public static String formatDur(FL_Duration d) {
    if (d == null)
        return "";

    int t = d.getNumIntervals().intValue();
    if (t == 0)//from  w w w  .  ja v  a2 s.  c o m
        return "-";

    ReadablePeriod period = null;
    switch (d.getInterval()) {
    case SECONDS:
        period = Seconds.seconds(t);
        break;
    case HOURS:
        period = Hours.hours(t);
        break;
    case DAYS:
        period = Days.days(t);
        break;
    case WEEKS:
        period = Weeks.weeks(t);
        break;
    case MONTHS:
        period = Months.months(t);
        break;
    case QUARTERS:
        period = Months.months(t * 3);
        break;
    case YEARS:
        period = Years.years(t);
        break;
    }

    PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroAlways().minimumPrintedDigits(2)
            .appendHours().appendSeparator(":").printZeroAlways().minimumPrintedDigits(2).appendMinutes()
            .appendSeparator(":").printZeroAlways().minimumPrintedDigits(2).appendSeconds().toFormatter();
    final String ftime = formatter.print(DateTimeParser.normalize(new Period(period)));

    return ftime;
}

From source file:org.cowboyprogrammer.org.OrgTimestamp.java

License:Open Source License

protected ReadablePeriod parsePeriod(final int t, final String w) {
    final ReadablePeriod p;

    if (w.equals("h")) {
        p = Hours.hours(t);/*from www  .j ava2  s  .c om*/
    } else if (w.equals("d")) {
        p = Days.days(t);
    } else if (w.equals("w")) {
        p = Weeks.weeks(t);
    } else if (w.equals("m")) {
        p = Months.months(t);
    } else {
        p = Years.years(t);
    }

    return p;
}

From source file:org.gnucash.android.model.Recurrence.java

License:Apache License

/**
 * Computes the number of occurrences of this recurrences between start and end date
 * <p>If there is no end date, it returns -1</p>
 * @return Number of occurrences, or -1 if there is no end date
 *///ww w  .  j ava2s  .  c  om
public int getCount() {
    if (mPeriodEnd == null)
        return -1;

    int multiple = mPeriodType.getMultiplier();
    ReadablePeriod jodaPeriod;
    switch (mPeriodType) {
    case DAY:
        jodaPeriod = Days.days(multiple);
        break;
    case WEEK:
        jodaPeriod = Weeks.weeks(multiple);
        break;
    case MONTH:
        jodaPeriod = Months.months(multiple);
        break;
    case YEAR:
        jodaPeriod = Years.years(multiple);
        break;
    default:
        jodaPeriod = Months.months(multiple);
    }
    int count = 0;
    LocalDateTime startTime = new LocalDateTime(mPeriodStart.getTime());
    while (startTime.toDateTime().getMillis() < mPeriodEnd.getTime()) {
        ++count;
        startTime = startTime.plus(jodaPeriod);
    }
    return count;

    /*
            //this solution does not use looping, but is not very accurate
            
            int multiplier = mPeriodType.getMultiplier();
            LocalDateTime startDate = new LocalDateTime(mPeriodStart.getTime());
            LocalDateTime endDate = new LocalDateTime(mPeriodEnd.getTime());
            switch (mPeriodType){
    case DAY:
        return Days.daysBetween(startDate, endDate).dividedBy(multiplier).getDays();
    case WEEK:
        return Weeks.weeksBetween(startDate, endDate).dividedBy(multiplier).getWeeks();
    case MONTH:
        return Months.monthsBetween(startDate, endDate).dividedBy(multiplier).getMonths();
    case YEAR:
        return Years.yearsBetween(startDate, endDate).dividedBy(multiplier).getYears();
    default:
        return -1;
            }
    */
}

From source file:org.obm.imap.archive.beans.RepeatKind.java

License:Open Source License

public static ReadablePeriod toPeriod(RepeatKind repeatKind, int period) {
    switch (repeatKind) {
    case DAILY:/* w w  w .j  a v a 2s.  c o  m*/
        return Days.days(period);
    case WEEKLY:
        return Weeks.weeks(period);
    case MONTHLY:
        return Months.months(period);
    case YEARLY:
        return Years.years(period);
    default:
        throw new IllegalArgumentException("Unknown repeat kind: " + repeatKind);
    }
}