本文整理汇总了Scala中org.joda.time.LocalDateTime类的典型用法代码示例。如果您正苦于以下问题:Scala LocalDateTime类的具体用法?Scala LocalDateTime怎么用?Scala LocalDateTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了LocalDateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: AuthenticatorQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import jdub.async.{ Statement, Row, FlatSingleRowQuery }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
object AuthenticatorQueries extends BaseQueries[CookieAuthenticator] {
override protected val tableName = "session_info"
override protected val columns = Seq("id", "provider", "key", "last_used", "expiration", "fingerprint", "created")
override protected val searchColumns = Seq("id::text", "key")
val insert = Insert
val getById = GetById
val removeById = RemoveById
case class FindSessionInfoByLoginInfo(l: LoginInfo) extends FlatSingleRowQuery[CookieAuthenticator] {
override val sql = getSql(Some("provider = ? and key = ?"))
override val values = Seq(l.providerID, l.providerKey)
override def flatMap(row: Row) = Some(fromRow(row))
}
case class UpdateAuthenticator(ca: CookieAuthenticator) extends Statement {
override val sql = updateSql(Seq("provider", "key", "last_used", "expiration", "fingerprint"))
override val values = Seq(
ca.loginInfo.providerID,
ca.loginInfo.providerKey,
ca.lastUsedDateTime.toLocalDateTime,
ca.expirationDateTime.toLocalDateTime,
ca.fingerprint,
ca.id
)
}
override protected def fromRow(row: Row) = {
val id = row.as[String]("id")
val provider = row.as[String]("provider")
val key = row.as[String]("key")
val lastUsed = row.as[LocalDateTime]("last_used").toDateTime
val expiration = row.as[LocalDateTime]("expiration").toDateTime
val idleTimeout = None
val cookieMaxAge = None
val fingerprint = row.asOpt[String]("fingerprint")
CookieAuthenticator(id, LoginInfo(provider, key), lastUsed, expiration, idleTimeout, cookieMaxAge, fingerprint)
}
override protected def toDataSeq(ca: CookieAuthenticator) = Seq(
ca.id,
ca.loginInfo.providerID,
ca.loginInfo.providerKey,
ca.lastUsedDateTime.toLocalDateTime,
ca.expirationDateTime.toLocalDateTime,
ca.fingerprint,
new LocalDateTime()
)
}
示例2: OAuth1InfoQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth1Info
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
object OAuth1InfoQueries extends BaseQueries[OAuth1Info] {
override protected val tableName = "oauth1_info"
override protected val columns = Seq("provider", "key", "token", "secret", "created")
override protected val idColumns = Seq("provider", "key")
override protected val searchColumns = Seq("key", "token")
val getById = GetById
val removeById = RemoveById
case class CreateOAuth1Info(l: LoginInfo, o: OAuth1Info) extends Statement {
override val sql = insertSql
override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
}
case class UpdateOAuth1Info(l: LoginInfo, o: OAuth1Info) extends Statement {
override val sql = s"update $tableName set token = ?, secret = ?, created = ? where provider = ? and key = ?"
override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
}
override protected def fromRow(row: Row) = {
val token = row.as[String]("token")
val secret = row.as[String]("secret")
OAuth1Info(token, secret)
}
override protected def toDataSeq(o: OAuth1Info) = Seq(o.token, o.secret, new LocalDateTime())
}
示例3: ProfileQueries
//设置package包名称以及导入依赖的类
package models.queries
import java.util.UUID
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.CommonSocialProfile
import jdub.async.queries.BaseQueries
import jdub.async.{ Query, Row, FlatSingleRowQuery }
import org.joda.time.LocalDateTime
object ProfileQueries extends BaseQueries[CommonSocialProfile] {
override protected val tableName = "user_profiles"
override protected val columns = Seq("provider", "key", "email", "first_name", "last_name", "full_name", "avatar_url", "created")
override protected val searchColumns = Seq("key", "email", "first_name", "last_name", "full_name")
val insert = Insert
val remove = RemoveById
case class FindProfile(provider: String, key: String) extends FlatSingleRowQuery[CommonSocialProfile] {
override val sql = getSql(Some("provider = ? and key = ?"))
override val values = Seq(provider, key)
override def flatMap(row: Row) = Some(fromRow(row))
}
case class FindProfilesByUser(id: UUID) extends Query[List[CommonSocialProfile]] {
override val sql = s"select ${columns.mkString(", ")} from $tableName p " +
"where (p.provider || ':' || p.key) in (select unnest(profiles) from users where users.id = ?)"
override val values = Seq(id)
override def reduce(rows: Iterator[Row]) = rows.map(fromRow).toList
}
override protected def fromRow(row: Row) = {
val loginInfo = LoginInfo(
providerID = row.as[String]("provider"),
providerKey = row.as[String]("key")
)
val firstName = row.asOpt[String]("first_name")
val lastName = row.asOpt[String]("last_name")
val fullName = row.asOpt[String]("full_name")
val email = row.asOpt[String]("email")
val avatarUrl = row.asOpt[String]("avatar_url")
CommonSocialProfile(loginInfo, firstName, lastName, fullName, email, avatarUrl)
}
override protected def toDataSeq(p: CommonSocialProfile) = Seq(
p.loginInfo.providerID, p.loginInfo.providerKey, p.email, p.firstName, p.lastName, p.fullName, p.avatarURL, new LocalDateTime()
)
}
示例4: OpenIdInfoQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OpenIDInfo
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
import play.api.libs.json.{ JsValue, Json }
object OpenIdInfoQueries extends BaseQueries[OpenIDInfo] {
override protected val tableName = "openid_info"
override protected val columns = Seq("provider", "key", "id", "attributes", "created")
override protected val idColumns = Seq("provider", "key")
override protected val searchColumns = Seq("key")
val getById = GetById
val removeById = RemoveById
case class CreateOpenIdInfo(l: LoginInfo, o: OpenIDInfo) extends Statement {
override val sql = insertSql
override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
}
case class UpdateOpenIdInfo(l: LoginInfo, o: OpenIDInfo) extends Statement {
override val sql = s"update $tableName set id = ?, attributes = ?, created = ? where provider = ? and key = ?"
val attributes = Json.prettyPrint(Json.toJson(o.attributes))
override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
}
override protected def fromRow(row: Row) = {
val id = row.as[String]("id")
val attributesString = row.as[String]("attributes")
val attributes = Json.parse(attributesString).as[Map[String, JsValue]].map(x => x._1 -> x._2.as[String])
OpenIDInfo(id, attributes)
}
override protected def toDataSeq(o: OpenIDInfo) = {
val attributes = Json.prettyPrint(Json.toJson(o.attributes))
Seq(o.id, attributes, new LocalDateTime())
}
}
示例5: PasswordInfoQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.api.util.PasswordInfo
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
object PasswordInfoQueries extends BaseQueries[PasswordInfo] {
override protected val tableName = "password_info"
override protected val columns = Seq("provider", "key", "hasher", "password", "salt", "created")
override protected def idColumns = Seq("provider", "key")
override protected val searchColumns = Seq("key")
val getById = GetById
val removeById = RemoveById
case class CreatePasswordInfo(l: LoginInfo, p: PasswordInfo) extends Statement {
override val sql = insertSql
override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(p)
}
case class UpdatePasswordInfo(l: LoginInfo, p: PasswordInfo) extends Statement {
override val sql = s"update $tableName set hasher = ?, password = ?, salt = ?, created = ? where provider = ? and key = ?"
override val values = toDataSeq(p) ++ Seq(l.providerID, l.providerKey)
}
override protected def fromRow(row: Row) = PasswordInfo(
hasher = row.as[String]("hasher"),
password = row.as[String]("password"),
salt = row.asOpt[String]("salt")
)
override protected def toDataSeq(p: PasswordInfo) = Seq(p.hasher, p.password, p.salt, new LocalDateTime())
}
示例6: OAuth2InfoQueries
//设置package包名称以及导入依赖的类
package models.queries
import com.mohiva.play.silhouette.api.LoginInfo
import com.mohiva.play.silhouette.impl.providers.OAuth2Info
import jdub.async.{ Row, Statement }
import jdub.async.queries.BaseQueries
import org.joda.time.LocalDateTime
import play.api.libs.json.{ JsValue, Json }
object OAuth2InfoQueries extends BaseQueries[OAuth2Info] {
override protected val tableName = "oauth2_info"
override protected val columns = Seq("provider", "key", "access_token", "token_type", "expires_in", "refresh_token", "params", "created")
override protected val idColumns = Seq("provider", "key")
override protected val searchColumns = Seq("key", "access_token")
val getById = GetById
val removeById = RemoveById
case class CreateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
override val sql = insertSql
override val values = Seq(l.providerID, l.providerKey) ++ toDataSeq(o)
}
case class UpdateOAuth2Info(l: LoginInfo, o: OAuth2Info) extends Statement {
override val sql = {
s"update $tableName set access_token = ?, token_type = ?, expires_in = ?, refresh_token = ?, params = ?, created = ? where provider = ? and key = ?"
}
override val values = toDataSeq(o) ++ Seq(l.providerID, l.providerKey)
}
override protected def fromRow(row: Row) = {
val params = row.asOpt[String]("params").map { p =>
Json.parse(p).as[Map[String, JsValue]].map(x => x._1 -> x._2.as[String])
}
OAuth2Info(
accessToken = row.as[String]("access_token"),
tokenType = row.asOpt[String]("token_type"),
expiresIn = row.asOpt[Int]("expires_in"),
refreshToken = row.asOpt[String]("refresh_token"),
params = params
)
}
override protected def toDataSeq(o: OAuth2Info) = {
val params = o.params.map(p => Json.prettyPrint(Json.toJson(p)))
Seq(o.accessToken, o.tokenType, o.expiresIn, o.refreshToken, params, new LocalDateTime())
}
}
示例7: User
//设置package包名称以及导入依赖的类
package models.user
import java.util.UUID
import com.mohiva.play.silhouette.api.{ Identity, LoginInfo }
import org.joda.time.LocalDateTime
case class User(
id: UUID,
username: Option[String],
profiles: Seq[LoginInfo],
roles: Set[Role] = Set(Role.User),
created: LocalDateTime
) extends Identity {
def isGuest = profiles.isEmpty
def isAdmin = roles.contains(models.user.Role.Admin)
}
示例8: BaseController
//设置package包名称以及导入依赖的类
package controllers
import java.util.UUID
import org.joda.time.LocalDateTime
import play.api.i18n.I18nSupport
import services.user.AuthenticationEnvironment
import com.mohiva.play.silhouette.api._
import com.mohiva.play.silhouette.impl.authenticators.CookieAuthenticator
import models.user.{ Role, User }
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc.{ AnyContent, Result }
import scala.concurrent.Future
abstract class BaseController() extends Silhouette[User, CookieAuthenticator] with I18nSupport {
def env: AuthenticationEnvironment
def withAdminSession(block: (SecuredRequest[AnyContent]) => Future[Result]) = SecuredAction.async { implicit request =>
if (request.identity.roles.contains(Role.Admin)) {
block(request)
} else {
Future.successful(NotFound("404 Not Found"))
}
}
def withSession(block: (SecuredRequest[AnyContent]) => Future[Result]) = UserAwareAction.async { implicit request =>
val response = request.identity match {
case Some(user) =>
val secured = SecuredRequest(user, request.authenticator.getOrElse(throw new IllegalStateException()), request)
block(secured).map { r =>
r
}
case None =>
val user = User(
id = UUID.randomUUID(),
username = None,
profiles = Nil,
created = new LocalDateTime()
)
for {
user <- env.userService.save(user)
authenticator <- env.authenticatorService.create(LoginInfo("anonymous", user.id.toString))
value <- env.authenticatorService.init(authenticator)
result <- block(SecuredRequest(user, authenticator, request))
authedResponse <- env.authenticatorService.embed(value, result)
} yield {
env.eventBus.publish(SignUpEvent(user, request, request2Messages))
env.eventBus.publish(LoginEvent(user, request, request2Messages))
authedResponse
}
}
response
}
}
示例9: User
//设置package包名称以及导入依赖的类
package models
import org.joda.time.LocalDateTime
import org.mindrot.jbcrypt.BCrypt
class User private (
val id: Long,
val name: String,
val email: String,
val passwordDigest: String,
val createdAt: LocalDateTime,
val updatedAt: LocalDateTime
) {
def verifyPassword(password: String): Boolean = {
BCrypt.checkpw(password, passwordDigest)
}
}
object User {
def apply(
id: Long,
name: String,
email: String,
passwordDigest: String,
createdAt: LocalDateTime = LocalDateTime.now,
updatedAt: LocalDateTime = LocalDateTime.now
): User = {
val validName = name match {
case n if n.length > 50 => throw new Exception
case _ => name
}
val validEmail = email match {
case e if e.length > 255 => throw new Exception
case e if !e.matches("""\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z""") => throw new Exception
case _ => email
}
val validPass = passwordDigest match {
case pass if pass.length < 6 => throw new Exception
case _ => passwordDigest
}
new User(id = id, name = validName, email = validEmail, passwordDigest = validPass, createdAt = createdAt, updatedAt = updatedAt)
}
}
示例10: ChargeSessionsService
//设置package包名称以及导入依赖的类
package services.business
import models.CurrentTariff
import org.joda.time.{Hours, LocalDateTime}
import org.joda.time.format.ISODateTimeFormat
object ChargeSessionsService {
def calculateTotalFee(transaction: Map[String,AnyRef], tariff: CurrentTariff) = {
val volume: Double = transaction.get("volume") match {
case Some(v) if v.isInstanceOf[Double] => v.asInstanceOf[Double]
case Some(v) if v.isInstanceOf[String] => v.asInstanceOf[String].toDouble
case _ => 0d
}
val startTime = parseDate(transaction, "startTime")
val endTime = parseDate(transaction, "endTime")
val numHours = Hours.hoursBetween(startTime, endTime).getHours
tariff.startFee + (numHours * tariff.hourlyFee) + (volume * tariff.feePerKwh)
}
private def parseDate(transaction: Map[String,AnyRef], field: String) = {
transaction.get(field).asInstanceOf[Option[String]] match {
case Some(dateTime) => ISODateTimeFormat.dateTimeParser().parseLocalDateTime(dateTime)
case _ => new LocalDateTime()
}
}
}
示例11: 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]
}
示例12: JsonValueImplicits
//设置package包名称以及导入依赖的类
package core.database
import org.mongodb.scala.bson.collection.immutable.Document
import play.api.libs.json.JsValue
import play.api.libs.json.Json
import play.api.libs.json.Writes
import org.joda.time.LocalDateTime
import play.api.libs.json.JsString
import org.joda.time.format.DateTimeFormat
object JsonValueImplicits {
implicit def jsValueToString(jsValue: JsValue): String = {
jsValue.toString()
}
implicit def documentToJsValue(document: Document): JsValue = {
Json.parse(document.toJson())
}
implicit val jodaDateWrites: Writes[LocalDateTime] = new Writes[LocalDateTime] {
def writes(date: LocalDateTime): JsValue = {
val fmt = DateTimeFormat.forPattern("HH:mm:ss");
JsString(date.toString(fmt))
}
}
implicit def localDateTimeToJsValue(localDateTime:LocalDateTime): JsValue = {
jodaDateWrites.writes(localDateTime)
}
}
示例13: 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)
}
示例14: MemoController
//设置package包名称以及导入依赖的类
package controllers
import javax.inject.{Inject, Singleton}
import model.Memo
import org.joda.time.LocalDateTime
import play.api.libs.json.Json
import play.api.mvc.{BodyParsers, Action, Controller}
import play.modules.reactivemongo.{MongoController, ReactiveMongoApi, ReactiveMongoComponents}
import reactivemongo.bson.BSONObjectID
import scala.concurrent.{Future, ExecutionContext}
@Singleton
class MemoController @Inject()(val reactiveMongoApi: ReactiveMongoApi)
(implicit ec: ExecutionContext)
extends Controller with MongoController with ReactiveMongoComponents {
def memoRepo = new backend.MemoMongoRepo(reactiveMongoApi)
//import reactivemongo.play.json._
import util.ReactiveMongoFormats._
implicit val memoFormat = Json.format[Memo]
def list = Action.async {
val memos: Future[List[Memo]] = memoRepo.find()
memos.map(list => Ok(Json.toJson(list)))
}
def post = Action.async(BodyParsers.parse.json) { implicit request =>
val memo: Memo = Memo(Some(BSONObjectID.generate()),
(request.body \ "text").as[String],
new LocalDateTime((request.body \ "date").as[Long]))
memoRepo.save(memo).map(_ => Created(memo._id.get.stringify))
}
}
示例15: CarSpeedGenerator
//设置package包名称以及导入依赖的类
package actors
import javax.inject.Inject
import akka.actor._
import org.joda.time.LocalDateTime
import scala.util.Random
import services._
object CarSpeedGenerator {
case object Update
}
class CarSpeedGenerator @Inject() (service: DailyCarSpeedService) extends Actor {
import CarSpeedGenerator._
import services.DailyCarSpeedService._
def receive: Receive = {
case Update =>
val speed = Random.nextInt(200)
val date = new LocalDateTime()
service.save(Request(date, speed))
}
}