本文整理汇总了Scala中org.joda.time.LocalDate类的典型用法代码示例。如果您正苦于以下问题:Scala LocalDate类的具体用法?Scala LocalDate怎么用?Scala LocalDate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalDate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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]
}
示例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)
}
示例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)
}
}
示例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)
}
}
示例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")))
}
}
}
示例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
}
}
}
示例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]
}
示例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
}
}
}
示例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
}
}
}
示例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")))
}
示例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"
)
})
}
示例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")
}
}
示例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())
}
}
示例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
)
}
}
示例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)
}