Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -1 +1,2 @@
|
||||
## Relevant Articles
|
||||
## Relevant Articles
|
||||
- [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections)
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
- [Parsing Date Strings with Varying Formats](https://www.baeldung.com/java-parsing-dates-many-formats)
|
||||
- [How Many Days Are There in a Particular Month of a Given Year?](https://www.baeldung.com/days-particular-month-given-year)
|
||||
- [Difference Between Instant and LocalDateTime](https://www.baeldung.com/java-instant-vs-localdatetime)
|
||||
- [Add Minutes to a Time String in Java](https://www.baeldung.com/java-string-time-add-mins)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-datetime-java8-1)
|
||||
|
||||
+24
-6
@@ -3,9 +3,11 @@ package com.baeldung.dateapi;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
|
||||
@@ -19,7 +21,7 @@ public class JavaDurationUnitTest {
|
||||
LocalTime finalTime = initialTime.plus(Duration.ofSeconds(30));
|
||||
|
||||
long seconds = Duration.between(initialTime, finalTime)
|
||||
.getSeconds();
|
||||
.getSeconds();
|
||||
|
||||
assertThat(seconds).isEqualTo(30);
|
||||
}
|
||||
@@ -34,6 +36,22 @@ public class JavaDurationUnitTest {
|
||||
assertThat(seconds).isEqualTo(30);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenADuration_whenCallingisZeroAndisNegative_thenGetExpectedResult() {
|
||||
LocalDateTime start = LocalDateTime.parse("2020-01-01T08:00:00");
|
||||
LocalDateTime end = LocalDateTime.parse("2020-01-01T12:00:00");
|
||||
assertFalse(Duration.between(start, end)
|
||||
.isNegative());
|
||||
assertTrue(Duration.between(end, start)
|
||||
.isNegative());
|
||||
|
||||
LocalDateTime theTime = LocalDateTime.parse("2023-09-09T08:00:00");
|
||||
assertTrue(Duration.between(theTime, theTime)
|
||||
.isZero());
|
||||
assertFalse(Duration.between(theTime, theTime)
|
||||
.isNegative());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Instant start = Instant.parse("2017-10-03T10:15:30.00Z");
|
||||
@@ -53,17 +71,17 @@ public class JavaDurationUnitTest {
|
||||
assertEquals(1, fromMinutes.toHours());
|
||||
|
||||
assertEquals(120, duration.plusSeconds(60)
|
||||
.getSeconds());
|
||||
.getSeconds());
|
||||
assertEquals(30, duration.minusSeconds(30)
|
||||
.getSeconds());
|
||||
.getSeconds());
|
||||
|
||||
assertEquals(120, duration.plus(60, ChronoUnit.SECONDS)
|
||||
.getSeconds());
|
||||
.getSeconds());
|
||||
assertEquals(30, duration.minus(30, ChronoUnit.SECONDS)
|
||||
.getSeconds());
|
||||
.getSeconds());
|
||||
|
||||
Duration fromChar1 = Duration.parse("P1DT1H10M10.5S");
|
||||
Duration fromChar2 = Duration.parse("PT10M");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,4 +5,5 @@
|
||||
- [Sorting a HashSet in Java](https://www.baeldung.com/java-sort-hashset)
|
||||
- [How to Get First Item From a Java Set](https://www.baeldung.com/first-item-set)
|
||||
- [Cartesian Product of Any Number of Sets in Java](https://www.baeldung.com/java-cartesian-product-sets)
|
||||
- [How to Get Index of an Item in Java Set](https://www.baeldung.com/java-set-element-find-index)
|
||||
- More articles: [[<-- prev]](/core-java-modules/core-java-collections-set)
|
||||
|
||||
@@ -5,4 +5,5 @@
|
||||
- [Java Concurrent HashSet Equivalent to ConcurrentHashMap](https://www.baeldung.com/java-concurrent-hashset-concurrenthashmap)
|
||||
- [Reading and Writing With a ConcurrentHashMap](https://www.baeldung.com/concurrenthashmap-reading-and-writing)
|
||||
- [ArrayBlockingQueue vs. LinkedBlockingQueue](https://www.baeldung.com/java-arrayblockingqueue-vs-linkedblockingqueue)
|
||||
- [Difference Between Hashtable and ConcurrentHashMap in Java](https://www.baeldung.com/java-hashtable-vs-concurrenthashmap)
|
||||
- [[<-- Prev]](/core-java-modules/core-java-concurrency-collections)
|
||||
|
||||
@@ -12,4 +12,4 @@ This module contains articles about inheritance in Java
|
||||
- [Guide to Inheritance in Java](https://www.baeldung.com/java-inheritance)
|
||||
- [Object Type Casting in Java](https://www.baeldung.com/java-type-casting)
|
||||
- [Variable and Method Hiding in Java](https://www.baeldung.com/java-variable-method-hiding)
|
||||
- [Inner Classes Vs. Subclasses in Java](https://www.baeldung.com/java-inner-classes-vs-subclasses)
|
||||
- [Inner Classes vs. Subclasses in Java](https://www.baeldung.com/java-inner-classes-vs-subclasses)
|
||||
|
||||
@@ -2,3 +2,4 @@
|
||||
- [Difference Between parallelStream() and stream().parallel() in Java](https://www.baeldung.com/java-parallelstream-vs-stream-parallel)
|
||||
- [Working With Empty Stream in Java](https://www.baeldung.com/java-empty-stream)
|
||||
- [Aggregate Runtime Exceptions in Java Streams](https://www.baeldung.com/java-streams-aggregate-exceptions)
|
||||
- [Streams vs. Loops in Java](https://www.baeldung.com/java-streams-vs-loops)
|
||||
|
||||
@@ -10,4 +10,5 @@
|
||||
- [Guide to Splitting a String by Whitespace in Java](https://www.baeldung.com/java-splitting-a-string-by-whitespace)
|
||||
- [Check if the First Letter of a String Is a Number](https://www.baeldung.com/java-check-if-string-starts-with-number)
|
||||
- [Print “” Quotes Around a String in Java](https://www.baeldung.com/java-string-print-quotes)
|
||||
- [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string)
|
||||
- [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string)
|
||||
- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string)
|
||||
|
||||
Reference in New Issue
Block a user