Skip to content

Commit

Permalink
Merge pull request #136 from CruncherBigData/develop
Browse files Browse the repository at this point in the history
jodatime re-sending to reflect latest changes.
  • Loading branch information
sritchie committed Jul 24, 2013
2 parents 35819a9 + 2fbeaaf commit 41a57bd
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 1 deletion.
Empty file modified CHANGES.md
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.twitter.bijection.jodatime

import com.twitter.bijection.{ Bijection, AbstractBijection}
import java.util.Date
import org.joda.time.DateTime

trait DateBijections {

implicit val date2joda: Bijection[java.util.Date, DateTime] =
new AbstractBijection[java.util.Date, DateTime] {
def apply(d: java.util.Date) = new DateTime(d)
override def invert(joda: DateTime) = joda.toDate()
}

implicit val joda2Long: Bijection[DateTime, Long] =
new AbstractBijection[DateTime, Long] {
def apply(d: DateTime) = d.getMillis()
override def invert(l: Long) = new DateTime(l)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.twitter.bijection.jodatime

import java.util.Date
import org.joda.time.DateTime
import com.twitter.bijection.Inversion.attempt
import com.twitter.bijection.{ Injection, InversionFailure, AbstractInjection }

trait DateInjections {

implicit val date2String: Injection[Date, String] =
new AbstractInjection[Date, String] {
def apply(d: Date) = d.toString
override def invert(s: String) = attempt(s)(new DateTime(_).toDate())

}

implicit val joda2String: Injection[DateTime, String] =
new AbstractInjection[DateTime, String] {
def apply(d: DateTime) = d.toString
override def invert(s: String) = attempt(s)(new DateTime(_))
}


implicit val joda2Date: Injection[DateTime, Date] =
new AbstractInjection[DateTime, Date] {
def apply(d: DateTime) = d.toDate()
override def invert(d: Date) = attempt(d)(new DateTime(_))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.twitter.bijection.jodatime

import org.scalacheck.Properties
import org.scalacheck.Gen._
import org.scalacheck.Arbitrary
import org.scalacheck.Prop._
import com.twitter.bijection.{ Bijection, BaseProperties, ImplicitBijection }
import java.util.Date
import org.joda.time.DateTime
import com.twitter.bijection._

object DateBijectionsLaws extends Properties("DateBijections") with BaseProperties with DateBijections with DateInjections {

import Rep._

implicit val strByte = arbitraryViaBijection[Date, String @@ Rep[Date]]

implicit val date = arbitraryViaFn { (dtime: Long) => new DateTime(dtime) }

property("Long <=> Joda") = isBijection[Long, DateTime]

property("Date <=> Joda") = isBijection[Date, DateTime]

property("round trips Date -> String") = isLooseInjection[DateTime,String]

property("round trips Joda -> Date") = isLooseInjection[DateTime, Date]


}
13 changes: 12 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ object BijectionBuild extends Build {
bijectionClojure,
bijectionNetty,
bijectionAvro,
bijectionHbase
bijectionHbase,
bijectionJodaTime
)

def module(name: String) = {
Expand Down Expand Up @@ -221,4 +222,14 @@ object BijectionBuild extends Build {
"org.apache.hadoop" % "hadoop-core" % "1.0.4" % "provided->default"
)
).dependsOn(bijectionCore % "test->test;compile->compile")

lazy val bijectionJodaTime = module("jodatime").settings(
osgiExportAll("com.twitter.bijection.jodatime"),
libraryDependencies ++= Seq(
"joda-time" % "joda-time" % "2.2",
"org.joda" % "joda-convert" % "1.3.1"
)
).dependsOn(bijectionCore % "test->test;compile->compile")


}

0 comments on commit 41a57bd

Please sign in to comment.