Created
July 16, 2017 19:03
-
-
Save RichardSilveira/a76a4666ec853f9476a7a913d52e7a3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.log4j.Logger | |
import org.junit.Test | |
import java.time.* | |
import java.time.format.DateTimeFormatter | |
open class ZonedDateTimeWithEpochTest { | |
@Test | |
fun dateTimesExchanges_Between_Brazil_USA_West_Epoch_should_be_the_same() { | |
val dateInString = "16-07-2017 02:30:05 PM" | |
val currentDate = LocalDateTime.now(ZoneId.of("America/Boa_Vista")) | |
val ldtNow = LocalDateTime.of(LocalDate.now(), LocalTime.now()) | |
val ldtSample = LocalDateTime.parse(dateInString, DateTimeFormatter.ofPattern(DATE_FORMAT)) | |
val cuiabaZoneId = ZoneId.of("America/Boa_Vista") | |
val cuiabaDateTime = ldtSample.atZone(cuiabaZoneId) | |
val newYokZoneId = ZoneId.of("Asia/Singapore") | |
val nyDateTime: ZonedDateTime = cuiabaDateTime.withZoneSameInstant(newYokZoneId) | |
val cuiabaEpoch = cuiabaDateTime.toInstant().toEpochMilli() | |
val nyEpoch = nyDateTime.toInstant().toEpochMilli() | |
val otherEpoch = ldtSample.toInstant(ZonedDateTime.now().offset).toEpochMilli() | |
assert(cuiabaEpoch.equals(nyEpoch) && nyEpoch.equals(otherEpoch)) | |
} | |
companion object { | |
private val LOG = Logger.getLogger(ZonedDateTimeWithEpochTest::class.java) | |
const val DATE_FORMAT: String = "dd-M-yyyy hh:mm:ss a" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment