本文整理汇总了Scala中org.joda.time.LocalDate类的典型用法代码示例。如果您正苦于以下问题:Scala LocalDate类的具体用法?Scala LocalDate怎么用?Scala LocalDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalDate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Books
//设置package包名称以及导入依赖的类
package org.packtpublishing.persistence
import org.joda.time.LocalDate
import slick.driver.H2Driver.api._
import com.github.tototoshi.slick.H2JodaSupport._
import org.packtpublishing.persistence.Publishers._
import org.packtpublishing.model.Book
class Books(tag: Tag) extends Table[Book](tag, "BOOKS") {
def isbn = column[String]("ISBN", O.PrimaryKey, O.Length(14))
def title = column[String]("TITLE", O.Length(512))
def author = column[String]("AUTHOR", O.Length(256))
def publishingDate = column[LocalDate]("PUBLISHING_DATE")
def publisherId = column[Long]("PUBLISHER_ID")
def publisher = foreignKey("PUBLISHER_FK", publisherId, publishers)(_.id, onUpdate=ForeignKeyAction.Restrict, onDelete=ForeignKeyAction.Cascade)
def * = (isbn, title, author, publishingDate, publisherId) <> (Book.tupled, Book.unapply)
}
object Books {
val books = TableQuery[Books]
}
开发者ID:allansene,项目名称:spray-scala-akka-book-catalog,代码行数:24,代码来源:Books.scala
示例2: dateOf
//设置package包名称以及导入依赖的类
package io.github.mijicd.prezi.modules
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormatterBuilder
trait DateConversion {
private val format = new DateTimeFormatterBuilder().
appendMonthOfYearText().
appendLiteral(" ").
appendDayOfMonth(1).
appendLiteral(", ").
appendYear(4, 4).
toFormatter
def dateOf(value: String): LocalDate = LocalDate.parse(value, format)
}
开发者ID:mijicd,项目名称:finatra-demo,代码行数:18,代码来源:DateConversion.scala
示例3: DataSourceSpec
//设置package包名称以及导入依赖的类
package io.github.mijicd.prezi.modules
import io.github.mijicd.prezi.TestSpec
import org.joda.time.LocalDate
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class DataSourceSpec extends TestSpec {
"DataSource" should "convert date strings into LocalDate instances" in {
val text = "March 18, 1987"
val date = new LocalDate(1987, 3, 18)
DataSource.dateOf(text) should equal(date)
}
it should "load 100 presentations from JSON file" in {
val items = DataSource.provideSource
items should have size 100
}
it should "load data in proper order" in {
val items = DataSource.provideSource
val dates = items map { item => DataSource.dateOf(item.createdAt) }
val sorted = dates.sortWith((a, b) => b.isBefore(a))
dates should equal(sorted)
}
}
开发者ID:mijicd,项目名称:finatra-demo,代码行数:31,代码来源:DataSourceSpec.scala
示例4: DateHelper
//设置package包名称以及导入依赖的类
package utilities
import java.sql.{Timestamp,Date,Time}
import org.joda.time.{DateTime,LocalDate,LocalTime,DateTimeZone}
import org.joda.time.format._
object DateHelper {
def dateTimeToSqlTimestamp: DateTime => Timestamp = { dt => new Timestamp(dt.getMillis) }
def sqlTimestampToDateTime: Timestamp => DateTime = { ts => new DateTime(ts.getTime) }
def localDateToSqlDate: LocalDate => Date = { ld => new Date(ld.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis) }
def sqlDateToLocalDate: Date => LocalDate = { d => new LocalDate(d.getTime) }
def localTimeToSqlTime: LocalTime => Time = { lt => new Time(lt.toDateTimeToday.getMillis) }
def sqlTimeToLocalTime: Time => LocalTime = { t => new LocalTime(t, DateTimeZone.UTC) }
def dateToString(date:java.util.Date, format:String = "yyyy-MM-dd HH:mm:ss"):String = {
import java.text._
val sdf = new SimpleDateFormat(format)
sdf.format(date)
}
def stringToDate(datestr:String, format:String = "yyyy-MM-dd HH:mm:ss"):java.util.Date = {
import java.text._
val sdf = new SimpleDateFormat(format)
sdf.parse(datestr)
}
}
开发者ID:bananapianist,项目名称:playfw_sample,代码行数:26,代码来源:DateHelper.scala
示例5: EmploymentCheckResult
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.controllers.api
import javax.inject.Inject
import org.joda.time.LocalDate
import play.api.libs.json.Json
import play.api.mvc.Controller
import uk.gov.bis.levyApiMock.actions.AuthorizedAction
import uk.gov.bis.levyApiMock.controllers.ClosedDateRange
import uk.gov.bis.levyApiMock.data.levy.EmploymentStatusOps
import uk.gov.hmrc.domain.EmpRef
import scala.concurrent.{ExecutionContext, Future}
case class EmploymentCheckResult(empref: String, nino: String, fromDate: LocalDate, toDate: LocalDate, employed: Boolean)
object EmploymentCheckResult {
implicit val formats = Json.format[EmploymentCheckResult]
}
class EmploymentController @Inject()(employment: EmploymentStatusOps[Future], AuthorizedAction: AuthorizedAction)(implicit ec: ExecutionContext) extends Controller {
def employmentCheck(empref: EmpRef, nino: String, fromDate: LocalDate, toDate: LocalDate) = AuthorizedAction(empref.value).async { implicit request =>
ClosedDateRange.fromDates(fromDate, toDate) match {
case Some(dateRange) => employment.employed(empref.value, nino, dateRange).map {
case Some(result) => Ok(Json.toJson(result))
case None => NotFound(Json.obj("code" -> "EPAYE_UNKNOWN", "message" -> "The provided NINO or EMPREF was not recognised"))
}
case None => Future.successful(BadRequest(Json.obj("code" -> "BAD_DATE_RANGE", "message" -> "The fromDate cannot be before the toDate")))
}
}
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:33,代码来源:EmploymentController.scala
示例6: LevyDeclarationController
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.controllers.api
import javax.inject._
import org.joda.time.LocalDate
import play.api.libs.json._
import play.api.mvc._
import uk.gov.bis.levyApiMock.actions.AuthorizedAction
import uk.gov.bis.levyApiMock.controllers.DateRange
import uk.gov.bis.levyApiMock.data.levy.{LevyDeclarationOps, LevyDeclarationResponse}
import uk.gov.hmrc.domain.EmpRef
import scala.concurrent.ExecutionContext
class LevyDeclarationController @Inject()(declarations: LevyDeclarationOps, AuthorizedAction: AuthorizedAction)(implicit exec: ExecutionContext)
extends Controller {
implicit class LevyDeclarationsSyntax(resp: LevyDeclarationResponse) {
def filter(dateRange: DateRange): LevyDeclarationResponse = {
val filtered = resp.declarations.filter(d => dateRange.contains(d.submissionTime.toLocalDate))
resp.copy(declarations = filtered)
}
def sort: LevyDeclarationResponse = {
val sorted = resp.declarations.sortBy(_.id).reverse
resp.copy(declarations = sorted)
}
}
def levyDeclarations(empref: EmpRef, fromDate: Option[LocalDate], toDate: Option[LocalDate]) =
AuthorizedAction(empref.value).async { implicit request =>
val dateRange = DateRange(fromDate, toDate)
declarations.byEmpref(empref.value).map {
case Some(decls) => Ok(Json.toJson(decls.filter(dateRange).sort))
case None => NotFound
}
}
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:40,代码来源:LevyDeclarationController.scala
示例7: PayrollPeriod
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.data.levy
import org.joda.time.format.DateTimeFormat
import org.joda.time.{LocalDate, LocalDateTime}
import play.api.libs.json._
case class PayrollPeriod(year: String, month: Int)
object PayrollPeriod {
implicit val formats = Json.format[PayrollPeriod]
}
case class LevyDeclaration(id: Long,
submissionTime: LocalDateTime,
dateCeased: Option[LocalDate] = None,
inactiveFrom: Option[LocalDate] = None,
inactiveTo: Option[LocalDate] = None,
payrollPeriod: Option[PayrollPeriod] = None,
levyDueYTD: Option[BigDecimal] = None,
levyAllowanceForFullYear: Option[BigDecimal] = None,
noPaymentForPeriod: Option[Boolean] = None)
object LevyDeclaration {
implicit val ldtFormats = new Format[LocalDateTime] {
val fmt = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS")
override def reads(json: JsValue): JsResult[LocalDateTime] = implicitly[Reads[JsString]].reads(json).map { js =>
fmt.parseDateTime(js.value).toLocalDateTime
}
override def writes(o: LocalDateTime): JsValue = JsString(fmt.print(o))
}
implicit val formats = Json.format[LevyDeclaration]
}
case class LevyDeclarationResponse(empref: String, declarations: Seq[LevyDeclaration])
object LevyDeclarationResponse {
implicit val formats = Json.format[LevyDeclarationResponse]
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:43,代码来源:LevyDeclarationResponse.scala
示例8: ClosedDateRangeTest
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.controllers
import org.joda.time.LocalDate
import org.scalatest.{Matchers, WordSpecLike}
class ClosedDateRangeTest extends WordSpecLike with Matchers {
val refRange = ClosedDateRange(new LocalDate(2017, 1, 1), new LocalDate(2017, 1, 31))
"overlaps" should {
"return correct result" in {
refRange.overlaps(ClosedDateRange(new LocalDate(2017, 1, 1), new LocalDate(2017, 1, 31))) shouldBe true
refRange.overlaps(ClosedDateRange(new LocalDate(2016, 12, 1), new LocalDate(2016, 12, 31))) shouldBe false
refRange.overlaps(ClosedDateRange(new LocalDate(2016, 12, 1), new LocalDate(2017, 1, 1))) shouldBe true
refRange.overlaps(ClosedDateRange(new LocalDate(2017, 1, 31), new LocalDate(2017, 2, 10))) shouldBe true
refRange.overlaps(ClosedDateRange(new LocalDate(2017, 1, 5), new LocalDate(2017, 1, 10))) shouldBe true
refRange.overlaps(ClosedDateRange(new LocalDate(2016, 12, 1), new LocalDate(2017, 2, 20))) shouldBe true
refRange.overlaps(ClosedDateRange(new LocalDate(2017, 2, 1), new LocalDate(2017, 2, 10))) shouldBe false
}
}
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:24,代码来源:ClosedDateRangeTest.scala
示例9: EmploymentsGenTest
//设置package包名称以及导入依赖的类
package uk.gov.bis.levyApiMock.services
import org.joda.time.LocalDate
import org.scalatest.{Matchers, OptionValues, WordSpecLike}
import uk.gov.bis.levyApiMock.controllers.ClosedDateRange
import uk.gov.bis.levyApiMock.data.levy.EmploymentCheckRecord
class EmploymentsGenTest extends WordSpecLike with Matchers with OptionValues {
import EmploymentStatusGenTestSupport._
val sut = new EmploymentsGen[TestF](repo)
"employed" should {
"return no records" in {
sut.employed("foo", "bar", ClosedDateRange(new LocalDate(), new LocalDate()))(TestData(Seq.empty))._2 shouldBe None
}
val empStart = new LocalDate(2017, 1, 1)
val empEnd = new LocalDate(2017, 2, 28)
val data = TestData(Seq(EmploymentCheckRecord("foo", "bar", empStart, empEnd)))
"return 'employed' if the request specifies a range that overlaps with the employment in any way" in {
sut.employed("foo", "bar", ClosedDateRange(empStart.minusDays(1), empEnd.plusDays(1)))(data)._2.value.employed shouldBe true
sut.employed("foo", "bar", ClosedDateRange(empStart, empEnd))(data)._2.value.employed shouldBe true
sut.employed("foo", "bar", ClosedDateRange(empStart, empEnd.minusDays(1)))(data)._2.value.employed shouldBe true
}
}
}
开发者ID:UKGovernmentBEIS,项目名称:das-alpha-hmrc-api-mock,代码行数:30,代码来源:EmploymentsGenTest.scala
示例10: LocalDateHelpers
//设置package包名称以及导入依赖的类
package utils
import algebra.Cats.TryAsJsResult
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormat
import play.api.libs.json._
import scala.util.Try
object LocalDateHelpers {
def parse(str: String): Try[LocalDate] =
dateFormat1(str) orElse dateFormat2(str) orElse dateFormat3(str) orElse dateFormat4(str) orElse dateFormat5(str) orElse dateFormat6(
str)
implicit val jsonReads: Reads[LocalDate] = Reads(_.validate[String].flatMap(x => TryAsJsResult(parse(x))))
implicit val jsonWrites: Writes[LocalDate] =
Writes { date =>
val format = DateTimeFormat.forPattern("dd-MM-yyyy")
val string = date.toString(format)
JsString(string)
}
implicit val orderingLocalDate: Ordering[LocalDate] =
Ordering.by[LocalDate, (Int, Int, Int)](x => (x.getYear, x.getMonthOfYear, x.getDayOfMonth))
private def dateFormat1(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("dd-mm-yyyy")))
private def dateFormat2(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("dd/mm/yyyy")))
private def dateFormat3(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("dd.mm.yyyy")))
private def dateFormat4(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("yyyy-mm-dd")))
private def dateFormat5(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("yyyy/mm/dd")))
private def dateFormat6(str: String): Try[LocalDate] =
Try(LocalDate.parse(str, DateTimeFormat.forPattern("yyyy.mm.dd")))
}
开发者ID:FrancoAra,项目名称:freet-presentation,代码行数:46,代码来源:LocalDateHelpers.scala
示例11: DatumTest
//设置package包名称以及导入依赖的类
package org.scalarules.dsl.nl.datum
import org.joda.time.LocalDate
import org.scalarules.dsl.nl.grammar.aanwezig
import org.scalarules.utils.InternalBerekeningenTester
import org.scalarules.dsl.nl.datum.DatumTestGlossary._
class DatumTest extends InternalBerekeningenTester(new DatumTestsBerekening) with DatumImplicits {
val supportedDateFormats = Set(
"d-M-yyyy",
"d-MM-yyyy",
"dd-M-yyyy",
"dd-MM-yyyy"
)
val datumEerder = new LocalDate(2014, 1, 1)
val datumGelijk = new LocalDate(2015, 1, 1)
val datumLater = new LocalDate(2016, 1, 1)
supportedDateFormats.foreach( pattern => {
test(s"${pattern} parsen werkt (1/3)") gegeven (
InvoerDatum is datumEerder.toString(pattern).datum
) verwacht (
EerderDan is "success",
EerderDanGelijk is "success",
LaterDan niet aanwezig,
LaterDanGelijk niet aanwezig,
GelijkAan niet aanwezig
)
test(s"${pattern} parsen werkt (2/3)") gegeven (
InvoerDatum is datumLater.toString(pattern).datum
) verwacht (
EerderDan niet aanwezig,
EerderDan niet aanwezig,
LaterDan is "success",
LaterDanGelijk is "success",
GelijkAan niet aanwezig
)
test(s"${pattern} parsen werkt (3/3)") gegeven (
InvoerDatum is datumGelijk.toString(pattern).datum
) verwacht (
EerderDan niet aanwezig,
EerderDanGelijk is "success",
LaterDan niet aanwezig,
LaterDanGelijk is "success",
GelijkAan is "success"
)
})
}
开发者ID:scala-rules,项目名称:rule-engine,代码行数:56,代码来源:DatumTest.scala
示例12: AttendanceRepositoryOnDB
//设置package包名称以及导入依赖的类
package infra.jdbc
import domain.AttendanceRepository
import domain.model.{Attendance, AttendanceId, OfficeId, UserId}
import org.joda.time.{DateTime, DurationFieldType, LocalDate}
import scalikejdbc._
import support.IOContext
import scala.concurrent.Future
class AttendanceRepositoryOnDB
extends AttendanceRepository
with RepositoryOnDB[Attendance, AttendanceId] {
override val tableName = "attendance"
override val columns = Seq("id", "user_id", "office_id", "start_time", "end_time", "creator_id", "created", "updator_id", "updated")
override def entityMap(e:Attendance):Map[SQLSyntax, ParameterBinder] = Map(
column.id -> e.id,
column.userId -> e.userId,
column.officeId -> e.officeId,
column.startTime -> e.startTime,
column.endTime -> e.endTime,
column.creatorId -> e.creatorId,
column.updatorId -> e.updatorId
)
override def entity(a: ResultName[Attendance])(rs: WrappedResultSet): Attendance =
Attendance(
id = AttendanceId(rs.get(a.id)),
userId = UserId(rs.get(a.userId)),
officeId = OfficeId(rs.get(a.officeId)),
startTime = rs.jodaDateTime(a.startTime),
endTime = rs.jodaDateTimeOpt(a.endTime),
creatorId = UserId(rs.get(a.creatorId)),
created = rs.jodaDateTime(a.created),
updatorId = UserId(rs.get(a.updatorId)),
updated = rs.jodaDateTime(a.updated)
)
override def createdEntity(e: Attendance, newId: Long): Attendance =
e.copy(id = AttendanceId(newId), created = DateTime.now(), updated = DateTime.now())
override val stx = syntax("a")
override def list(userId: UserId, year: Int, month: Int)(implicit io: IOContext): Future[List[Attendance]] =
Future{
val from = new LocalDate(year, month, 1)
val to = from.withFieldAdded(DurationFieldType.months(), 1)
_select(sqls"user_id = $userId AND start_time >= $from AND start_time < $to")
}
}
开发者ID:tockri,项目名称:hello-next,代码行数:54,代码来源:AttendanceRepositoryOnDB.scala
示例13: DatedDag
//设置package包名称以及导入依赖的类
package sativum
import org.joda.time.LocalDate
abstract class DatedDag(_dt: String) extends Dag {
val dt = new LocalDate(_dt)
def runDated() {
endpoints.map(sativum(_))
while (!ready()) {
Thread.sleep(waitTime)
}
endpoints.flatMap(_.parents).foreach {
case d: DatedTask => d.delete()
case _ =>
}
endpoints.par.map(sativum(_).get())
}
}
开发者ID:mindfulmachines,项目名称:sativum,代码行数:19,代码来源:DatedDag.scala
示例14: ImplicitsTest
//设置package包名称以及导入依赖的类
package sativum
import org.joda.time.LocalDate
import org.scalatest.FunSuite
class ImplicitsTest extends FunSuite {
test("LocalDateImplicits") {
import Implicits._
assert(
new LocalDate("2016-01-01").until(new LocalDate("2016-01-03")) ==
new LocalDate("2016-01-01") :: new LocalDate("2016-01-02") :: Nil
)
assert(
"2016-01-01".until("2016-01-03") ==
new LocalDate("2016-01-01") :: new LocalDate("2016-01-02") :: Nil
)
}
}
开发者ID:mindfulmachines,项目名称:sativum,代码行数:19,代码来源:ImplicitsTest.scala
示例15: TimeEntry
//设置package包名称以及导入依赖的类
package redmine4s.api.model
import org.joda.time.{DateTime, LocalDate}
import redmine4s.Redmine
case class TimeEntry(id: Long,
project: (Long, String),
issueId: Option[Long],
user: (Long, String),
activity: (Long, String),
hours: Double,
comments: String,
spentOn: LocalDate,
createdOn: DateTime,
updatedOn: DateTime,
customField: Seq[CustomFieldValue],
redmine: Redmine) {
def delete(): Unit = redmine.deleteTimeEntry(id)
}
开发者ID:tomingtoming,项目名称:redmine4s,代码行数:21,代码来源:TimeEntry.scala
示例16:
//设置package包名称以及导入依赖的类
package redmine4s.api.json
import org.joda.time.{DateTime, LocalDate}
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads.pure
import play.api.libs.json._
import redmine4s.api.model.{CustomFieldValue, TimeEntry}
trait TimeEntryJsonHelper extends CustomFieldJsonHelper {
implicit val timeEntryReads: Reads[TimeEntry] = (
(__ \ 'id).read[Long] ~
(__ \ 'project).read[(Long, String)] ~
((__ \ 'issue \ 'id).readNullable[Long] orElse (__ \ 'issue).readNullable[Long]) ~
(__ \ 'user).read[(Long, String)] ~
(__ \ 'activity).read[(Long, String)] ~
(__ \ 'hours).read[Double] ~
(__ \ 'comments).read[String] ~
(__ \ 'spent_on).read[LocalDate](dateReads) ~
(__ \ 'created_on).read[DateTime](timeReads) ~
(__ \ 'updated_on).read[DateTime](timeReads) ~
((__ \ 'custom_fields).read[Seq[CustomFieldValue]] or pure(Seq.empty[CustomFieldValue]))
) { (id: Long, project: (Long, String), issueId: Option[Long], user: (Long, String), activity: (Long, String), hours: Double, comments: String, spentOn: LocalDate, createdOn: DateTime, updatedOn: DateTime, customField: Seq[CustomFieldValue]) =>
TimeEntry(id, project, issueId, user, activity, hours, comments, spentOn, createdOn, updatedOn, customField, null)
}
implicit val timeEntryCreateForProjectWrites = (
(__ \ 'time_entry \ 'project_id).write[Long] ~
(__ \ 'time_entry \ 'spent_on).write[LocalDate] ~
(__ \ 'time_entry \ 'hours).write[Double] ~
(__ \ 'time_entry \ 'activity_id).write[Long] ~
(__ \ 'time_entry \ 'comments).write[String] ~
(__ \ 'time_entry \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
implicit val timeEntryCreateForIssueWrites = (
(__ \ 'time_entry \ 'issue_id).write[Long] ~
(__ \ 'time_entry \ 'spent_on).write[LocalDate] ~
(__ \ 'time_entry \ 'hours).write[Double] ~
(__ \ 'time_entry \ 'activity_id).write[Long] ~
(__ \ 'time_entry \ 'comments).write[String] ~
(__ \ 'time_entry \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
implicit val timeEntryUpdateForProjectWrites = (
(__ \ 'time_entry \ 'project_id).writeNullable[Long] ~
(__ \ 'time_entry \ 'spent_on).writeNullable[LocalDate] ~
(__ \ 'time_entry \ 'hours).writeNullable[Double] ~
(__ \ 'time_entry \ 'activity_id).writeNullable[Long] ~
(__ \ 'time_entry \ 'comments).writeNullable[String] ~
(__ \ 'time_entry \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
implicit val timeEntryUpdateForIssueWrites = (
(__ \ 'time_entry \ 'issue_id).writeNullable[Long] ~
(__ \ 'time_entry \ 'spent_on).writeNullable[LocalDate] ~
(__ \ 'time_entry \ 'hours).writeNullable[Double] ~
(__ \ 'time_entry \ 'activity_id).writeNullable[Long] ~
(__ \ 'time_entry \ 'comments).writeNullable[String] ~
(__ \ 'time_entry \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
}
开发者ID:tomingtoming,项目名称:redmine4s,代码行数:58,代码来源:TimeEntryJsonHelper.scala
示例17:
//设置package包名称以及导入依赖的类
package redmine4s.api.json
import org.joda.time.{DateTime, LocalDate}
import play.api.libs.functional.syntax._
import play.api.libs.json.Reads.pure
import play.api.libs.json._
import redmine4s.api.model._
trait VersionJsonHelper extends CustomFieldJsonHelper {
implicit val versionStatusReads: Reads[Status] = JsPath.read[String].map(Status.fromString)
implicit val versionSharingReads: Reads[Sharing] = JsPath.read[String].map(Sharing.fromString)
implicit val versionStatusWrites: Writes[Status] = JsPath.write[String].contramap(_.toString)
implicit val versionSharingWrites: Writes[Sharing] = JsPath.write[String].contramap(_.toString)
implicit val versionReads: Reads[Version] = (
(__ \ 'id).read[Long] ~
(__ \ 'project).read[(Long, String)] ~
(__ \ 'name).read[String] ~
(__ \ 'description).read[String] ~
(__ \ 'due_date).readNullable[LocalDate](dateReads) ~
(__ \ 'status).read[Status] ~
(__ \ 'sharing).read[Sharing] ~
(__ \ 'created_on).read[DateTime](timeReads) ~
(__ \ 'updated_on).read[DateTime](timeReads) ~
((__ \ 'custom_fields).read[Seq[CustomFieldValue]] or pure(Seq.empty[CustomFieldValue]))
) { (id: Long, project: (Long, String), name: String, description: String, dueDate: Option[LocalDate], status: Status, sharing: Sharing, createdOn: DateTime, updatedOn: DateTime, customField: Seq[CustomFieldValue]) =>
Version(id, project, name, description, dueDate, status, sharing, createdOn, updatedOn, customField, null)
}
implicit val versionCreateWrites = (
(__ \ 'version \ 'name).write[String] ~
(__ \ 'version \ 'status).writeNullable[Status] ~
(__ \ 'version \ 'sharing).writeNullable[Sharing] ~
(__ \ 'version \ 'due_date).writeNullable[LocalDate](dateWrites) ~
(__ \ 'version \ 'description).writeNullable[String] ~
(__ \ 'version \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
implicit val versionUpdateWrites = (
(__ \ 'version \ 'name).writeNullable[String] ~
(__ \ 'version \ 'status).writeNullable[Status] ~
(__ \ 'version \ 'sharing).writeNullable[Sharing] ~
(__ \ 'version \ 'due_date).writeNullable[LocalDate](dateWrites) ~
(__ \ 'version \ 'description).writeNullable[String] ~
(__ \ 'version \ 'custom_fields).writeNullable[Seq[(Long, String)]]
).tupled
}
开发者ID:tomingtoming,项目名称:redmine4s,代码行数:45,代码来源:VersionJsonHelper.scala
示例18:
//设置package包名称以及导入依赖的类
package redmine4s.api.json
import org.joda.time.{DateTime, LocalDate}
import play.api.libs.functional.syntax._
import play.api.libs.json._
trait BaseJsonHelper {
val dateReads: Reads[LocalDate] = Reads.jodaLocalDateReads("yyyy-MM-dd")
val timeReads: Reads[DateTime] = Reads.jodaDateReads("yyyy-MM-dd'T'HH:mm:ssZ")
val dateWrites: Writes[LocalDate] = JsPath.write[String].contramap(_.toString)
val timeWrites: Writes[DateTime] = JsPath.write[String].contramap(_.toString)
implicit val idNameReads: Reads[(Long, String)] = (
(__ \ 'id).read[Long] and (__ \ 'name).read[String]
) { (id, name) => (id, name) }
implicit val idValueWrites: Writes[(Long, String)] = (
(__ \ 'id).write[Long] ~ (__ \ 'value).write[String]
).tupled
}
开发者ID:tomingtoming,项目名称:redmine4s,代码行数:19,代码来源:BaseJsonHelper.scala
示例19: ReactiveMongoFormats
//设置package包名称以及导入依赖的类
package util
import org.joda.time.{DateTime, DateTimeZone, LocalDate, LocalDateTime}
import play.api.libs.json._
import reactivemongo.bson.BSONObjectID
object ReactiveMongoFormats extends ReactiveMongoFormats
trait ReactiveMongoFormats {
implicit val localDateRead: Reads[LocalDate] =
(__ \ "$date").read[Long].map { date => new LocalDate(date, DateTimeZone.UTC) }
implicit val localDateWrite: Writes[LocalDate] = new Writes[LocalDate] {
def writes(localDate: LocalDate): JsValue = Json.obj(
"$date" -> localDate.toDateTimeAtStartOfDay(DateTimeZone.UTC).getMillis
)
}
implicit val localDateTimeRead: Reads[LocalDateTime] =
(__ \ "$date").read[Long].map { dateTime => new LocalDateTime(dateTime, DateTimeZone.UTC) }
implicit val localDateTimeWrite: Writes[LocalDateTime] = new Writes[LocalDateTime] {
def writes(dateTime: LocalDateTime): JsValue = JsNumber(
dateTime.toDateTime(DateTimeZone.UTC).getMillis
)
}
implicit val dateTimeRead: Reads[DateTime] =
(__ \ "$date").read[Long].map { dateTime =>
new DateTime(dateTime, DateTimeZone.UTC)
}
implicit val dateTimeWrite: Writes[DateTime] = new Writes[DateTime] {
def writes(dateTime: DateTime): JsValue = Json.obj(
"$date" -> dateTime.getMillis
)
}
implicit val objectIdRead: Reads[BSONObjectID] =
(__ \ "$oid").read[String].map { oid =>
BSONObjectID(oid)
}
implicit val objectIdWrite: Writes[BSONObjectID] = new Writes[BSONObjectID] {
def writes(objectId: BSONObjectID): JsValue = JsString(
objectId.stringify
)
}
implicit val objectIdFormats = Format(objectIdRead, objectIdWrite)
implicit val dateTimeFormats = Format(dateTimeRead, dateTimeWrite)
implicit val localDateFormats = Format(localDateRead, localDateWrite)
implicit val localDateTimeFormats = Format(localDateTimeRead, localDateTimeWrite)
}
开发者ID:dturbay,项目名称:memo-rest,代码行数:61,代码来源:ReactiveMongoFormats.scala
示例20: toDate
//设置package包名称以及导入依赖的类
package util
import org.joda.time.LocalDate
import org.joda.time.format.DateTimeFormat
import skinny.logging.Logger
def toDate(org: String): Option[LocalDate] = {
if (org.isEmpty) None else {
val str = org.replaceAll("/", "").replaceAll("-", "")
try {
Option(DateTimeFormat.forPattern("yyyyMMdd").parseLocalDate(str))
} catch {
case e: Throwable =>
logger.error(e.getMessage, e)
None
}
}
}
}
开发者ID:nemuzuka,项目名称:vss-kanban,代码行数:21,代码来源:ConvertUtil.scala
注:本文中的org.joda.time.LocalDate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论