Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utcLocalDateTime to ApsoTimeDateTime #628

Merged
merged 1 commit into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions time/src/main/scala/com/velocidi/apso/time/Implicits.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 10 additions & 0 deletions time/src/test/scala/com/velocidi/apso/time/ImplicitsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
Loading