本文整理汇总了Scala中org.joda.time.Interval类的典型用法代码示例。如果您正苦于以下问题:Scala Interval类的具体用法?Scala Interval怎么用?Scala Interval使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Interval类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: conf
//设置package包名称以及导入依赖的类
package frontend
import controllers.routes
import jp.t2v.lab.play2.auth._
import org.joda.time.{DateTime, Interval}
import play.api.data.Form
import play.api.data.Forms._
import play.api.mvc.Results._
import play.api.mvc._
import scala.collection.mutable
import scala.concurrent.{Future, ExecutionContext}
import scala.reflect.ClassTag
trait AuthorizationConfig extends AuthConfig {
mixin: { def conf: play.api.Configuration } =>
override type Id = String
override type User = frontend.Account
override type Authority = frontend.Permission
override val idTag: ClassTag[Id] = scala.reflect.classTag[Id]
override val sessionTimeoutInSeconds = tokenMaxAge
lazy val intervals: mutable.LinkedHashMap[Interval, String] = loadStages(conf.getObjectList("stages"))
override def resolveUser(id: Id)(implicit ctx: ExecutionContext): Future[Option[User]] = {
val fields = id.split(",")
val id0 = fields(0)
val login = fields(1)
val password = fields(2)
val permission = fields(3)
val token = fields(4)
Future.successful(Option(Account(id0.toInt, login, password, permission, token)))
}
cookieName = conf.getString("http-session.header").getOrElse("AUTH_SESS_ID"),
cookieSecureOption = play.api.Play.isProd(play.api.Play.current),
cookieMaxAge = Some(sessionTimeoutInSeconds)
)
def authenticationErrorForm(errorMessage: String) = Form {
mapping(("login" -> nonEmptyText), ("password" -> nonEmptyText))({(l,r) => None: Option[frontend.Account]})(_ => None)
.verifying("Invalid login or password", result => result.isDefined)
}.withGlobalError(errorMessage)
def loginUrl: String = conf.getString("url.login").get
//should be equal to backend Max-Age
def tokenMaxAge: Int = conf.getInt("http-session.max-age").get
}
示例2: MonthCalendar
//设置package包名称以及导入依赖的类
package kippercalendar
import kippercalendar.Calendar._
import kippercalendar.Clock._
import net.liftweb.http.SHtml
import net.liftweb.http.js.JsCmds._
import org.joda.time.Interval
import scala.xml.NodeSeq
object MonthCalendar {
val previousMonthButtonId = "previousMonthButtonId"
val nextMonthButtonId = "nextMonthButtonId"
val monthTitleId = "monthTitleId"
def apply(monthInterval: Interval): NodeSeq = {
<h3>
<span id={monthTitleId}>{title(monthInterval)}</span>
{monthDayNavigationButtons(monthInterval, monthActive = true)}
</h3> ++
previousMonthButton(monthInterval) ++
nextMonthButton(monthInterval)
}
def title(monthInterval: Interval) = monthInterval.getStart.getYear.toString + " " + monthFull(monthInterval.getStart)
private def previousMonthButton(monthInterval: Interval) =
SHtml.ajaxButton("< previous month", () ? SetHtml(kipperCalendarContainerId, MonthCalendar(new Interval(monthInterval.getStart.minusMonths(1), monthInterval.getEnd.minusMonths(1)))), "id" ? previousMonthButtonId, "class" ? "col-lg-2 btn btn-primary")
private def nextMonthButton(monthInterval: Interval) =
SHtml.ajaxButton("next month >", () ? SetHtml(kipperCalendarContainerId, MonthCalendar(new Interval(monthInterval.getStart.plusMonths(1), monthInterval.getEnd.plusMonths(1)))), "id" ? nextMonthButtonId, "class" ? "col-lg-2 col-lg-offset-8 btn btn-primary")
}
示例3: Calendar
//设置package包名称以及导入依赖的类
package kippercalendar
import net.liftweb.http.SHtml
import net.liftweb.http.js.JsCmds
import net.liftweb.http.js.JsCmds.SetHtml
import org.joda.time.{DateTime, Interval}
object Calendar {
val kipperCalendarContainerId = "kipperCalendarContainerId"
val dayViewButtonId = "showDayViewButtonId"
val monthViewButtonId = "showMonthViewButtonId"
def apply(initialDateTime: DateTime) =
<form class="lift:form.ajax">
<div id={kipperCalendarContainerId}>
{MonthCalendar(new Interval(new DateTime().withTimeAtStartOfDay(), new DateTime().withTimeAtStartOfDay().plusDays(1)))}
</div>
</form>
def monthDayNavigationButtons(intervalDisplayed: Interval, monthActive: Boolean = true) = {
val dayActive = !monthActive
<div class="btn-group pull-right">
{SHtml.ajaxButton("Day", () ? if (dayActive) JsCmds.Noop else SetHtml(kipperCalendarContainerId, DayCalendar(new Interval(intervalDisplayed.getStart.withDayOfMonth(new DateTime().getDayOfMonth), intervalDisplayed.getStart.withDayOfMonth(new DateTime().getDayOfMonth).plusDays(1)))), "id" ? dayViewButtonId, "class" ? { if (dayActive) "btn btn-default active" else "btn btn-default"})}
{SHtml.ajaxButton("Month", () ? if (monthActive) JsCmds.Noop else SetHtml(kipperCalendarContainerId, MonthCalendar(new Interval(intervalDisplayed.getStart.withDayOfMonth(1), intervalDisplayed.getStart.withDayOfMonth(1).plusMonths(1).minusDays(1)))), "id" ? monthViewButtonId, "class" ? { if (monthActive) "btn btn-default active" else "btn btn-default"})}
</div>
}
}
示例4: DayCalendar
//设置package包名称以及导入依赖的类
package kippercalendar
import kippercalendar.Calendar._
import kippercalendar.Clock._
import net.liftweb.http.SHtml
import net.liftweb.http.js.JsCmds.SetHtml
import org.joda.time.Interval
import scala.xml.NodeSeq
object DayCalendar {
val previousDayButtonId = "previousDayButtonId"
val nextDayButtonId = "nextDayButtonId"
val dayTitleId = "dayTitleId"
def apply(day: Interval): NodeSeq =
<h3>
<span id={dayTitleId}>{title(day)}</span>
{monthDayNavigationButtons(day, monthActive = false)}
</h3> ++
previousDayButton(day) ++
nextDayButton(day)
def title(day: Interval) = dayOfTheWeekAndMonth(day.getStart) + " " + monthFull(day.getStart) + " " + day.getStart.getYear
private def previousDayButton(monthInterval: Interval) =
SHtml.ajaxButton("< previous day", () ? SetHtml(kipperCalendarContainerId, DayCalendar(new Interval(monthInterval.getStart.minusDays(1), monthInterval.getEnd.minusDays(1)))), "id" ? previousDayButtonId, "class" ? "col-lg-2 btn btn-primary")
private def nextDayButton(monthInterval: Interval) =
SHtml.ajaxButton("next day >", () ? SetHtml(kipperCalendarContainerId, DayCalendar(new Interval(monthInterval.getStart.plusDays(1), monthInterval.getEnd.plusDays(1)))), "id" ? nextDayButtonId, "class" ? "col-lg-2 col-lg-offset-8 btn btn-primary")
}
示例5: CalendarDriver
//设置package包名称以及导入依赖的类
package kippercalendar.acceptance.driver
import im.mange.driveby.Id
import im.mange.driveby.browser.Browser
import im.mange.driveby.conditions.{AttributeContains, TextEquals}
import kippercalendar.{DayCalendar, MonthCalendar}
import kippercalendar.acceptance.context.Context
import org.joda.time.{Interval, DateTime}
case class CalendarDriver(context: Context, browser: Browser) extends Navigable {
import kippercalendar.MonthCalendar._
import kippercalendar.DayCalendar._
import kippercalendar.Calendar._
def clickDisplayDayCalendar() = click(dayViewButtonId)
def clickDisplayMonthCalendar() = click(monthViewButtonId)
def clickPreviousMonth() = click(previousMonthButtonId)
def clickNextMonth() = click(nextMonthButtonId)
def clickPreviousDay() = click(previousDayButtonId)
def clickNextDay() = click(nextDayButtonId)
def assertMonthTitle(date: DateTime) = browser.assert(TextEquals(Id(monthTitleId), MonthCalendar.title(new Interval(date, date.plusMonths(1)))))
def assertDayTitle(date: DateTime) = browser.assert(TextEquals(Id(dayTitleId), DayCalendar.title(new Interval(date, date.plusMonths(1)))))
def assertMonthActive = browser.assert(AttributeContains(Id(monthViewButtonId), "class", "active"))
def assertDayActive = browser.assert(AttributeContains(Id(dayViewButtonId), "class", "active"))
def assertPreviousMonthButtonDisplayed = browser.assert(TextEquals(Id(previousMonthButtonId), "< previous month"))
def assertNextMonthButtonDisplayed = browser.assert(TextEquals(Id(nextMonthButtonId), "next month >"))
def assertPreviousDayButtonDisplayed = browser.assert(TextEquals(Id(previousDayButtonId), "< previous day"))
def assertNextDayButtonDisplayed = browser.assert(TextEquals(Id(nextDayButtonId), "next day >"))
}
示例6: Main
//设置package包名称以及导入依赖的类
package com.puzzle.addressbook
import com.github.nscala_time.time.OrderingImplicits._
import org.joda.time.Interval
object Main {
val records = Resource("AddressBook").flatMap(AddressRecord.fromString)
def main(args: Array[String]): Unit = {
println("Run: sbt test")
}
def findByGender(gender: Gender): Int = {
records.count(_.gender == gender)
}
def findByAge(age: Age): AddressRecord = {
age match {
case Oldest => records.minBy(_.birthday)
case Youngest => records.maxBy(_.birthday)
}
}
def getDaysDifference(olderName: String, youngerName: String): Option[Long] = {
for {
older <- records.find(_.firstName == olderName)
younger <- records.find(_.firstName == youngerName)
} yield {
new Interval(older.birthday, younger.birthday).toDuration.getStandardDays
}
}
}
示例7: PerformanceReporting
//设置package包名称以及导入依赖的类
package highperfscala.clientreports.views
import org.joda.time.{Duration, Instant, Interval}
object PerformanceReporting {
def trend(
now: () => Instant,
findOrders: (Interval, Ticker) => List[Order],
findExecutions: (Interval, Ticker) => List[Execution],
request: GenerateTradingPerformanceTrend): List[TradingPerformanceTrend] = {
def periodPnL(
duration: Duration): Map[Ticker, PeriodPnL] = {
val currentTime = now()
val interval = new Interval(currentTime.minus(duration), currentTime)
(for {
ticker <- request.tickers
orders = findOrders(interval, ticker)
executions = findExecutions(interval, ticker)
idToExecPrice = executions.groupBy(_.id).mapValues(es =>
Price.average(es.map(_.price)))
signedExecutionPrices = for {
o <- orders
if o.clientId == request.clientId
price <- idToExecPrice.get(o.id).map(p => o match {
case _: BuyOrder => Price(p.value * -1)
case _: SellOrder => p
}).toList
} yield price
trend = signedExecutionPrices.foldLeft(PnL.zero) {
case (pnl, p) => PnL(pnl.value + p.value)
} match {
case p if p.value >= PnL.zero.value => PeriodPositive
case _ => PeriodNegative
}
} yield ticker -> trend).toMap
}
val tickerToLastHour = periodPnL(Duration.standardHours(1)).mapValues {
case PeriodPositive => LastHourPositive
case PeriodNegative => LastHourNegative
}
val tickerToLastDay = periodPnL(Duration.standardDays(1)).mapValues {
case PeriodPositive => LastDayPositive
case PeriodNegative => LastDayNegative
}
val tickerToLastSevenDays = periodPnL(Duration.standardDays(7)).mapValues {
case PeriodPositive => LastSevenDayPositive
case PeriodNegative => LastSevenDayNegative
}
tickerToLastHour.zip(tickerToLastDay).zip(tickerToLastSevenDays).map({
case (((t, lastHour), (_, lastDay)), (_, lastSevenDays)) =>
TradingPerformanceTrend(t, lastHour, lastDay, lastSevenDays)
}).toList
}
}
开发者ID:PacktPublishing,项目名称:Scala-High-Performance-Programming,代码行数:58,代码来源:PerformanceReporting.scala
示例8: ViewPerformanceReporting
//设置package包名称以及导入依赖的类
package highperfscala.clientreports.views
import org.joda.time.{Duration, Instant, Interval}
object ViewPerformanceReporting {
def trend(
now: () => Instant,
findOrders: (Interval, Ticker) => List[Order],
findExecutions: (Interval, Ticker) => List[Execution],
request: GenerateTradingPerformanceTrend): List[TradingPerformanceTrend] = {
def periodPnL(
duration: Duration): Map[Ticker, PeriodPnL] = {
val currentTime = now()
val interval = new Interval(currentTime.minus(duration), currentTime)
(for {
ticker <- request.tickers
orders = findOrders(interval, ticker)
executions = findExecutions(interval, ticker)
idToExecPrice = executions.groupBy(_.id).mapValues(es =>
Price.average(es.map(_.price)))
signedExecutionPrices = for {
o <- orders.view
if o.clientId == request.clientId
price <- idToExecPrice.get(o.id).map(p => o match {
case _: BuyOrder => Price(p.value * -1)
case _: SellOrder => p
}).toList
} yield price
trend = signedExecutionPrices.foldLeft(PnL.zero) {
case (pnl, p) => PnL(pnl.value + p.value)
} match {
case p if p.value >= PnL.zero.value => PeriodPositive
case _ => PeriodNegative
}
} yield ticker -> trend).toMap
}
val tickerToLastHour = periodPnL(Duration.standardHours(1)).mapValues {
case PeriodPositive => LastHourPositive
case PeriodNegative => LastHourNegative
}
val tickerToLastDay = periodPnL(Duration.standardDays(1)).mapValues {
case PeriodPositive => LastDayPositive
case PeriodNegative => LastDayNegative
}
val tickerToLastSevenDays = periodPnL(Duration.standardDays(7)).mapValues {
case PeriodPositive => LastSevenDayPositive
case PeriodNegative => LastSevenDayNegative
}
tickerToLastHour.zip(tickerToLastDay).zip(tickerToLastSevenDays).map({
case (((t, lastHour), (_, lastDay)), (_, lastSevenDays)) =>
TradingPerformanceTrend(t, lastHour, lastDay, lastSevenDays)
}).toList
}
}
开发者ID:PacktPublishing,项目名称:Scala-High-Performance-Programming,代码行数:60,代码来源:ViewPerformanceReporting.scala