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


Java ReadableDuration类代码示例

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


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

示例1: formatDuration

import org.joda.time.ReadableDuration; //导入依赖的package包/类
/**
 * Return given duration in a human-friendly format. For example, "4
 * minutes" or "1 second". Returns only largest meaningful unit of time,
 * from seconds up to hours.
 *
 * The longest duration it supports is hours.
 *
 * This method assumes that there are 60 minutes in an hour,
 * 60 seconds in a minute and 1000 milliseconds in a second.
 * All currently supplied chronologies use this definition.
 */
public static CharSequence formatDuration(Context context, ReadableDuration readableDuration) {
    Resources res = context.getResources();
    Duration duration = readableDuration.toDuration();

    final int hours = (int) duration.getStandardHours();
    if (hours != 0) {
        return res.getQuantityString(R.plurals.joda_time_android_duration_hours, hours, hours);
    }

    final int minutes = (int) duration.getStandardMinutes();
    if (minutes != 0) {
        return res.getQuantityString(R.plurals.joda_time_android_duration_minutes, minutes, minutes);
    }

    final int seconds = (int) duration.getStandardSeconds();
    return res.getQuantityString(R.plurals.joda_time_android_duration_seconds, seconds, seconds);
}
 
开发者ID:BenAlderfer,项目名称:RIT-Dining-Planner-Android,代码行数:29,代码来源:DateUtils.java

示例2: onCreate

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mRecipe = getArguments().getParcelable(ARG_RECIPE);
    mStep = getArguments().getParcelable(ARG_STEP);
    if (mRecipe == null) {
        throw new IllegalStateException("No recipe argument");
    }
    if (mStep == null) {
        throw new IllegalStateException("No step argument");
    }
    if (savedInstanceState != null) {
        // Restore remaining time
        mRemainingTime = (ReadableDuration) savedInstanceState.getSerializable(KEY_TIME_REMAINING);
    } else {
        // Get duration from step
        mRemainingTime = mStep.getTime();
    }

    // Check parent
    if (!(getActivity() instanceof StepFinishListener)) {
        throw new IllegalStateException("The parent of this fragment must implement StepFinishListener");
    }
}
 
开发者ID:Cook-E-team,项目名称:Cook-E,代码行数:26,代码来源:TimerFragment.java

示例3: testTerminationConditionsAfterTimeSinceNewOutput

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Test
public void testTerminationConditionsAfterTimeSinceNewOutput() {
  Instant now = Instant.now();
  Watch.Growth.AfterTimeSinceNewOutput<Object> c = afterTimeSinceNewOutput(standardSeconds(5));
  KV<Instant, ReadableDuration> state = c.forNewInput(now, null);
  assertFalse(c.canStopPolling(now, state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(6)), state));

  state = c.onSeenNewOutput(now.plus(standardSeconds(3)), state);
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(6)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(9)), state));

  state = c.onSeenNewOutput(now.plus(standardSeconds(5)), state);
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(6)), state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(9)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(11)), state));
}
 
开发者ID:apache,项目名称:beam,代码行数:21,代码来源:WatchTest.java

示例4: testGetDurationConverter

import org.joda.time.ReadableDuration; //导入依赖的package包/类
public void testGetDurationConverter() {
    DurationConverter c = ConverterManager.getInstance().getDurationConverter(new Long(0L));
    assertEquals(Long.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getDurationConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getDurationConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:TestConverterManager.java

示例5: testGetPeriodConverter

import org.joda.time.ReadableDuration; //导入依赖的package包/类
public void testGetPeriodConverter() {
    PeriodConverter c = ConverterManager.getInstance().getPeriodConverter(new Period(1, 2, 3, 4, 5, 6, 7, 8));
    assertEquals(ReadablePeriod.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Duration(123L));
    assertEquals(ReadableDuration.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(new Interval(0L, 1000L));
    assertEquals(ReadableInterval.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter("");
    assertEquals(String.class, c.getSupportedType());
    
    c = ConverterManager.getInstance().getPeriodConverter(null);
    assertEquals(null, c.getSupportedType());
    
    try {
        ConverterManager.getInstance().getPeriodConverter(Boolean.TRUE);
        fail();
    } catch (IllegalArgumentException ex) {}
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:TestConverterManager.java

示例6: createLoginTokenForActiveUser

import org.joda.time.ReadableDuration; //导入依赖的package包/类
public String createLoginTokenForActiveUser(final ReadableDuration timeToLive) {
    final UserInfo activeUserInfo = getActiveUserInfo();
    final DateTime now = DateUtil.now();

    return Jwts.builder()
            .setSubject(activeUserInfo.getUsername())
            .setIssuedAt(now.toDate())
            .setExpiration(now.plus(timeToLive).toDate())
            .setAudience(JwtAuthenticationProvider.AUD_LOGIN)
            .signWith(JwtAuthenticationProvider.JWT_SIGNATURE_ALG, securityConfigurationProperties.getJwtSecret())
            .compact();
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:13,代码来源:ActiveUserService.java

示例7: updateTimer

import org.joda.time.ReadableDuration; //导入依赖的package包/类
private void updateTimer(ReadableDuration remainingTime) {
    // Round the duration down to remove milliseconds
    final Duration roundedTime = roundDownToSecond(remainingTime);
    final Period remainingPeriod = roundedTime.toPeriod();
    mTimerView.setText(mFormatter.print(remainingPeriod));
    mRemainingTime = remainingTime;
}
 
开发者ID:Cook-E-team,项目名称:Cook-E,代码行数:8,代码来源:TimerFragment.java

示例8: Step

import org.joda.time.ReadableDuration; //导入依赖的package包/类
/**
 * Creates a Step
 * @param ingredients the ingredients required for this step
 * @param description a human-readable description of this step
 * @param duration an estimate of the time required to complete this step
 * @param isSimultaneous if this step can be done simultaneously
 * @throws NullPointerException if any parameter is null
 */
public Step(@NonNull List<String> ingredients, @NonNull String description,
            @NonNull ReadableDuration duration, boolean isSimultaneous, int index) {
    Objects.requireNonNull(ingredients, "ingredients must not be null");
    Objects.requireNonNull(description, "description must not be null");
    Objects.requireNonNull(duration, "duration must not be null");
    mDescription = description;
    mTime = duration.toDuration();
    mIngredients = new ArrayList<>(ingredients);
    this.mSimultaneous = isSimultaneous;
    mIndex = index;
}
 
开发者ID:Cook-E-team,项目名称:Cook-E,代码行数:20,代码来源:Step.java

示例9: decode

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Override
public IntervalWindow decode(InputStream inStream)
    throws IOException, CoderException {
  Instant end = instantCoder.decode(inStream);
  ReadableDuration duration = durationCoder.decode(inStream);
  return new IntervalWindow(end.minus(duration), end);
}
 
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:IntervalWindow.java

示例10: toString

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Override
public String toString(KV<Instant, ReadableDuration> state) {
  return "AfterTotalOf{"
      + "timeStarted="
      + state.getKey()
      + ", maxTimeSinceInput="
      + state.getValue()
      + '}';
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:Watch.java

示例11: canStopPolling

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Override
public boolean canStopPolling(Instant now, KV<Instant, ReadableDuration> state) {
  Instant timeOfLastNewOutput = state.getKey();
  ReadableDuration maxTimeSinceNewOutput = state.getValue();
  return timeOfLastNewOutput != null
      && new Duration(timeOfLastNewOutput, now).isLongerThan(maxTimeSinceNewOutput);
}
 
开发者ID:apache,项目名称:beam,代码行数:8,代码来源:Watch.java

示例12: encode

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Override
public void encode(ReadableDuration value, OutputStream outStream)
    throws CoderException, IOException {
  if (value == null) {
    throw new CoderException("cannot encode a null ReadableDuration");
  }
  LONG_CODER.encode(toLong(value), outStream);
}
 
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:DurationCoder.java

示例13: testTerminationConditionsAfterTotalOf

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Test
public void testTerminationConditionsAfterTotalOf() {
  Instant now = Instant.now();
  Watch.Growth.AfterTotalOf<Object> c = afterTotalOf(standardSeconds(5));
  KV<Instant, ReadableDuration> state = c.forNewInput(now, null);
  assertFalse(c.canStopPolling(now, state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(6)), state));
}
 
开发者ID:apache,项目名称:beam,代码行数:10,代码来源:WatchTest.java

示例14: testTerminationConditionsEitherOf

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Test
public void testTerminationConditionsEitherOf() {
  Instant now = Instant.now();
  Watch.Growth.AfterTotalOf<Object> a = afterTotalOf(standardSeconds(5));
  Watch.Growth.AfterTotalOf<Object> b = afterTotalOf(standardSeconds(10));

  Watch.Growth.BinaryCombined<
          Object, KV<Instant, ReadableDuration>, KV<Instant, ReadableDuration>>
      c = eitherOf(a, b);
  KV<KV<Instant, ReadableDuration>, KV<Instant, ReadableDuration>> state =
      c.forNewInput(now, null);
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(7)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(12)), state));
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:WatchTest.java

示例15: testTerminationConditionsAllOf

import org.joda.time.ReadableDuration; //导入依赖的package包/类
@Test
public void testTerminationConditionsAllOf() {
  Instant now = Instant.now();
  Watch.Growth.AfterTotalOf<Object> a = afterTotalOf(standardSeconds(5));
  Watch.Growth.AfterTotalOf<Object> b = afterTotalOf(standardSeconds(10));

  Watch.Growth.BinaryCombined<
          Object, KV<Instant, ReadableDuration>, KV<Instant, ReadableDuration>>
      c = allOf(a, b);
  KV<KV<Instant, ReadableDuration>, KV<Instant, ReadableDuration>> state =
      c.forNewInput(now, null);
  assertFalse(c.canStopPolling(now.plus(standardSeconds(3)), state));
  assertFalse(c.canStopPolling(now.plus(standardSeconds(7)), state));
  assertTrue(c.canStopPolling(now.plus(standardSeconds(12)), state));
}
 
开发者ID:apache,项目名称:beam,代码行数:16,代码来源:WatchTest.java


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