-
Notifications
You must be signed in to change notification settings - Fork 34
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
Conversation
Also adds utility for encode from int and long to Array[Byte].
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
docs/src/main/tut/quickstart.md
Outdated
@@ -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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frees-rpc-marshallers-jodatime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks.
This is no longer blocked or waiting for the 0.14.0 ;) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
|
||
"allow to convert int to and from byteArray" in { | ||
check { | ||
{ n: Int => |
There was a problem hiding this comment.
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
}
}
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
Add utility method for encoding joda.time instances.
Also adds utility for encoding from int and long to Array[Byte] in the internal module