diff --git a/time/src/main/scala/com/velocidi/apso/time/Implicits.scala b/time/src/main/scala/com/velocidi/apso/time/Implicits.scala index 89c4a948..93879adf 100644 --- a/time/src/main/scala/com/velocidi/apso/time/Implicits.scala +++ b/time/src/main/scala/com/velocidi/apso/time/Implicits.scala @@ -66,6 +66,12 @@ object Implicits { */ final implicit class ApsoTimeDateTime(val d1: DateTime) extends AnyVal { + /** Returns a `LocalDateTime` corresponding to this `DateTime` at UTC. + * @return + * a `LocalDateTime` corresponding to this `DateTime` at UTC. + */ + def utcLocalDateTime: LocalDateTime = d1.withZone(DateTimeZone.UTC).toLocalDateTime + /** Returns a `LocalDate` corresponding to this `DateTime` at UTC. * @return * a `LocalDate` corresponding to this `DateTime` at UTC. diff --git a/time/src/test/scala/com/velocidi/apso/time/ImplicitsSpec.scala b/time/src/test/scala/com/velocidi/apso/time/ImplicitsSpec.scala index 5c95d2a2..d8bf9954 100644 --- a/time/src/test/scala/com/velocidi/apso/time/ImplicitsSpec.scala +++ b/time/src/test/scala/com/velocidi/apso/time/ImplicitsSpec.scala @@ -47,6 +47,16 @@ class ImplicitsSpec extends Specification { "An ApsoTimeDateTime" should { + "support conversion to UTC LocalDateTime" in { + val localDateTime = LocalDateTime.parse("2014-01-01T01:10:58") + val dateTime = localDateTime.toDateTime(DateTimeZone.forID("NZ")) + val estLocalDateTime = dateTime.toLocalDateTime + val utcLocalDateTime = dateTime.utcLocalDateTime + + estLocalDateTime === new LocalDateTime(2014, 1, 1, 1, 10, 58) + utcLocalDateTime === new LocalDateTime(2013, 12, 31, 12, 10, 58) + } + "support conversion to UTC LocalDate" in { val localDate = "2014-01-01".toLocalDate val dateTime = localDate.toDateTimeAtStartOfDay.toDateTime(DateTimeZone.forID("EST"))