当前位置: 首页>>代码示例>>Java>>正文


Java DurationFieldType类代码示例

本文整理汇总了Java中org.joda.time.DurationFieldType的典型用法代码示例。如果您正苦于以下问题:Java DurationFieldType类的具体用法?Java DurationFieldType怎么用?Java DurationFieldType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DurationFieldType类属于org.joda.time包,在下文中一共展示了DurationFieldType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: lengthBetween

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
 * 获得两个时间点之间的时间跨度
 * 
 * @param time1
 *            开始的时间点
 * @param time2
 *            结束的时间点
 * @param timeUnit
 *            跨度的时间单位 see {@link JodaTime}
 *            (支持的时间单位有DAY,HOUR,MINUTE,SECOND,MILLI)
 */
public static long lengthBetween(DateTime time1, DateTime time2,
		DurationFieldType timeUnit) {
	Duration duration = Days.daysBetween(time1, time2).toStandardDuration();
	if (timeUnit == JodaTime.DAY) {
		return duration.getStandardDays();
	} else if (timeUnit == JodaTime.HOUR) {
		return duration.getStandardHours();
	} else if (timeUnit == JodaTime.MINUTE) {
		return duration.getStandardMinutes();
	} else if (timeUnit == JodaTime.SECOND) {
		return duration.getStandardSeconds();
	} else if (timeUnit == JodaTime.MILLI) {
		return duration.getMillis();
	} else {
		throw new RuntimeException(
				"TimeUnit not supported except DAY,HOUR,MINUTE,SECOND,MILLI");
	}
}
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:30,代码来源:DateUtils.java

示例2: getDurationFieldType

import org.joda.time.DurationFieldType; //导入依赖的package包/类
private static DurationFieldType getDurationFieldType(OrgInterval.Unit unit) {
    switch (unit) {
        case HOUR:
            return DurationFieldType.hours();
        case DAY:
            return DurationFieldType.days();
        case WEEK:
            return DurationFieldType.weeks();
        case MONTH:
            return DurationFieldType.months();
        case YEAR:
            return DurationFieldType.years();
        default:
            throw new IllegalArgumentException("Unknown unit " + unit);
    }
}
 
开发者ID:orgzly,项目名称:org-java,代码行数:17,代码来源:OrgDateTimeUtils.java

示例3: addPeriodInto

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
 * Adds the fields from another period.
 * 
 * @param values  the array of values to update
 * @param period  the period to add from, not null
 * @return the updated values
 * @throws IllegalArgumentException if an unsupported field's value is non-zero
 */
protected int[] addPeriodInto(int[] values, ReadablePeriod period) {
    for (int i = 0, isize = period.size(); i < isize; i++) {
        DurationFieldType type = period.getFieldType(i);
        int value = period.getValue(i);
        if (value != 0) {
            int index = indexOf(type);
            if (index == -1) {
                throw new IllegalArgumentException(
                    "Period does not support field '" + type.getName() + "'");
            } else {
                values[index] = FieldUtils.safeAdd(getValue(index), value);
            }
        }
    }
    return values;
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:25,代码来源:BasePeriod.java

示例4: isSupported

import org.joda.time.DurationFieldType; //导入依赖的package包/类
boolean isSupported(PeriodType type, int field) {
    switch (field) {
    default:
        return false;
    case YEARS:
        return type.isSupported(DurationFieldType.years());
    case MONTHS:
        return type.isSupported(DurationFieldType.months());
    case WEEKS:
        return type.isSupported(DurationFieldType.weeks());
    case DAYS:
        return type.isSupported(DurationFieldType.days());
    case HOURS:
        return type.isSupported(DurationFieldType.hours());
    case MINUTES:
        return type.isSupported(DurationFieldType.minutes());
    case SECONDS:
        return type.isSupported(DurationFieldType.seconds());
    case MILLIS:
        return type.isSupported(DurationFieldType.millis());
    case SECONDS_MILLIS: // drop through
    case SECONDS_OPTIONAL_MILLIS:
        return type.isSupported(DurationFieldType.seconds()) ||
               type.isSupported(DurationFieldType.millis());
    }
}
 
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:27,代码来源:PeriodFormatterBuilder.java

示例5: add

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public FDate add(final FTimeUnit field, final int amount) {
    final MutableDateTime delegate = newMutableDateTime();
    final int usedAmount;
    final DurationFieldType usedField;
    switch (field) {
    case MILLENIA:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_MILLENIUM;
        break;
    case CENTURIES:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_CENTURY;
        break;
    case DECADES:
        usedField = FTimeUnit.YEARS.jodaTimeValue();
        usedAmount = amount * FTimeUnit.YEARS_IN_DECADE;
        break;
    default:
        usedField = field.jodaTimeValue();
        usedAmount = amount;
        break;
    }
    delegate.add(usedField, usedAmount);
    return new FDate(delegate);
}
 
开发者ID:subes,项目名称:invesdwin-util,代码行数:26,代码来源:FDate.java

示例6: testCutoverAddYears

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public void testCutoverAddYears() {
    testAdd("1582-01-01", DurationFieldType.years(), 1, "1583-01-01");
    testAdd("1582-02-15", DurationFieldType.years(), 1, "1583-02-15");
    testAdd("1582-02-28", DurationFieldType.years(), 1, "1583-02-28");
    testAdd("1582-03-01", DurationFieldType.years(), 1, "1583-03-01");
    testAdd("1582-09-30", DurationFieldType.years(), 1, "1583-09-30");
    testAdd("1582-10-01", DurationFieldType.years(), 1, "1583-10-01");
    testAdd("1582-10-04", DurationFieldType.years(), 1, "1583-10-04");
    testAdd("1582-10-15", DurationFieldType.years(), 1, "1583-10-15");
    testAdd("1582-10-16", DurationFieldType.years(), 1, "1583-10-16");
    testAdd("1580-01-01", DurationFieldType.years(), 4, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.years(), 4, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.years(), 4, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.years(), 4, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.years(), 4, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.years(), 4, "1584-12-31");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:18,代码来源:TestISOChronology.java

示例7: testAdd

import org.joda.time.DurationFieldType; //导入依赖的package包/类
private void testAdd(String start, DurationFieldType type, int amt, String end) {
    DateTime dtStart = new DateTime(start, GJChronology.getInstance(DateTimeZone.UTC));
    DateTime dtEnd = new DateTime(end, GJChronology.getInstance(DateTimeZone.UTC));
    assertEquals(dtEnd, dtStart.withFieldAdded(type, amt));
    assertEquals(dtStart, dtEnd.withFieldAdded(type, -amt));

    DurationField field = type.getField(GJChronology.getInstance(DateTimeZone.UTC));
    int diff = field.getDifference(dtEnd.getMillis(), dtStart.getMillis());
    assertEquals(amt, diff);
    
    if (type == DurationFieldType.years() ||
        type == DurationFieldType.months() ||
        type == DurationFieldType.days()) {
        YearMonthDay ymdStart = new YearMonthDay(start, GJChronology.getInstance(DateTimeZone.UTC));
        YearMonthDay ymdEnd = new YearMonthDay(end, GJChronology.getInstance(DateTimeZone.UTC));
        assertEquals(ymdEnd, ymdStart.withFieldAdded(type, amt));
        assertEquals(ymdStart, ymdEnd.withFieldAdded(type, -amt));
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:TestGJChronology.java

示例8: testCutoverAddMonths

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public void testCutoverAddMonths() {
    testAdd("1582-01-01", DurationFieldType.months(), 1, "1582-02-01");
    testAdd("1582-01-01", DurationFieldType.months(), 6, "1582-07-01");
    testAdd("1582-01-01", DurationFieldType.months(), 12, "1583-01-01");
    testAdd("1582-11-15", DurationFieldType.months(), 1, "1582-12-15");

    testAdd("1582-09-04", DurationFieldType.months(), 2, "1582-11-04");
    testAdd("1582-09-05", DurationFieldType.months(), 2, "1582-11-05");
    testAdd("1582-09-10", DurationFieldType.months(), 2, "1582-11-10");
    testAdd("1582-09-15", DurationFieldType.months(), 2, "1582-11-15");


    // Leap years...
    testAdd("1580-01-01", DurationFieldType.months(), 48, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.months(), 48, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.months(), 48, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.months(), 48, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.months(), 48, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.months(), 48, "1584-12-31");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:TestGJChronology.java

示例9: testCutoverAddYears

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public void testCutoverAddYears() {
    testAdd("1582-01-01", DurationFieldType.years(), 1, "1583-01-01");
    testAdd("1582-02-15", DurationFieldType.years(), 1, "1583-02-15");
    testAdd("1582-02-28", DurationFieldType.years(), 1, "1583-02-28");
    testAdd("1582-03-01", DurationFieldType.years(), 1, "1583-03-01");
    testAdd("1582-09-30", DurationFieldType.years(), 1, "1583-09-30");
    testAdd("1582-10-01", DurationFieldType.years(), 1, "1583-10-01");
    testAdd("1582-10-04", DurationFieldType.years(), 1, "1583-10-04");
    testAdd("1582-10-15", DurationFieldType.years(), 1, "1583-10-15");
    testAdd("1582-10-16", DurationFieldType.years(), 1, "1583-10-16");

    // Leap years...
    testAdd("1580-01-01", DurationFieldType.years(), 4, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.years(), 4, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.years(), 4, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.years(), 4, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.years(), 4, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.years(), 4, "1584-12-31");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:TestGJChronology.java

示例10: testAddMonths

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public void testAddMonths() {
    testAdd("1582-01-01", DurationFieldType.months(), 1, "1582-02-01");
    testAdd("1582-01-01", DurationFieldType.months(), 6, "1582-07-01");
    testAdd("1582-01-01", DurationFieldType.months(), 12, "1583-01-01");
    testAdd("1582-11-15", DurationFieldType.months(), 1, "1582-12-15");
    testAdd("1582-09-04", DurationFieldType.months(), 2, "1582-11-04");
    testAdd("1582-09-05", DurationFieldType.months(), 2, "1582-11-05");
    testAdd("1582-09-10", DurationFieldType.months(), 2, "1582-11-10");
    testAdd("1582-09-15", DurationFieldType.months(), 2, "1582-11-15");
    testAdd("1580-01-01", DurationFieldType.months(), 48, "1584-01-01");
    testAdd("1580-02-29", DurationFieldType.months(), 48, "1584-02-29");
    testAdd("1580-10-01", DurationFieldType.months(), 48, "1584-10-01");
    testAdd("1580-10-10", DurationFieldType.months(), 48, "1584-10-10");
    testAdd("1580-10-15", DurationFieldType.months(), 48, "1584-10-15");
    testAdd("1580-12-31", DurationFieldType.months(), 48, "1584-12-31");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:TestISOChronology.java

示例11: testCutoverAddWeekyears

import org.joda.time.DurationFieldType; //导入依赖的package包/类
public void testCutoverAddWeekyears() {
    testAdd("1582-W01-1", DurationFieldType.weekyears(), 1, "1583-W01-1");
    testAdd("1582-W39-1", DurationFieldType.weekyears(), 1, "1583-W39-1");
    testAdd("1583-W45-1", DurationFieldType.weekyears(), 1, "1584-W45-1");

    // This test fails, but I'm not sure if its worth fixing. The date
    // falls after the cutover, but in the cutover year. The add operation
    // is performed completely within the gregorian calendar, with no
    // crossing of the cutover. As a result, no special correction is
    // applied. Since the full gregorian year of 1582 has a different week
    // numbers than the full julian year of 1582, the week number is off by
    // one after the addition.
    //
    //testAdd("1582-W42-1", DurationFieldType.weekyears(), 1, "1583-W42-1");

    // Leap years...
    testAdd("1580-W01-1", DurationFieldType.weekyears(), 4, "1584-W01-1");
    testAdd("1580-W30-7", DurationFieldType.weekyears(), 4, "1584-W30-7");
    testAdd("1580-W50-7", DurationFieldType.weekyears(), 4, "1584-W50-7");
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:21,代码来源:TestGJChronology.java

示例12: getListOfDates

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
    * Get the list of dates among the starting and ending date.
    * 
    * @param LocalDate the starting date
    * @param LocalDate the ending date
    * @return List<String> the list of dates between the starting and ending date
    */
public List<String> getListOfDates(LocalDate startDate, LocalDate endDate) {
	
	List<String> datesList = new ArrayList<String>();
	
	int days = Days.daysBetween(startDate, endDate).getDays();
	
	for (int i = 0; i < days; i++) {
	    LocalDate dt = startDate.withFieldAdded(DurationFieldType.days(), i);
	    datesList.add(dt.toString());
	}
	
	return datesList;
}
 
开发者ID:YourDataStories,项目名称:harvesters,代码行数:21,代码来源:HelperMethods.java

示例13: initializeDuration

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
 * Creates a Joda duration/period object
 *
 * @param date object that represents the duration of the period through milisseconds
 */
private void initializeDuration(Date date) {
    // Get duration from Date
    mDuration = new Duration(date.getTime());

    // Get period
    final DurationFieldType[] durationFields = new DurationFieldType[]{DurationFieldType.weeks(), DurationFieldType.days(), DurationFieldType.hours(), DurationFieldType.minutes()};
    mPeriod = mDuration.toPeriod(PeriodType.forFields(durationFields)).normalizedStandard();
    updatePeriod();
}
 
开发者ID:Kamshak,项目名称:BrainPhaser,代码行数:15,代码来源:SettingsViewHolder.java

示例14: onSelectionChanged

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
 * This method is called when the selection in the view holder has changed
 *
 * @param slider The calling slider
 * @param value the new value
 */
@Override
public void onSelectionChanged(TimePeriodSlider slider, int value) {
    DurationFieldType fieldType = mConversion.get(slider.getDateType());
    mPeriod = mPeriod.withField(fieldType, value);
    updatePeriod();
}
 
开发者ID:Kamshak,项目名称:BrainPhaser,代码行数:13,代码来源:SettingsViewHolder.java

示例15: FixedYearLengthChronology

import org.joda.time.DurationFieldType; //导入依赖的package包/类
/**
 * @param daysInYear The number of days in each year
 */
protected FixedYearLengthChronology(int daysInYear) {
    this.daysInYear = daysInYear;

    this.yearDuration = new PreciseDurationField(DurationFieldType.years(),
            daysInYear * dayDuration.getUnitMillis());
    this.centuryDuration = new PreciseDurationField(DurationFieldType.centuries(),
            100 * yearDuration.getUnitMillis());

    this.dayOfYear = new OneBasedPreciseDateTimeField(DateTimeFieldType.dayOfYear(),
            dayDuration, this.yearDuration);
    this.yearOfCentury =  new PreciseDateTimeField(DateTimeFieldType.yearOfCentury(),
            this.yearDuration, this.centuryDuration);
    this.year = new YearField(this.yearDuration);
}
 
开发者ID:NOAA-PMEL,项目名称:LAS,代码行数:18,代码来源:FixedYearLengthChronology.java


注:本文中的org.joda.time.DurationFieldType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。