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


Java PeriodType类代码示例

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


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

示例1: formatDuration

import org.joda.time.PeriodType; //导入依赖的package包/类
public static String formatDuration(long duration)
{
	// Using Joda Time
	DateTime now = new DateTime(); // Now
	DateTime plus = now.plus(new Duration(duration * 1000));

	// Define and calculate the interval of time
	Interval interval = new Interval(now.getMillis(), plus.getMillis());
	Period period = interval.toPeriod(PeriodType.time());

	// Define the period formatter for pretty printing
	String ampersand = " & ";
	PeriodFormatter pf = new PeriodFormatterBuilder().appendHours().appendSuffix(ds("hour"), ds("hours"))
		.appendSeparator(" ", ampersand).appendMinutes().appendSuffix(ds("minute"), ds("minutes"))
		.appendSeparator(ampersand).appendSeconds().appendSuffix(ds("second"), ds("seconds")).toFormatter();

	return pf.print(period).trim();
}
 
开发者ID:equella,项目名称:Equella,代码行数:19,代码来源:EchoUtils.java

示例2: getPeriodType

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

示例3: isSupported

import org.joda.time.PeriodType; //导入依赖的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

示例4: testToPeriodWithLowClosedHighOpenDate

import org.joda.time.PeriodType; //导入依赖的package包/类
@Test
public void testToPeriodWithLowClosedHighOpenDate() {
    PointInTime start = new PointInTime(2000, 1, 2);
    PointInTime stop = new PointInTime(2001, 1, 1);
    Period expected = new Period(start.promote().getLow(), stop.promote().getHigh().subtractMilliseconds(1));
    Period actual = new IntervalOfTime(start, stop).toPeriod();
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
    expected = new Period(start.promote().getLow(), stop.promote().getHigh().subtractMilliseconds(1), PeriodType.yearMonthDay());
    actual = new IntervalOfTime(start, stop).toPeriod(PeriodType.yearMonthDay());
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:24,代码来源:IntervalOfTimeTest.java

示例5: testToPeriodWithLowOpenHighClosedDate

import org.joda.time.PeriodType; //导入依赖的package包/类
@Test
public void testToPeriodWithLowOpenHighClosedDate() {
    PointInTime start = new PointInTime(2000, 1, 2);
    PointInTime stop = new PointInTime(2001, 1, 1);
    IntervalOfTime iot = stop.promote();
    PointInTime iota = iot.getHigh();
    Period expected = new Period(start.promote().getLow().addMilliseconds(1), iota.subtractMilliseconds(1));
    Period actual = new IntervalOfTime(start, stop, false, true, false).toPeriod();
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
    expected = new Period(start.promote().getLow().addMilliseconds(1), iota.subtractMilliseconds(1), PeriodType.yearMonthDay());
    actual = new IntervalOfTime(start, stop, false, true, false).toPeriod(PeriodType.yearMonthDay());
    assertThat(expected.getYears(), is(actual.getYears()));
    assertThat(expected.getMonths(), is(actual.getMonths()));
    assertThat(expected.getDays(), is(actual.getDays()));
    assertThat(expected.getHours(), is(actual.getHours()));
    assertThat(expected.getMinutes(), is(actual.getMinutes()));
    assertThat(expected.getSeconds(), is(actual.getSeconds()));
    assertThat(expected.getMillis(), is(actual.getMillis()));
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:26,代码来源:IntervalOfTimeTest.java

示例6: toString

import org.joda.time.PeriodType; //导入依赖的package包/类
@Override
public String toString() {
	StringBuffer sb = new StringBuffer();
	String lf = "+%s => %s\n";
	Iterator<Entry<Long, DATA>> entryItr = this.timeSeries.entrySet().iterator();
	long last = 0;
	for (int i = 0; i < this.size(); i++) {
		Entry<Long, DATA> entry = entryItr.next();
		long time = entry.getKey();
		DATA data = entry.getValue();
		Interval inter = new Interval(last,time);
		Period p = inter.toPeriod(PeriodType.yearDayTime());
		sb.append(String.format(lf, p,data));
		last =time;
	}
	return sb.toString();
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:18,代码来源:ConcreteTimeSeries.java

示例7: testFormatStandard

import org.joda.time.PeriodType; //导入依赖的package包/类
public void testFormatStandard() {
    Period p = new Period(1, 2, 3, 4, 5, 6, 7, 8);
    assertEquals("P1Y2M3W4DT5H6M7.008S", ISOPeriodFormat.standard().print(p));
    p = new Period(1, 2, 3, 4, 5, 6 ,7, 0);
    assertEquals("P1Y2M3W4DT5H6M7S", ISOPeriodFormat.standard().print(p));
    
    p = new Period(0);
    assertEquals("PT0S", ISOPeriodFormat.standard().print(p));
    p = new Period(0, PeriodType.standard().withMillisRemoved().withSecondsRemoved());
    assertEquals("PT0M", ISOPeriodFormat.standard().print(p));
    
    assertEquals("P1Y4DT5H6M7.008S", ISOPeriodFormat.standard().print(YEAR_DAY_PERIOD));
    assertEquals("PT0S", ISOPeriodFormat.standard().print(EMPTY_YEAR_DAY_PERIOD));
    assertEquals("P1Y2M3W4D", ISOPeriodFormat.standard().print(DATE_PERIOD));
    assertEquals("PT5H6M7.008S", ISOPeriodFormat.standard().print(TIME_PERIOD));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:TestISOPeriodFormat.java

示例8: testFormatAlternateExtended

import org.joda.time.PeriodType; //导入依赖的package包/类
public void testFormatAlternateExtended() {
    Period p = new Period(1, 2, 3, 4, 5, 6 ,7, 8);
    assertEquals("P0001-02-04T05:06:07.008", ISOPeriodFormat.alternateExtended().print(p));
    p = new Period(1, 2, 3, 4, 5, 6 ,7, 0);
    assertEquals("P0001-02-04T05:06:07", ISOPeriodFormat.alternateExtended().print(p));
    
    p = new Period(0);
    assertEquals("P0000-00-00T00:00:00", ISOPeriodFormat.alternateExtended().print(p));
    p = new Period(0, PeriodType.standard().withMillisRemoved().withSecondsRemoved());
    assertEquals("P0000-00-00T00:00:00", ISOPeriodFormat.alternateExtended().print(p));
    
    assertEquals("P0001-00-04T05:06:07.008", ISOPeriodFormat.alternateExtended().print(YEAR_DAY_PERIOD));
    assertEquals("P0000-00-00T00:00:00", ISOPeriodFormat.alternateExtended().print(EMPTY_YEAR_DAY_PERIOD));
    assertEquals("P0001-02-04T00:00:00", ISOPeriodFormat.alternateExtended().print(DATE_PERIOD));
    assertEquals("P0000-00-00T05:06:07.008", ISOPeriodFormat.alternateExtended().print(TIME_PERIOD));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:TestISOPeriodFormat.java

示例9: testFormatAlternateWithWeeks

import org.joda.time.PeriodType; //导入依赖的package包/类
public void testFormatAlternateWithWeeks() {
    Period p = new Period(1, 2, 3, 4, 5, 6 ,7, 8);
    assertEquals("P0001W0304T050607.008", ISOPeriodFormat.alternateWithWeeks().print(p));
    p = new Period(1, 2, 3, 4, 5, 6 ,7, 0);
    assertEquals("P0001W0304T050607", ISOPeriodFormat.alternateWithWeeks().print(p));
    
    p = new Period(0);
    assertEquals("P0000W0000T000000", ISOPeriodFormat.alternateWithWeeks().print(p));
    p = new Period(0, PeriodType.standard().withMillisRemoved().withSecondsRemoved());
    assertEquals("P0000W0000T000000", ISOPeriodFormat.alternateWithWeeks().print(p));
    
    assertEquals("P0001W0004T050607.008", ISOPeriodFormat.alternateWithWeeks().print(YEAR_DAY_PERIOD));
    assertEquals("P0000W0000T000000", ISOPeriodFormat.alternateWithWeeks().print(EMPTY_YEAR_DAY_PERIOD));
    assertEquals("P0001W0304T000000", ISOPeriodFormat.alternateWithWeeks().print(DATE_PERIOD));
    assertEquals("P0000W0000T050607.008", ISOPeriodFormat.alternateWithWeeks().print(TIME_PERIOD));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:TestISOPeriodFormat.java

示例10: toAge

import org.joda.time.PeriodType; //导入依赖的package包/类
public static String toAge(Date from, Date to) {
  if (from == null || to == null) return "N/A";
  final Period period = new Period(from.getTime(), to.getTime());
  DurationFieldType[] dtf = new ArrayList<DurationFieldType>() {{
    add(DurationFieldType.years()); add(DurationFieldType.months());
    add(DurationFieldType.days());
    if (period.getYears() == 0 && period.getMonths() == 0 && period.getDays() == 0) {
      add(DurationFieldType.hours());
      add(DurationFieldType.minutes());
    }

  }}.toArray(new DurationFieldType[0]);

  PeriodFormatter pf = PeriodFormat.getDefault();
  return pf.print(period.normalizedStandard(PeriodType.forFields(dtf)));
}
 
开发者ID:h2oai,项目名称:h2o-3,代码行数:17,代码来源:PrettyPrint.java

示例11: testFormatAlternateExtendedWithWeeks

import org.joda.time.PeriodType; //导入依赖的package包/类
public void testFormatAlternateExtendedWithWeeks() {
    Period p = new Period(1, 2, 3, 4, 5, 6 ,7, 8);
    assertEquals("P0001-W03-04T05:06:07.008", ISOPeriodFormat.alternateExtendedWithWeeks().print(p));
    p = new Period(1, 2, 3, 4, 5, 6 ,7, 0);
    assertEquals("P0001-W03-04T05:06:07", ISOPeriodFormat.alternateExtendedWithWeeks().print(p));
    
    p = new Period(0);
    assertEquals("P0000-W00-00T00:00:00", ISOPeriodFormat.alternateExtendedWithWeeks().print(p));
    p = new Period(0, PeriodType.standard().withMillisRemoved().withSecondsRemoved());
    assertEquals("P0000-W00-00T00:00:00", ISOPeriodFormat.alternateExtendedWithWeeks().print(p));
    
    assertEquals("P0001-W00-04T05:06:07.008", ISOPeriodFormat.alternateExtendedWithWeeks().print(YEAR_DAY_PERIOD));
    assertEquals("P0000-W00-00T00:00:00", ISOPeriodFormat.alternateExtendedWithWeeks().print(EMPTY_YEAR_DAY_PERIOD));
    assertEquals("P0001-W03-04T00:00:00", ISOPeriodFormat.alternateExtendedWithWeeks().print(DATE_PERIOD));
    assertEquals("P0000-W00-00T05:06:07.008", ISOPeriodFormat.alternateExtendedWithWeeks().print(TIME_PERIOD));
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:17,代码来源:TestISOPeriodFormat.java

示例12: getDiffFormatted

import org.joda.time.PeriodType; //导入依赖的package包/类
public static String getDiffFormatted(Date from, Date to) {
    Duration duration = new Duration(to.getTime() - from.getTime()); // in
                                                                     // milliseconds
    PeriodFormatter formatter = new PeriodFormatterBuilder().printZeroNever()//
            .appendWeeks().appendSuffix("w").appendSeparator(" ")//
            .appendDays().appendSuffix("d").appendSeparator(" ")//
            .appendHours().appendSuffix("h").appendSeparator(" ")//
            .appendMinutes().appendSuffix("m").appendSeparator(" ")//
            .appendSeconds().appendSuffix("s")//
            .toFormatter();
    String fullTimeAgo = formatter.print(duration.toPeriod(PeriodType.yearMonthDayTime()));
    return Arrays.stream(fullTimeAgo.split(" ")).limit(2).collect(Collectors.joining(" "));
}
 
开发者ID:BlackCraze,项目名称:GameResourceBot,代码行数:14,代码来源:PrintUtils.java

示例13: getOccurrences

import org.joda.time.PeriodType; //导入依赖的package包/类
/**
 * Gets all occurrences of an event time
 *
 * @param fromTime the from time
 * @return list of occurrences
 */
@JsonIgnore
public List<ParsedEventData> getOccurrences(final long fromTime) {
    List<ParsedEventData> parsedResults = new ArrayList<>();

    if (getStartTime() == null) {
        return parsedResults;
    }

    final long startTime = getStartTime().getMillis();

    if (startTime >= fromTime) {
        parsedResults.add(generateParsedEventData(startTime, getDuration(), event.getId()));
    }

    if ((getRepeatTime() != null) && (getRepeatTime().normalizedStandard(PeriodType.hours()).getHours() >= 24)) {
        final long finalTime = DateTime.now().plusWeeks(6).getMillis();
        final long lastTime = (getRepeatEnd() != null) ? getRepeatEnd().getMillis() : finalTime;
        final long newLastTime = lastTime <= finalTime ? lastTime : finalTime;
        final long timeDifference = newLastTime - startTime;

        if (timeDifference > 0) {
            final long repeatTime = getRepeatTime().normalizedStandard(PeriodType.millis()).getMillis();
            final int repeatOccurrences = (int) Math.floor((double) timeDifference / (double) repeatTime);

            for (int i = 1; i <= Math.min(repeatOccurrences, 10); i++) {
                final long occurrenceTime = startTime + (repeatTime * i);
                if (occurrenceTime >= fromTime) {
                    parsedResults.add(generateParsedEventData(
                            occurrenceTime,
                            getDuration(),
                            event.getId()));
                }
            }
        }
    }

    return parsedResults;
}
 
开发者ID:mhaddon,项目名称:Sound.je,代码行数:45,代码来源:EventTime.java

示例14: timeQuantityBetween

import org.joda.time.PeriodType; //导入依赖的package包/类
/**
 * Format the duration between since and until to a human readable string
 *
 * @param since Start DateTime
 * @param until End DateTime
 * @return A formatted string describing the time between since and until
 */
public String timeQuantityBetween(DateTime since, DateTime until) {
  long diff = new Duration(since, until).getMillis();
  if (diff <= 1000) {
    return "0 " + i18n.getString("TimeUnit.seconds");
  }

  if (diff < MILLIS_IN_MONTH) {
    return timeStringSmallScale(new Period(since, until, PeriodType.dayTime()));
  } else {
    return timeStringLargeScale(new Period(since, until, PeriodType.yearMonthDay()));
  }
}
 
开发者ID:Juraji,项目名称:Biliomi,代码行数:20,代码来源:TimeFormatter.java

示例15: initializeDuration

import org.joda.time.PeriodType; //导入依赖的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


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