[BAEL-11403] - Moved articles out of core-java (part 4)
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.zoneddatetime;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class OffsetDateTimeExampleUnitTest {
|
||||
|
||||
OffsetDateTimeExample offsetDateTimeExample = new OffsetDateTimeExample();
|
||||
|
||||
@Test
|
||||
public void givenZoneOffset_whenGetCurrentTime_thenResultHasZone() {
|
||||
String offset = "+02:00";
|
||||
OffsetDateTime time = offsetDateTimeExample.getCurrentTimeByZoneOffset(offset);
|
||||
|
||||
assertTrue(time.getOffset()
|
||||
.equals(ZoneOffset.of(offset)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.baeldung.zoneddatetime;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.time.OffsetTime;
|
||||
import java.time.ZoneOffset;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class OffsetTimeExampleUnitTest {
|
||||
|
||||
OffsetTimeExample offsetTimeExample = new OffsetTimeExample();
|
||||
|
||||
@Test
|
||||
public void givenZoneOffset_whenGetCurrentTime_thenResultHasZone() {
|
||||
String offset = "+02:00";
|
||||
OffsetTime time = offsetTimeExample.getCurrentTimeByZoneOffset(offset);
|
||||
|
||||
assertTrue(time.getOffset()
|
||||
.equals(ZoneOffset.of(offset)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.zoneddatetime;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ZoneDateTimeExampleUnitTest {
|
||||
|
||||
ZoneDateTimeExample zoneDateTimeExample = new ZoneDateTimeExample();
|
||||
|
||||
@Test
|
||||
public void givenZone_whenGetCurrentTime_thenResultHasZone() {
|
||||
String zone = "Europe/Berlin";
|
||||
ZonedDateTime time = zoneDateTimeExample.getCurrentTimeByZoneId(zone);
|
||||
|
||||
assertTrue(time.getZone()
|
||||
.equals(ZoneId.of(zone)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenZones_whenConvertDateByZone_thenGetConstantDiff() {
|
||||
String sourceZone = "Europe/Berlin";
|
||||
String destZone = "Asia/Tokyo";
|
||||
ZonedDateTime sourceDate = zoneDateTimeExample.getCurrentTimeByZoneId(sourceZone);
|
||||
ZonedDateTime destDate = zoneDateTimeExample.convertZonedDateTime(sourceDate, destZone);
|
||||
|
||||
assertTrue(sourceDate.toInstant()
|
||||
.compareTo(destDate.toInstant()) == 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user