Merge pull request #12936 from achraftt/BAEL-5791-deleteDiedCode
BAEL-5791: adaptation after creating new module
This commit is contained in:
commit
13698a3ed3
|
@ -1,32 +0,0 @@
|
|||
package com.baeldung.instant;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class StringToInstantConverterUnitTest {
|
||||
String stringDate = "09:15:30 PM, Sun 10/09/2022";
|
||||
String pattern = "hh:mm:ss a, EEE M/d/uuuu";
|
||||
|
||||
@Test public void givenStringTimeStamp_whenConvertingWithInstantUsingTimeZone_thenConvertToInstant() {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern, Locale.US);
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(stringDate, dateTimeFormatter);
|
||||
ZoneId zoneId = ZoneId.of("America/Chicago");
|
||||
ZonedDateTime zonedDateTime = localDateTime.atZone(zoneId);
|
||||
Instant instant = zonedDateTime.toInstant();
|
||||
assertThat(instant.toString()).isEqualTo("2022-10-10T02:15:30Z");
|
||||
}
|
||||
|
||||
@Test public void givenStringTimeStamp_whenConvertingWithLocalDateTime_thenConvertToInstant() {
|
||||
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern, Locale.US);
|
||||
LocalDateTime localDateTime = LocalDateTime.parse(stringDate, dateTimeFormatter);
|
||||
assertThat(localDateTime.toString()).isEqualTo("2022-10-09T21:15:30");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue