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


Scala Date类代码示例

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


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

示例1: Cookies

//设置package包名称以及导入依赖的类
package codes.mark.geilematte.facades

import org.scalajs.dom.document

import scala.scalajs.js.Date
import scalaz.std.list._

object Cookies {

  def read: Map[String, String] =
    document.cookie
      .split(";")
      .toList
      .map(_.split("=").toList)
      .flatMap(x =>
        (x.headOption, x.drop(1).headOption) match {
          case (Some(k), Some(v)) => List((k.trim, v))
          case _                  => Nil
        })
      .toMap

  def write(values:Map[String, String]): Unit = {
    val expiry = new Date(2020, 1)
    values.toList.foreach {
        case (k, v) =>
          val expires = expiry.toUTCString
          document.cookie = s"$k=$v;expires=$expires;path=/"
    }
  }
} 
开发者ID:i-am-the-slime,项目名称:geilematte,代码行数:31,代码来源:Cookies.scala

示例2: WorkloadsTests

//设置package包名称以及导入依赖的类
package drt.client.services

import drt.shared.FlightsApi._
import drt.shared._
import utest._

import scala.collection.immutable.{IndexedSeq, Map}
import scala.scalajs.js.Date

object WorkloadsTests extends TestSuite {

  def tests = TestSuite {

    "Given workloads, " - {
      "we need a label per minute, starting at midnight of today" - {
        val firstTime = Date.parse("2016-11-01T07:20Z").toLong
        val workloads = Workloads(
          Map("T1" ->
            Map("eeaDesk" ->
              (List(WL(firstTime, 99)), List(Pax(firstTime, 10))))))
        val labels: IndexedSeq[TerminalName] = workloads.labels.take(5)
        assert(labels  == List(
          "00:00",
          "00:01",
          "00:02",
          "00:03",
          "00:04"
        ))
      }
      "it doesn't matter what terminal we have in workloads we need a label per minute" - {
        val firstTime = Date.parse("2016-11-01T07:20Z").toLong
        val workloads = Workloads(
          Map("A1" ->
            Map("eeaDesk" ->
              (List(WL(firstTime, 99)), List(Pax(firstTime, 10))))))
        val labels: IndexedSeq[TerminalName] = workloads.labels.take(5)
        assert(labels  == List(
          "00:00",
          "00:01",
          "00:02",
          "00:03",
          "00:04"
        ))
      }
      "the labels are in 24H format" - {
        val firstTime = Date.parse("2016-11-01T14:20Z").toLong
        val workloads = Workloads(
          Map("A1" ->
            Map("eeaDesk" ->
              (List(WL(firstTime, 99)), List(Pax(firstTime, 10))))))
        val labels: IndexedSeq[TerminalName] = workloads.labels.drop(800).take(5)
        assert(labels  == List(
          "13:20", "13:21", "13:22", "13:23", "13:24"
        ))
      }
    }
  }
} 
开发者ID:UKHomeOffice,项目名称:drt-scalajs-spa-exploration,代码行数:59,代码来源:WorkloadsTests.scala

示例3: SimpleLogger

//设置package包名称以及导入依赖的类
package me.mmcoulombe.aad

import scala.annotation.elidable
import scala.annotation.elidable._
import scala.scalajs.js.Date


object SimpleLogger {
  @elidable(FINEST)
  def trace(msg: String): Unit =
    println(s"TRACE [${new Date()}: $msg")

  @elidable(FINE)
  def debug(msg: String): Unit =
    println(s"DEBUG [${new Date()}: $msg")

  @elidable(INFO)
  def info(msg: String): Unit =
    println(s"INFO [${new Date()}: $msg")
} 
开发者ID:mmcoulombe,项目名称:poc-aad,代码行数:21,代码来源:SimpleLogger.scala

示例4: MainTest

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

import org.scalatest.FreeSpec

import scala.scalajs.js
import scala.scalajs.js.Date

class MainTest extends FreeSpec {

  "getMillis" - {
    "should return UNIX timestamp" in {
      val millisBefore = Date.now().toLong
      val millis = Main.getNowInMillis
      val millisAfter = Date.now().toLong
      assert(millis >= millisBefore)
      assert(millis <= millisAfter)
    }
  }

} 
开发者ID:scalacenter,项目名称:scalajs-bundler,代码行数:21,代码来源:MainTest.scala

示例5: main

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

import com.outr.scribe.Logging
import org.hyperscala._
import org.scalajs.dom._

import scala.scalajs.js.Date

trait ClientProfileScreen extends ProfileScreen with SimpleClientScreen[html.Div] with Logging {
  override def main = byId[html.Div]("profile")
  def dashboardButton = byId[html.Button]("dashboardButton")
  def reloadButton = byId[html.Button]("reloadButton")
  def createdBlock = byId[html.Element]("created")

  override def init(state: InitState): Unit = {
    logger.info(s"Profile init! (state: $state)")

    createdBlock.innerHTML = new Date().toTimeString()

    reloadButton.onclick = (evt: Event) => {
      logger.info("Requesting reload of page...")
      requestReloadContent()

      false
    }
    dashboardButton.onclick = (evt: Event) => {
      app.connection.screen := ExampleApplication.dashboard

      false
    }
  }
} 
开发者ID:outr,项目名称:hyperscala,代码行数:33,代码来源:ClientProfileScreen.scala

示例6: Platform

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

import scala.scalajs.js.Date

object Platform {
  val lineSeparator = "\n"

  private val replacements = Map(
    "%1$tY" -> ((d: Date) => d.getFullYear().toString),
    "%1$tm" -> ((d: Date) => twoPlaces(d.getMonth() + 1).toString),
    "%1$td" -> ((d: Date) => d.getDate().toString),
    "%1$tT" -> ((d: Date) => s"${d.getHours()}:${twoPlaces(d.getMinutes())}:${twoPlaces(d.getSeconds())}"),
    "%1$tL" -> ((d: Date) => d.getMilliseconds().toString)
  )

  private def twoPlaces(value: Int): String = {
    if (value < 10) {
      s"0$value"
    } else {
      value.toString
    }
  }

  def formatDate(pattern: String, timestamp: Long): String = {
    val date = new Date(timestamp.toDouble)
    val standardPattern = replacements.foldLeft(pattern) {
      case (p, (original, update)) => p.replaceAllLiterally(original, update(date))
    }
    date.formatted(standardPattern)
  }
} 
开发者ID:outr,项目名称:scribe,代码行数:32,代码来源:Platform.scala

示例7: emptyComponent

//设置package包名称以及导入依赖的类
package io.udash.testing

import com.github.ghik.silencer.silent
import org.scalajs.dom
import org.scalatest.{Assertion, Succeeded}
import org.scalatest.concurrent.PatienceConfiguration
import org.scalatest.time.{Millis, Span}

import scala.concurrent.{ExecutionContext, Future, Promise}
import scala.scalajs.concurrent.JSExecutionContext
import scala.scalajs.js.Date
import scala.util.{Failure, Success}

trait FrontendTestUtils {
  import scalatags.JsDom.all.div
  def emptyComponent() = div().render
}

trait UdashFrontendTest extends UdashSharedTest with FrontendTestUtils {
  @silent
  implicit val testExecutionContext = JSExecutionContext.runNow
}

trait AsyncUdashFrontendTest extends AsyncUdashSharedTest with FrontendTestUtils with PatienceConfiguration {
  case object EventuallyTimeout extends Exception

  @silent
  override implicit def executionContext: ExecutionContext = JSExecutionContext.runNow
  override implicit val patienceConfig = PatienceConfig(scaled(Span(5000, Millis)), scaled(Span(100, Millis)))

  def eventually(code: => Any)(implicit patienceConfig: PatienceConfig): Future[Assertion] = {
    val start = Date.now()
    val p = Promise[Assertion]
    def startTest(): Unit = {
      dom.window.setTimeout(() => {
        if (patienceConfig.timeout.toMillis > Date.now() - start) {
          try {
            code
            p.complete(Success(Succeeded))
          } catch {
            case _: Exception => startTest()
          }
        } else {
          p.complete(Failure(EventuallyTimeout))
        }
      }, patienceConfig.interval.toMillis)
    }
    startTest()
    p.future
  }
} 
开发者ID:UdashFramework,项目名称:udash-core,代码行数:52,代码来源:UdashFrontendTest.scala

示例8: ActorRepository

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

import rx.Var

import scala.scalajs.js
import scala.scalajs.js.Date

class ActorRepository {

  import ActorRepository._

  private[this] val currentActorState = js.Dictionary[Var[ActorState]]()

  //TODO: make it visible on the outside as Rx[Set[String]] just in case
  val newActors = Var[Set[String]](Set())
  val seenActors = Var[Set[String]](Set())

  def state(actor: String): Var[ActorState] = currentActorState.getOrElseUpdate(
    actor,
    Var(ActorState(actor, FrontendUtil.shortActorName(actor), FrontendUtil.systemName(actor)))
  )

  def mutateActor(actor: String)(fn: ActorState => ActorState) = {
    state(actor)() = fn(state(actor).now.copy(lastUpdatedAt = new js.Date()))
    addActorsToSeen(actor)
  }

  @inline
  final def addActorsToSeen(actors: String*): Unit = {
    addActorsToSeen(actors)
  }

  def addActorsToSeen(actors: Iterable[String]): Unit = {
    val previouslySeen = seenActors.now
    val newSeen = previouslySeen ++ actors
    if (previouslySeen.size != newSeen.size) {
      newActors() = newSeen -- previouslySeen
      seenActors() = newSeen
    }
  }

}

case object ActorRepository {

  case class FSMState(currentState: String, currentData: String)

  case class ActorState(
    path: String,
    label: String,
    system: String,
    isDead: Boolean = false,
    mailboxSize: js.UndefOr[Int] = js.undefined,
    internalState: js.UndefOr[String] = js.undefined,
    className: js.UndefOr[String] = js.undefined,
    fsmState: js.UndefOr[FSMState] = js.undefined,
    fsmTransitions: Set[(String, String)] = Set(),
    lastUpdatedAt: js.Date = new Date()
  )

} 
开发者ID:blstream,项目名称:akka-viz,代码行数:62,代码来源:ActorRepository.scala

示例9: mapOutSparse

//设置package包名称以及导入依赖的类
package quizleague.web.service.fixtures


import angulate2.std.Injectable
import angulate2.ext.classModeScala
import angulate2.http.Http
import quizleague.web.service.EntityService
import quizleague.web.model._
import quizleague.web.model.{Fixture => Model}
import quizleague.domain.{Fixture => Dom}
import quizleague.domain.Ref
import rxjs.Observable
import quizleague.web.names.ComponentNames
import scala.scalajs.js
import quizleague.web.util.DateTimeConverters._
import scala.scalajs.js.Date
import quizleague.web.service._
import quizleague.web.names.FixtureNames
import rxjs.Observable
import quizleague.web.service.venue.VenueGetService
import quizleague.web.service.team.TeamGetService
import quizleague.web.service.venue.VenuePutService
import quizleague.web.service.team.TeamPutService
import quizleague.web.service.DirtyListService
import quizleague.web.names.FixtureNames
import io.circe._,io.circe.parser._,io.circe.syntax._
import quizleague.util.json.codecs.DomainCodecs._



trait FixtureGetService extends GetService[Fixture] with FixtureNames{
    override type U = Dom
    
  val venueService:VenueGetService
  val teamService:TeamGetService

  override protected def mapOutSparse(dom:Dom) = Model(dom.id,dom.description,dom.parentDescription,refObs(dom.venue, venueService),refObs(dom.home, teamService),refObs(dom.away, teamService),dom.date,dom.time,dom.duration)
  
  override protected def dec(json:String) = decode[U](json)
  override protected def decList(json:String) = decode[List[U]](json)
}

trait FixturePutService extends PutService[Fixture] with FixtureGetService with DirtyListService[Model]{
  override protected def mapIn(model:Model) = Dom(model.id, model.description, model.parentDescription, venueService.ref(model.venue), teamService.ref(model.home), teamService.ref(model.away), model.date, model.time, model.duration)
  override protected def make() = ???
  
  override val venueService:VenuePutService
  override val teamService:TeamPutService
  
  def instance(fx:Fixtures, home:Team, away:Team, venue:Venue) = {
    val dom = Dom(newId,fx.description, fx.parentDescription,venueService.getRef(venue),teamService.getRef(home),teamService.getRef(away),fx.date,fx.start,fx.duration)
    mapOutSparse(dom)
  }
  
  override def enc(item: Dom) = item.asJson

} 
开发者ID:gumdrop,项目名称:quizleague,代码行数:58,代码来源:FixtureService.scala


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