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


Java Duration类代码示例

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


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

示例1: CPSPublisherTask

import org.threeten.bp.Duration; //导入依赖的package包/类
private CPSPublisherTask(StartRequest request) {
  super(request, "gcloud", MetricsHandler.MetricName.PUBLISH_ACK_LATENCY);
  try {
    this.publisher =
        Publisher.defaultBuilder(TopicName.create(request.getProject(), request.getTopic()))
            .setBatchingSettings(
                BatchingSettings.newBuilder()
                    .setElementCountThreshold(950L)
                    .setRequestByteThreshold(9500000L)
                    .setDelayThreshold(
                        Duration.ofMillis(Durations.toMillis(request.getPublishBatchDuration())))
                    .build())
            .build();
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
  this.payload = ByteString.copyFromUtf8(LoadTestRunner.createMessage(request.getMessageSize()));
  this.batchSize = request.getPublishBatchSize();
  this.messageSize = request.getMessageSize();
  this.id = (new Random()).nextInt();
}
 
开发者ID:GoogleCloudPlatform,项目名称:pubsub,代码行数:22,代码来源:CPSPublisherTask.java

示例2: getRelativeTimeSpanString

import org.threeten.bp.Duration; //导入依赖的package包/类
public static String getRelativeTimeSpanString(@NonNull OffsetDateTime offsetDateTime) {
    long offset = Duration.between(offsetDateTime, OffsetDateTime.now()).toMillis();
    if (offset > YEAR) {
        return (offset / YEAR) + "年前";
    } else if (offset > MONTH) {
        return (offset / MONTH) + "个月前";
    } else if (offset > WEEK) {
        return (offset / WEEK) + "周前";
    } else if (offset > DAY) {
        return (offset / DAY) + "天前";
    } else if (offset > HOUR) {
        return (offset / HOUR) + "小时前";
    } else if (offset > MINUTE) {
        return (offset / MINUTE) + "分钟前";
    } else {
        return "刚刚";
    }
}
 
开发者ID:TakWolf,项目名称:Readhub-Android,代码行数:19,代码来源:FormatUtils.java

示例3: resetAfterRestart

import org.threeten.bp.Duration; //导入依赖的package包/类
@Test @SuppressWarnings("PMD.JUnitTestContainsTooManyAsserts")
public void resetAfterRestart() {
  LocalDateTime firstMockStart = LocalDateTime.of(2016, 1, 1, 0, 0, 0);
  LocalDateTime firstMockEnd = LocalDateTime.of(2016, 1, 1, 0, 1, 0);

  when(clock.now()).thenReturn(firstMockStart);
  stopwatch.start();
  when(clock.now()).thenReturn(firstMockEnd);
  stopwatch.stop();

  Duration firstActualDuration = Duration.between(firstMockStart, firstMockEnd);
  Duration firstMeasuredDuration = stopwatch.getDuration();
  assertThat(firstMeasuredDuration).isEqualTo(firstActualDuration);

  LocalDateTime secondMockStart = LocalDateTime.of(2016, 1, 1, 0, 5, 0);
  LocalDateTime secondMockEnd = LocalDateTime.of(2016, 1, 1, 0, 10, 0);

  when(clock.now()).thenReturn(secondMockStart);
  stopwatch.start();
  when(clock.now()).thenReturn(secondMockEnd);
  stopwatch.stop();

  Duration secondActualDuration = Duration.between(secondMockStart, secondMockEnd);
  Duration secondMeasuredDuration = stopwatch.getDuration();
  assertThat(secondMeasuredDuration).isEqualTo(secondActualDuration);
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:27,代码来源:StopwatchShould.java

示例4: newInfo

import org.threeten.bp.Duration; //导入依赖的package包/类
protected AccelerationData.Info newInfo(final Materialization materialization) {
  final com.dremio.service.accelerator.proto.JobDetails details = materialization.getJob();
  final Long jobStart = details.getJobStart();
  final Long jobEnd = details.getJobEnd();

  final AccelerationData.Info info = new AccelerationData.Info();
  if (jobStart != null) {
    info.setStart(DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(jobStart), ZoneOffset.UTC)));
  }
  if (jobEnd != null) {
    info.setEnd(DateTimeFormatter.RFC_1123_DATE_TIME.format(ZonedDateTime.ofInstant(Instant.ofEpochMilli(jobEnd), ZoneOffset.UTC)));
  }

  if (jobStart != null && jobEnd != null) {
    final Duration duration = Duration.ofMillis(jobEnd - jobStart);
    info.setDuration(DateTimeFormatter.ISO_LOCAL_TIME.format(LocalTime.MIDNIGHT.plus(duration)));
  }

  info.setJobId(details.getJobId())
    .setInputBytes(details.getInputBytes())
    .setInputRecords(details.getInputRecords())
    .setOutputBytes(details.getOutputBytes())
    .setOutputRecords(details.getOutputRecords());

  return info;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:27,代码来源:DatasetsResource.java

示例5: RxBindingExampleViewModel

import org.threeten.bp.Duration; //导入依赖的package包/类
@Inject
public RxBindingExampleViewModel() {
    final long intervalMs = 10;
    final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("mm:ss:SS");

    timeStream = Observable
            .interval(intervalMs, TimeUnit.MILLISECONDS)
            .onBackpressureDrop()
            .map(beats -> Duration.ofMillis(intervalMs * beats))
            .map(duration -> formatter.format(LocalTime.MIDNIGHT.plus(duration)));

    calculateSubject = PublishSubject.create();
    highLoadStream = calculateSubject
            .observeOn(Schedulers.computation())
            .scan((sum, value) -> ++sum)
            .map(iteration -> {
                // Simulate high processing load
                try {
                    Thread.sleep(1000);
                }
                catch (InterruptedException e) {}
                return iteration;
            });
}
 
开发者ID:futurice,项目名称:android-rxmvvmdi,代码行数:25,代码来源:RxBindingExampleViewModel.java

示例6: propertySet

import org.threeten.bp.Duration; //导入依赖的package包/类
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
  switch (propertyName.hashCode()) {
    case -281470431:  // classifier
      ((BloombergBpipePermissionCheckProviderComponentFactory) bean).setClassifier((String) newValue);
      return;
    case -614707837:  // publishRest
      ((BloombergBpipePermissionCheckProviderComponentFactory) bean).setPublishRest((Boolean) newValue);
      return;
    case 2061648978:  // bloombergConnector
      ((BloombergBpipePermissionCheckProviderComponentFactory) bean).setBloombergConnector((BloombergConnector) newValue);
      return;
    case 201583102:  // identityExpiryTime
      ((BloombergBpipePermissionCheckProviderComponentFactory) bean).setIdentityExpiryTime((Duration) newValue);
      return;
    case -1788671322:  // referenceDataProvider
      ((BloombergBpipePermissionCheckProviderComponentFactory) bean).setReferenceDataProvider((ReferenceDataProvider) newValue);
      return;
  }
  super.propertySet(bean, propertyName, newValue, quiet);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:BloombergBpipePermissionCheckProviderComponentFactory.java

示例7:

import org.threeten.bp.Duration; //导入依赖的package包/类
/**
 * @param allResults Cells in the viewport containing the data, history and the value specification. The outer
 * list contains the data by rows and the inner lists contain the data for each row
 * @param viewportDefinition Definition of the rows and columns in the viewport
 * @param columns The columns in the viewport's grid
 */
/* package */ ViewportResults(List<ResultsCell> allResults,
                              ViewportDefinition viewportDefinition,
                              GridColumnGroups columns,
                              Duration calculationDuration, Instant valuationTime) {
  ArgumentChecker.notNull(allResults, "allResults");
  ArgumentChecker.notNull(columns, "columns");
  ArgumentChecker.notNull(viewportDefinition, "viewportDefinition");
  ArgumentChecker.notNull(calculationDuration, "calculationDuration");
  ArgumentChecker.notNull(valuationTime, "valuationTime");
  _allResults = allResults;
  _viewportDefinition = viewportDefinition;
  _columns = columns;
  _calculationDuration = calculationDuration;
  _valuationTime = valuationTime;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:ViewportResults.java

示例8: init

import org.threeten.bp.Duration; //导入依赖的package包/类
@Override
public void init(Set<ValueSpecification> values, long timeout, TimeUnit ucUnit) {
  Instant start = OpenGammaClock.getInstance().instant();
  TemporalUnit unit = convertUnit(ucUnit);
  Duration remaining = Duration.of(timeout, unit);

  _historicalSnapshot1.init(values, timeout, ucUnit);
  Instant after1 = OpenGammaClock.getInstance().instant();
  Duration duration1 = Duration.between(start, after1);
  remaining = remaining.minus(duration1);
  if (remaining.isNegative()) {
    return;
  }
  _historicalSnapshot2.init(values, remaining.get(unit), ucUnit);
  Instant after2 = OpenGammaClock.getInstance().instant();
  Duration duration2 = Duration.between(after1, after2);
  remaining = remaining.minus(duration2);
  if (remaining.isNegative()) {
    return;
  }
  _baseSnapshot.init(values, remaining.get(unit), ucUnit);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:23,代码来源:HistoricalShockMarketDataSnapshot.java

示例9: checkModel

import org.threeten.bp.Duration; //导入依赖的package包/类
static void checkModel(InMemoryViewResultModel model) {
  ViewCycleExecutionOptions executionOptions = ViewCycleExecutionOptions.builder()
      .setValuationTime(Instant.ofEpochMilli(400)).create();

  model.setViewCycleExecutionOptions(executionOptions);
  assertEquals(executionOptions, model.getViewCycleExecutionOptions());
  model.setCalculationTime(Instant.ofEpochMilli(500));
  assertEquals(Instant.ofEpochMilli(500), model.getCalculationTime());
  model.setCalculationDuration(Duration.ofMillis(100));
  assertEquals(Duration.ofMillis(100), model.getCalculationDuration());
  
  model.addValue("configName1", COMPUTED_VALUE_RESULT);
  assertEquals(Sets.newHashSet(SPEC), Sets.newHashSet(model.getAllTargets()));
  
  ViewCalculationResultModel calcResult = model.getCalculationResult("configName1");
  assertNotNull(calcResult);
  
  Map<Pair<String, ValueProperties>, ComputedValueResult> targetResults = calcResult.getValues(SPEC);
  assertEquals(1, targetResults.size());
  assertEquals("DATA", targetResults.keySet().iterator().next().getFirst());
  assertEquals(COMPUTED_VALUE_RESULT, targetResults.values().iterator().next());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:23,代码来源:ViewComputationResultModelImplTest.java

示例10: set

import org.threeten.bp.Duration; //导入依赖的package包/类
@Override
public Builder set(String propertyName, Object newValue) {
  switch (propertyName.hashCode()) {
    case 109757538:  // start
      this._start = (Instant) newValue;
      break;
    case -1965553416:  // totalDuration
      this._totalDuration = (Duration) newValue;
      break;
    case -1109030316:  // initializationDuration
      this._initializationDuration = (Duration) newValue;
      break;
    case 440870092:  // executionDuration
      this._executionDuration = (Duration) newValue;
      break;
    case 1739046348:  // resultsBuildDuration
      this._resultsBuildDuration = (Duration) newValue;
      break;
    default:
      throw new NoSuchElementException("Unknown property: " + propertyName);
  }
  return this;
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:ViewTimer.java

示例11: invoke

import org.threeten.bp.Duration; //导入依赖的package包/类
@Override
protected Object invoke(Object proxy, Object delegate, Method method, Object[] args) throws Throwable {
  // this avoids recording calls to toString() in the debugger
  if (method.getName().equals("toString")) {
    return method.invoke(delegate, args);
  }
  Tracer tracer = s_tracer.get();
  tracer.called(method, args);
  long start = System.nanoTime();
  try {
    Object retVal = method.invoke(delegate, args);
    tracer.returned(retVal, Duration.ofNanos(System.nanoTime() - start));
    return retVal;
  } catch (Exception ex) {
    long end = System.nanoTime();
    Throwable cause = EngineUtils.getCause(ex);
    tracer.threw(cause, Duration.ofNanos(end - start));
    throw cause;
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:TracingProxy.java

示例12: apply

import org.threeten.bp.Duration; //导入依赖的package包/类
@Override
public ExerciseSession apply(@javax.annotation.Nullable UserEventRecord exerciseSession) {
  checkNotNull(exerciseSession, "exerciseSession should be non-null");
  checkArgument(exerciseSession.getEventType() == EXERCISE);

  Instant internalTimeUTC =
      DEXCOM_SYSTEM_TIME_TO_INSTANT.apply(exerciseSession.getInternalSecondsSinceDexcomEpoch());
  LocalDateTime localRecordedTime =
      DEXCOM_DISPLAY_TIME_TO_LOCAL_DATE_TIME.apply(exerciseSession.getLocalSecondsSinceDexcomEpoch());
  LocalDateTime eventLocalTime =
      DEXCOM_DISPLAY_TIME_TO_LOCAL_DATE_TIME.apply(exerciseSession.getEventSecondsSinceDexcomEpoch());

  long duration = exerciseSession.getEventValue();

  UserEventRecord.ExerciseIntensity exerciseIntensity =
      UserEventRecord.ExerciseIntensity.fromId(exerciseSession.getEventSubType());
  ExerciseSession.Intensity intensity =
      DEXCOM_EXERCISE_INTENSITY_TO_INTENSITY.apply(exerciseIntensity);

  return new ExerciseSession(internalTimeUTC, localRecordedTime, eventLocalTime,
      intensity, Duration.ofMinutes(duration), EMPTY_DESCRIPTION);
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:23,代码来源:DexcomAdapterService.java

示例13: exerciseUserRecordShouldBeConverted

import org.threeten.bp.Duration; //导入依赖的package包/类
@Test
public void exerciseUserRecordShouldBeConverted() throws Exception {
  DexcomAdapterService dexcomAdapterService = new DexcomAdapterService();

  SyncData syncData = dexcomAdapterService.convertData(
      new DexcomSyncData(EMPTY_GLUCOSE_READ_RECORDS,
          Arrays.asList(new UserEventRecord(1000L, 2000L, 1500L, UserEventRecord.UserEventType.EXERCISE,
              UserEventRecord.ExerciseIntensity.LIGHT.getId(), 10)),
          new ManufacturingParameters(SERIAL_NUMBER, "partNumber", HARDWARE_REVISION, "2013-10-18 10:10", HARDWARE_ID),
              TEST_TIME));

  ExerciseSession expectedExerciseSession = new ExerciseSession(internalTimeFromSeconds(1000L),
      localDateTimeFromSeconds(2000L), localDateTimeFromSeconds(1500L), ExerciseSession.Intensity.LIGHT,
      Duration.ofMinutes(10), ExerciseSession.EMPTY_DESCRIPTION);
  SyncData expectedSyncData = new SyncData(EMPTY_GLUCOSE_READS, EMPTY_INSULIN_INJECTIONS, EMPTY_FOOD_EVENTS,
      Arrays.asList(expectedExerciseSession), new DeviceInfo(SERIAL_NUMBER, HARDWARE_ID, HARDWARE_REVISION),
          TEST_TIME);

  assertThat(syncData, is(equalTo(expectedSyncData)));
}
 
开发者ID:alexandre-normand,项目名称:blood-shepherd,代码行数:21,代码来源:TestDexcomAdapterService.java

示例14: isSmsSentOneHourAgo

import org.threeten.bp.Duration; //导入依赖的package包/类
public static boolean isSmsSentOneHourAgo(Context context) {
    Long smsSentEpoch = CRDSharedPreferences.getInstance(context).getSendingSmsEpoch();

    if (smsSentEpoch == null) {
        return false;
    }

    Instant oneHourAgo = getNowTime().toInstant().minus(Duration.ofHours(1));
    Instant smsSentInstant = Instant.ofEpochMilli(smsSentEpoch);

    return smsSentInstant.isAfter(oneHourAgo) && smsSentInstant.isBefore(getNowTime().toInstant());
}
 
开发者ID:NinoDLC,项目名称:CineReminDay,代码行数:13,代码来源:CRDTimeManager.java

示例15: measureDurationTime

import org.threeten.bp.Duration; //导入依赖的package包/类
@Test public void measureDurationTime() {
  LocalDateTime mockStart = LocalDateTime.of(2016, 1, 1, 0, 0, 0);
  LocalDateTime mockEnd = LocalDateTime.of(2016, 1, 1, 0, 1, 0);

  when(clock.now()).thenReturn(mockStart);
  stopwatch.start();

  when(clock.now()).thenReturn(mockEnd);
  stopwatch.stop();

  assertThat(stopwatch.getDuration()).isEqualTo(Duration.between(mockStart, mockEnd));
}
 
开发者ID:philipphager,项目名称:disclosure-android-app,代码行数:13,代码来源:StopwatchShould.java


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