2023-01-08 17:13:31 +08:00
|
|
|
/*
|
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
|
* license agreements; and to You under the Apache License, version 2.0:
|
|
|
|
|
*
|
|
|
|
|
* https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the Apache Pekko project, derived from Akka.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-10-29 17:19:37 +08:00
|
|
|
/*
|
2022-02-04 12:36:44 +01:00
|
|
|
* Copyright (C) 2013-2022 Lightbend Inc. <https://www.lightbend.com>
|
2012-09-13 11:16:01 +02:00
|
|
|
*/
|
|
|
|
|
|
2017-05-11 11:59:28 +03:00
|
|
|
package jdocs.duration;
|
2012-09-13 11:16:01 +02:00
|
|
|
|
2019-01-12 04:00:53 +08:00
|
|
|
// #import
|
2012-10-15 16:18:52 +02:00
|
|
|
import scala.concurrent.duration.Duration;
|
|
|
|
|
import scala.concurrent.duration.Deadline;
|
2021-05-07 22:27:39 +03:00
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
2019-01-12 04:00:53 +08:00
|
|
|
// #import
|
2012-09-13 11:16:01 +02:00
|
|
|
|
|
|
|
|
class Java {
|
|
|
|
|
public void demo() {
|
2019-01-12 04:00:53 +08:00
|
|
|
// #dsl
|
2012-09-13 11:16:01 +02:00
|
|
|
final Duration fivesec = Duration.create(5, "seconds");
|
2012-10-15 16:18:52 +02:00
|
|
|
final Duration threemillis = Duration.create("3 millis");
|
2012-09-13 11:16:01 +02:00
|
|
|
final Duration diff = fivesec.minus(threemillis);
|
2021-05-07 22:27:39 +03:00
|
|
|
assertTrue(diff.lt(fivesec));
|
|
|
|
|
assertTrue(Duration.Zero().lt(Duration.Inf()));
|
2019-01-12 04:00:53 +08:00
|
|
|
// #dsl
|
|
|
|
|
// #deadline
|
2012-09-13 11:16:01 +02:00
|
|
|
final Deadline deadline = Duration.create(10, "seconds").fromNow();
|
|
|
|
|
final Duration rest = deadline.timeLeft();
|
2019-01-12 04:00:53 +08:00
|
|
|
// #deadline
|
2012-09-19 23:55:53 +02:00
|
|
|
rest.toString();
|
2012-09-13 11:16:01 +02:00
|
|
|
}
|
|
|
|
|
}
|