当前位置: 首页>>代码示例>>Scala>>正文


Scala Days类代码示例

本文整理汇总了Scala中org.joda.time.Days的典型用法代码示例。如果您正苦于以下问题:Scala Days类的具体用法?Scala Days怎么用?Scala Days使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Days类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: IfTag

//设置package包名称以及导入依赖的类
package helpers

import models._
import org.joda.time.format.DateTimeFormat
import org.joda.time.{DateTime, Days}
import org.joda.time.Minutes
import org.joda.time.Hours
import play.api.Play
import play.api.Play.current
import play.api.i18n.Lang
import play.twirl.api.Html
import utils.DateUtils
import utils.m
import play.api.mvc.WrappedRequest

class IfTag(condition: Boolean, content: => Html) extends scala.xml.NodeSeq {

  def theSeq = Nil // just ignore, required by NodeSeq

  override def toString = if (condition) content.toString else ""

  def orElse(failed: => Html) = if (condition) content else failed
}

object CustomTag {

  
  def date2delay(d: DateTime)(implicit request: WrappedRequest[_]): String = {
    val d_minus_seven_days = DateUtils.now.minusDays(7)
    val d_minus_one_days = DateUtils.now.minusDays(1)
    val d_minus_one_hours = DateUtils.now.minusHours(1)
    val now = DateUtils.now

    if (d.isAfterNow) { "" }
    else if (d.isAfter(d_minus_one_hours)) {
      val minutes_delta = Minutes.minutesBetween(d, now)
      m("general.date.delay.minutes", Math.abs(minutes_delta.getMinutes))
    } else if (d.isAfter(d_minus_one_days)) {
      val hours_delta = Hours.hoursBetween(d, now)
      m("general.date.delay.hours", Math.abs(hours_delta.getHours))
    } else if (d.isAfter(d_minus_seven_days.toInstant)) {
      val day_delta = Days.daysBetween(d, now)
      m("general.date.delay.days", Math.abs(day_delta.getDays))
    } else {
      m("general.date.delay.on", date_format(d, Some("MMM")), d.getDayOfMonth)
    }
  }

  def date_format(date: DateTime, format: Option[String] = None)(implicit lang: Lang): String = {
    val pattern = format
      .orElse(Play.configuration.getString(s"date.i18n.date.format.${lang.language}"))
      .getOrElse("dd/MM/yyyy")
    val locale = lang.toLocale

    val formatter = DateTimeFormat.forPattern(pattern).withLocale(locale)
    formatter.print(date)
  }
} 
开发者ID:Driox,项目名称:play-app-seed,代码行数:59,代码来源:CustomTag.scala

示例2: PasswordResetCodeSenderImpl

//设置package包名称以及导入依赖的类
package access.authentication

import access.CodeSender
import access.registration.ActivationCodeGenerator
import com.eigenroute.time.TimeProvider
import com.google.inject.Inject
import entrypoint.AuthenticationAPI
import org.joda.time.Days
import play.api.Configuration
import user.UserMessage

import scala.util.{Random, Success}

class PasswordResetCodeSenderImpl @Inject()(
    authenticationAPI: AuthenticationAPI,
    linkSender: CodeSender,
    timeProvider: TimeProvider,
    configuration: Configuration)
  extends PasswordResetCodeSender {

  val key = configuration.getString(ActivationCodeGenerator.configurationKey).getOrElse("")

  override def send(user: UserMessage, host: String): Unit = {
    authenticationAPI.retrievePasswordResetCode(user.email)
        .filter { passwordResetCodeAndDate =>
          Days.daysBetween(passwordResetCodeAndDate.date.withTimeAtStartOfDay(),
            timeProvider.now().withTimeAtStartOfDay()).getDays <
              configuration.getInt("accessService.passwordResetLinkIsValidForDays").getOrElse(10)
        }
    .fold[Unit] {
      val passwordResetCode = Random.alphanumeric.take(20).mkString
      val hashedPasswordResetCodeWithDashes = ActivationCodeGenerator.generateWithDashes(passwordResetCode, key)
      authenticationAPI.storePasswordResetCode(user.email, passwordResetCode) match {
        case Success(retrievedUser) =>
          linkSender
          .send(retrievedUser, hashedPasswordResetCodeWithDashes, "passwordresetlink.subject", "passwordresetlink.body")
        case _ =>
      }
    } { existingPasswordResetCode =>
      val hashedPasswordResetCodeToSend = ActivationCodeGenerator.generateWithDashes(existingPasswordResetCode.code, key)
      linkSender
      .send(user, hashedPasswordResetCodeToSend, "passwordresetlink.subject", "passwordresetlink.body")
    }

  }

} 
开发者ID:shafiquejamal,项目名称:api-gateway-template,代码行数:48,代码来源:PasswordResetCodeSenderImpl.scala

示例3: Coach

//设置package包名称以及导入依赖的类
package lila.coach

import org.joda.time.{ DateTime, Days }

import lila.user.User

case class Coach(
    _id: Coach.Id, // user ID
    listed: Coach.Listed,
    available: Coach.Available,
    approved: Coach.Approved,
    profile: CoachProfile,
    picturePath: Option[Coach.PicturePath],
    nbReviews: Int,
    createdAt: DateTime,
    updatedAt: DateTime
) {

  def id = _id

  def is(user: User) = id.value == user.id

  def hasPicture = picturePath.isDefined

  def isListed = listed.value && approved.value

  def daysOld = Days.daysBetween(createdAt, DateTime.now).getDays
}

object Coach {

  def make(user: User) = Coach(
    _id = Id(user.id),
    listed = Listed(false),
    available = Available(true),
    approved = Approved(true),
    profile = CoachProfile(),
    picturePath = None,
    nbReviews = 0,
    createdAt = DateTime.now,
    updatedAt = DateTime.now
  )

  case class WithUser(coach: Coach, user: User)

  case class Id(value: String) extends AnyVal with StringValue
  case class Listed(value: Boolean) extends AnyVal
  case class Available(value: Boolean) extends AnyVal
  case class Approved(value: Boolean) extends AnyVal
  case class PicturePath(value: String) extends AnyVal with StringValue
} 
开发者ID:DrNixx,项目名称:line,代码行数:52,代码来源:Coach.scala

示例4: InvestmentPeriodsCreator

//设置package包名称以及导入依赖的类
package com.eigenroute.portfoliosimulation.investmentperiod

import com.eigenroute.portfoliosimulation.{ETFData, PortfolioDesign}
import org.joda.time.{DateTime, Days}

class InvestmentPeriodsCreator(
    portfolioDesign: PortfolioDesign,
    sortedCommonDatesETFData:Seq[ETFData],
    investmentDurationYears: Int) {

  val allDates: List[DateTime] =
    sortedCommonDatesETFData.toList.map(_.asOfDate)
    .distinct.sortWith( (d1, d2) => d1.isBefore(d2))
  val maybeEarliestDate: Option[DateTime] = allDates.headOption
  val maybeLatestDate: Option[DateTime] = allDates.reverse.headOption

  def create:Seq[InvestmentPeriod] =
    (for {
      earliestDate <- maybeEarliestDate.toSeq
      latestDate <- maybeLatestDate.toSeq
      daysBetween =
      Days.daysBetween(
        earliestDate.toLocalDate,
        latestDate.minusYears(investmentDurationYears).plusDays(1).toLocalDate)
      .getDays
      day <- 0.to(daysBetween)
      if !earliestDate.plusYears(investmentDurationYears).isAfter(latestDate)
      startOfPeriod = earliestDate.plusDays(day)
      endOfPeriod = earliestDate.plusYears(investmentDurationYears).plusDays(day)
    } yield {
      InvestmentPeriod(startOfPeriod, endOfPeriod)
    }).filter(iP =>
      allDates.contains(iP.startDate)
    )
} 
开发者ID:shafiquejamal,项目名称:portfolio-simulation,代码行数:36,代码来源:InvestmentPeriodsCreator.scala

示例5: PrefixedTokensTest

//设置package包名称以及导入依赖的类
package com.gu.cas

import org.joda.time.{Days, Weeks}
import org.scalatest.{FlatSpec, Matchers}

class PrefixedTokensTest extends FlatSpec with Matchers {
  "Token Encoder" should "roundtrip" in {

    val encoder = RawTokenEncoder("secret")
    val periods = 0.until(53).map(Weeks.weeks)
    val creationOffsetDays = 0.until(2047).map(Days.days)

    for (period <- periods) {
      for (creationDateOffset <- creationOffsetDays) {
        val payload = TokenPayload(creationDateOffset, period, SevenDay)
        val token: String = encoder.encode(payload)
        val decodedPayload = encoder.decode(token).asInstanceOf[Valid].payload

        decodedPayload.period should equal (period)
        decodedPayload.creationDateOffset should equal (creationDateOffset)
      }
    }

  }
} 
开发者ID:guardian,项目名称:content-authorisation-common,代码行数:26,代码来源:PrefixedTokensTest.scala

示例6: InvestmentPeriodsCreator

//设置package包名称以及导入依赖的类
package com.eigenroute.portfolioanalysis.investment

import com.eigenroute.portfolioanalysis.rebalancing.{ETFData, PortfolioDesign}
import org.joda.time.{DateTime, Days}

class InvestmentPeriodsCreator(
    portfolioDesign: PortfolioDesign,
    sortedCommonDatesETFData:Seq[ETFData],
    investmentDurationYears: Int) {

  val allDates: List[DateTime] =
    sortedCommonDatesETFData.toList.map(_.asOfDate)
    .distinct.sortWith( (d1, d2) => d1.isBefore(d2))
  val maybeEarliestDate: Option[DateTime] = allDates.headOption
  val maybeLatestDate: Option[DateTime] = allDates.reverse.headOption

  def create:Seq[InvestmentPeriod] =
    (for {
      earliestDate <- maybeEarliestDate.toSeq
      latestDate <- maybeLatestDate.toSeq
      daysBetween =
        Days.daysBetween(
          earliestDate.toLocalDate,
          latestDate.minusYears(investmentDurationYears).plusDays(1).toLocalDate)
          .getDays
      day <- 0.to(daysBetween)
      if !earliestDate.plusYears(investmentDurationYears).isAfter(latestDate)
      startOfPeriod = earliestDate.plusDays(day)
      endOfPeriod = earliestDate.plusYears(investmentDurationYears).plusDays(day)
    } yield {
      InvestmentPeriod(startOfPeriod, endOfPeriod)
    }).filter(iP =>
      allDates.contains(iP.startDate)
    )
} 
开发者ID:shafiquejamal,项目名称:portfolioanalysis,代码行数:36,代码来源:InvestmentPeriodsCreator.scala

示例7: PasswordResetCodeSenderImpl

//设置package包名称以及导入依赖的类
package access.authentication

import com.google.inject.Inject
import communication.LinkSender
import org.joda.time.Days
import play.api.Configuration
import user.UserMessage
import util.TimeProvider

import scala.util.{Random, Success}

class PasswordResetCodeSenderImpl @Inject()(
    authenticationAPI: AuthenticationAPI,
    linkSender: LinkSender,
    timeProvider: TimeProvider,
    configuration: Configuration)
  extends PasswordResetCodeSender {

  override def send(user: UserMessage, host: String): Unit = {
    authenticationAPI.retrievePasswordResetCode(user.email)
        .filter { passwordResetCodeAndDate =>
          Days.daysBetween(passwordResetCodeAndDate.date.withTimeAtStartOfDay(), timeProvider.now().withTimeAtStartOfDay()).getDays <
          configuration.getInt("crauth.passwordResetLinkIsValidForDays").getOrElse(10)
        }
    .fold[Unit] {
      val passwordResetCode = Random.alphanumeric.take(50).mkString
      authenticationAPI.storePasswordResetCode(user.email, passwordResetCode) match {
        case Success(retrievedUser) =>
          linkSender
          .send(retrievedUser, host, passwordResetCode, "reset-password", "passwordresetlink.subject", "passwordresetlink.body")
        case _ =>
      }
    }(existingPasswordResetCode =>
      linkSender
        .send(user, host, existingPasswordResetCode.code, "reset-password", "passwordresetlink.subject", "passwordresetlink.body")
     )




  }

} 
开发者ID:shafiquejamal,项目名称:play-authentication,代码行数:44,代码来源:PasswordResetCodeSenderImpl.scala

示例8: date2i

//设置package包名称以及导入依赖的类
package ch.octo.cffpoc.gtfs

import org.joda.time.{ Days, LocalDate }

import scala.collection.BitSet


  def date2i(localDate: LocalDate): Int = {
    if (localDate.isBefore(startDate) || localDate.isAfter(endDate)) {
      throw new IndexOutOfBoundsException(s"$localDate not  within [$startDate - $endDate]")
    }
    return Days.daysBetween(startDate, localDate).getDays
  }
}

object ExceptionDater {
  def load(calendar: RawCalendar, itExceptionDates: Iterator[RawCalendarDate]): ExceptionDater = {
    return itExceptionDates.foldLeft(new ExceptionDater(calendar.dateStart.minusDays(3), calendar.dateEnd.plusDays(3)))((ed, rcd) => ed.addException(rcd.serviceId, rcd.date))
  }
} 
开发者ID:alexmasselot,项目名称:gtfs-simulation-play,代码行数:21,代码来源:ExceptionDater.scala


注:本文中的org.joda.time.Days类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。