org.joda.time.DurationField#add ( )源码实例Demo

下面列出了org.joda.time.DurationField#add ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: astor   文件: BaseChronology.java
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param duration  the duration to query
 * @return the values of the period extracted from the duration
 */
public int[] get(ReadablePeriod period, long duration) {
    int size = period.size();
    int[] values = new int[size];
    if (duration != 0) {
        long current = 0;
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            if (field.isPrecise()) {
                int value = field.getDifference(duration, current);
                current = field.add(current, value);
                values[i] = value;
            }
        }
    }
    return values;
}
 
源代码2 项目: astor   文件: BaseChronology.java
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param duration  the duration to query
 * @return the values of the period extracted from the duration
 */
public int[] get(ReadablePeriod period, long duration) {
    int size = period.size();
    int[] values = new int[size];
    if (duration != 0) {
        long current = 0;
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            if (field.isPrecise()) {
                int value = field.getDifference(duration, current);
                current = field.add(current, value);
                values[i] = value;
            }
        }
    }
    return values;
}
 
源代码3 项目: astor   文件: BaseChronology.java
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param startInstant  the start instant of an interval to query
 * @param endInstant  the start instant of an interval to query
 * @return the values of the period extracted from the interval
 */
public int[] get(ReadablePeriod period, long startInstant, long endInstant) {
    int size = period.size();
    int[] values = new int[size];
    if (startInstant != endInstant) {
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            int value = field.getDifference(endInstant, startInstant);
            startInstant = field.add(startInstant, value);
            values[i] = value;
        }
    }
    return values;
}
 
源代码4 项目: astor   文件: BaseChronology.java
/**
 * Gets the values of a period from an interval.
 *
 * @param period  the period instant to use
 * @param startInstant  the start instant of an interval to query
 * @param endInstant  the start instant of an interval to query
 * @return the values of the period extracted from the interval
 */
public int[] get(ReadablePeriod period, long startInstant, long endInstant) {
    int size = period.size();
    int[] values = new int[size];
    if (startInstant != endInstant) {
        for (int i = 0; i < size; i++) {
            DurationField field = period.getFieldType(i).getField(this);
            int value = field.getDifference(endInstant, startInstant);
            startInstant = field.add(startInstant, value);
            values[i] = value;
        }
    }
    return values;
}
 
源代码5 项目: astor   文件: AgeCalculator.java
public long updateResult(long minuend, long subtrahend) {
    // Because time zone can be dynamically changed, field must be
    // dynamically acquired.

    DurationField field;
    switch (iFieldType) {
    case YEARS:
        field = iChronology.years();
        break;
    case MONTHS:
        field = iChronology.months();
        break;
    case DAYS:
        field = iChronology.days();
        break;
    case WEEKYEARS:
        field = iChronology.weekyears();
        break;
    case WEEKS:
        field = iChronology.weeks();
        break;
    case HOURS:
        field = iChronology.hours();
        break;
    case MINUTES:
        field = iChronology.minutes();
        break;
    case SECONDS: default:
        field = iChronology.seconds();
        break;
    }

    String textToSet = "";

    if (iCheckbox.isSelected()) {
        long difference = field.getDifferenceAsLong(minuend, subtrahend);
        textToSet = Long.toString(difference);
        subtrahend = field.add(subtrahend, difference);
    }

    if (!iResult.getText().equals(textToSet)) {
        iResult.setText(textToSet);
    }

    return subtrahend;
}
 
源代码6 项目: astor   文件: AgeCalculator.java
public long updateResult(long minuend, long subtrahend) {
    // Because time zone can be dynamically changed, field must be
    // dynamically acquired.

    DurationField field;
    switch (iFieldType) {
    case YEARS:
        field = iChronology.years();
        break;
    case MONTHS:
        field = iChronology.months();
        break;
    case DAYS:
        field = iChronology.days();
        break;
    case WEEKYEARS:
        field = iChronology.weekyears();
        break;
    case WEEKS:
        field = iChronology.weeks();
        break;
    case HOURS:
        field = iChronology.hours();
        break;
    case MINUTES:
        field = iChronology.minutes();
        break;
    case SECONDS: default:
        field = iChronology.seconds();
        break;
    }

    String textToSet = "";

    if (iCheckbox.isSelected()) {
        long difference = field.getDifferenceAsLong(minuend, subtrahend);
        textToSet = Long.toString(difference);
        subtrahend = field.add(subtrahend, difference);
    }

    if (!iResult.getText().equals(textToSet)) {
        iResult.setText(textToSet);
    }

    return subtrahend;
}