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

Utility method for encode joda time instances #276

Merged
merged 6 commits into from
Jul 10, 2018

Conversation

AntonioMateoGomez
Copy link
Contributor

Add utility method for encoding joda.time instances.
Also adds utility for encoding from int and long to Array[Byte] in the internal module

Also adds utility for encode from int and long to Array[Byte].
Copy link
Contributor

@fedefernandez fedefernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove the byte array related methods from JavaTimeUtil and update the encoders and the tests

val value: Array[Byte] = EncoderUtil.longToByteArray(n)

EncoderUtil.byteArrayToLong(value) shouldBe n
EncoderUtil.byteArrayToLong(value) == n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a mistake in my first PR, you could remove the shouldBe statement

val date: LocalDateTime = dt.toDateTime(DateTimeZone.UTC).toLocalDateTime
val value: Long = JodaTimeUtil.JodaLocalDatetimeToLong(date)

JodaTimeUtil.longToJodaLocalDateTime(value) shouldBe date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

val date: LocalDate = dt.toLocalDate
val value: Int = JodaTimeUtil.jodaLocalDateToInt(date)

JodaTimeUtil.intToJodaLocalDate(value) shouldBe date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line, please

{ n: Int =>
val value: Array[Byte] = EncoderUtil.intToByteArray(n)

EncoderUtil.byteArrayToInt(value) shouldBe n
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove this line

import org.joda.time._

object JodaTimeUtil {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a val here with the initial date? Something like:

private[this] val initialDate = DateTime.now(DateTimeZone.UTC).withMillis(0)

 and updated the encoders and the tests.
Also removed the shouldBe statement from JodaTimeUtilTest and EncoderUtilTest
@@ -49,8 +49,9 @@ class JavaTimeUtilTests extends WordSpec with Matchers with Checkers {
check {
forAll(genDateTimeWithinRange(from, range)) { zdt: ZonedDateTime =>
val date = zdt.toLocalDate
val value = JavaTimeUtil.localDateToByteArray(date)
JavaTimeUtil.byteArrayToLocalDate(value) == date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove this test. We've removed this method.

@@ -71,8 +72,8 @@ class JavaTimeUtilTests extends WordSpec with Matchers with Checkers {
check {
forAll(genDateTimeWithinRange(from, range)) { zdt: ZonedDateTime =>
val date = zdt.toLocalDateTime
val value = JavaTimeUtil.localDateTimeToByteArray(date)
JavaTimeUtil.byteArrayToLocalDateTime(value) == date
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, please remove this test

def jodaLocalDateToInt(value: LocalDate): Int =
Days
.daysBetween(
DateTime.now(DateTimeZone.UTC).withMillis(0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace this by the initalDate val

.getDays

def intToJodaLocalDate(value: Int): LocalDate =
DateTime.now().withMillis(0).plusDays(value).toLocalDate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Use of the initialDate val in the JodaTimeUtil methods.
Copy link
Contributor

@L-Lavigne L-Lavigne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! I have some comments about modules and dependencies, please take a look.

//// MARSHALLERS ////
/////////////////////

lazy val `marshallers-jodatime` = project
Copy link
Contributor

@L-Lavigne L-Lavigne May 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this really be in its own module? Makes sense if our practice is to do so when introducing new dependencies, otherwise I suggest integrating in an existing module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any case if making a new module, we should add it to the list in quickstart.md.

Copy link
Contributor

@fedefernandez fedefernandez May 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO it's a good idea to put it in it's own module in order to avoid adding more transitive dependencies. And yes, good catch, we should add it to the quickstart

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. We could also add a sentence or two in the docs about the new marshallers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add the information in the docs once we solved #269 because now it's not ready for its usage. @L-Lavigne @juanpedromoreno thoughts?

build.sbt Outdated

lazy val `marshallers-jodatime` = project
.in(file("modules/marshallers/jodatime"))
.dependsOn(common % "compile->compile;test->test")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all those dependencies? I don't see them imported in the code. (Possibly more dependencies are needed for unit tests, but those should be only in test scopes and not exported).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they will be used in the next PR for adding the marshallers but we could remove them for now 👍

Removed unused dependencies from the marshallers module in the `build.sbt`.
Minor changes in `JodaTimeUtil`
//// MARSHALLERS ////
/////////////////////

lazy val `marshallers-jodatime` = project
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. We could also add a sentence or two in the docs about the new marshallers.

@@ -28,6 +28,7 @@ It's divided into multiple and different artifacts, grouped by scope:
`frees-rpc-client-netty` | Client | Yes* | Mandatory on the client side if we are using `Netty` in the server side.
`frees-rpc-client-okhttp` | Client | Yes* | Mandatory on the client side if we are using `OkHttp` in the server side.
`frees-rpc-config` | Server/Client | No | Provides configuration helpers using [frees-config] to load the application configuration values.
`frees-rpc-marshallers` | Server/Client | No | Provides marshallers for serializing and deserializing the `LocalDate` and `LocalDateTime` joda instances.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

frees-rpc-marshallers-jodatime

Copy link
Contributor

@fedefernandez fedefernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks.

@juanpedromoreno
Copy link
Member

This is no longer blocked or waiting for the 0.14.0 ;)

Copy link
Member

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@AntonioMateoGomez AntonioMateoGomez merged commit ed9c222 into master Jul 10, 2018

"allow to convert int to and from byteArray" in {
check {
{ n: Int =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is missing the forAll right? maybe I'm missing something but I think this should be:

check {
  forAll { n: Int =>
    val value: Array[Byte] = EncoderUtil.intToByteArray(n)
    EncoderUtil.byteArrayToInt(value) == n
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes Fede, you are right.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, we can tackle it in the next PR. Thanks

@diesalbla diesalbla deleted the feature/joda-time-utilities branch May 7, 2019 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants