Split the first 2 modules: java-dates-conversion and java-dates-string.

This commit is contained in:
Alessio Stalla
2019-09-17 19:13:21 +02:00
parent 9154f5e062
commit ed9463faa1
62 changed files with 158 additions and 48 deletions

View File

@@ -0,0 +1,33 @@
package com.baeldung.zonedatetime;
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);
}
}