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


Scala ZoneId类代码示例

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


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

示例1: Rfc3339Util

//设置package包名称以及导入依赖的类
package de.zalando.play.controllers

import java.time.format.{ DateTimeFormatter, DateTimeParseException }
import java.time.{ LocalDate, ZoneId, ZonedDateTime }


object Rfc3339Util {

  private val fullDate = DateTimeFormatter.ofPattern("yyyy-MM-dd")
  private val shortDateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ")
  private val shortDTWithTicks = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
  private val fullDTWithTicks = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'")
  private val dateTime = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSSZ")

  def parseDateTime(datestring: String): ZonedDateTime =
    if (datestring.endsWith("Z") || datestring.endsWith("z")) parseFull(datestring)
    else parseParts(datestring)

  def parseDate(datestring: String): LocalDate =
    LocalDate.parse(datestring, fullDate)

  def writeDate(date: LocalDate): String = fullDate.format(date)

  def writeDateTime(date: ZonedDateTime): String = dateTime.format(date)

  private def parseParts(datestring: String): ZonedDateTime = {
    //step one, split off the timezone.
    val sepChar = if (datestring.indexOf('+') > 0) '+' else '-'
    val firstpart = datestring.substring(0, datestring.lastIndexOf(sepChar.toInt))
    val secondpart = datestring.substring(datestring.lastIndexOf(sepChar.toInt))
    //step two, remove the colon from the timezone offset
    val thirdpart = secondpart.substring(0, secondpart.indexOf(':')) + secondpart.substring(secondpart.indexOf(':') + 1)
    val dstring = firstpart + thirdpart
    try {
      ZonedDateTime.parse(dstring, shortDateTime)
    } catch {
      case pe: DateTimeParseException =>
        ZonedDateTime.parse(dstring, dateTime)
    }
  }

  private def parseFull(datestring: String): ZonedDateTime = {
    val z = ZoneId.systemDefault()
    try {
      ZonedDateTime.parse(datestring, shortDTWithTicks.withZone(z))
    } catch {
      case p: DateTimeParseException => ZonedDateTime.parse(datestring, fullDTWithTicks.withZone(z))
    }
  }

} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:52,代码来源:Rfc3339Util.scala

示例2: TimeServiceImpl

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

import time.api.TimeService
import com.lightbend.lagom.javadsl.api.ServiceCall
import akka.NotUsed
import java.util.concurrent.CompletableFuture
import java.util.concurrent.CompletionStage
import java.time.LocalTime
import java.time.ZoneId

class TimeServiceImpl extends TimeService{

  
  override def timeAt(tz: String): ServiceCall[NotUsed, String] = {
    new ServiceCall[NotUsed, String] {
      
      override def invoke(obj: NotUsed) : CompletionStage[String] = {
        val c = new CompletableFuture[String]
        c.complete(LocalTime.now(ZoneId.of(tz, ZoneId.SHORT_IDS)).toString)
        c
      }
      
    }
  }
  
} 
开发者ID:oswaldo,项目名称:lagom-scala-scalajs-scalatags,代码行数:27,代码来源:TimeServiceImpl.scala

示例3: Global

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

import play.api.libs.json._
import models.Building
import java.time.{ ZonedDateTime, ZoneId, DayOfWeek }

//Constants or constnat builders that are not messages
object Global {
  final val ZONEID = "Asia/Seoul"

  val baseStartTime = 9
  val baseEndTime = 17

  val classroomList = ("1202" :: "1203" :: "1204" :: "1205" :: "1206" :: "1207" :: "1208" :: Nil) ++
    ("1210" :: "1211" :: "1301" :: "1302" :: "1303" :: "1304" :: "1305" :: "1306" :: "1307" :: Nil) ++
    ("1308" :: "1309" :: "1310" :: "1311" :: "1401" :: "1402" :: "1403" :: "1404" :: "1405" :: Nil) ++
    ("1406" :: "1407" :: "1408" :: "1409" :: "1501" :: "1502" :: "1503" :: "1504" :: "1505" :: Nil) ++
    ("1506" :: "1507" :: "1508" :: "1509" :: "1601" :: "1602" :: "1603" :: "1604" :: "1605" :: Nil) ++
    ("1606" :: "1607" :: "1608" :: "1609" :: "2201" :: "2202" :: "2203" :: "2204" :: "2205" :: Nil) ++
    ("2207" :: "2208" :: "2210" :: "2401" :: "2402" :: "2403" :: "2404" :: "2405" :: "2407" :: Nil) ++
    ("2408" :: "2409" :: "2501" :: "2502" :: "2503" :: "2504" :: "2506" :: "2507" :: "2508" :: Nil) ++
    ("2509" :: "3201" :: "3203" :: "3205" :: "3206" :: "3301" :: "3302" :: "3303" :: "3304" :: Nil) ++
    ("3305" :: "3306" :: "3307" :: "3308" :: "3401" :: "3402" :: "3403" :: "3404" :: "3405" :: Nil) ++
    ("3406" :: "3407" :: "3408" :: "3409" :: "3501" :: "3502" :: "3503" :: "3504" :: "3505" :: Nil) ++
    ("3506" :: "3507" :: "3508" :: "3509" :: "C301" :: "C302" :: "C304" :: "C305" :: "C306" :: Nil) ++
    ("C307" :: "C308" :: "C309" :: "C310" :: "C311" :: "C401" :: "C402" :: "C405" :: "C406" :: Nil) ++
    ("C407" :: "C408" :: "C409" :: "C410" :: "C411" :: "C412" :: "C413" :: "C501" :: "C509" :: Nil) ++
    ("C510" :: "C513" :: "C514" :: "C515" :: "C606" :: "C614" :: "C615" :: "C616" :: Nil) ++
    ("0109" :: "0115" :: "0116" :: "0117" :: "0118" :: "0221" :: "0225" :: "0328" :: "0329" :: "0330" :: "0338" :: Nil)


  def keyboardTemplate(buttons: Seq[String]) = Json.obj(
    "type" -> "buttons",
    "buttons" -> buttons
  )

  def responseTemplate(message: String, buttons: Seq[String]) = Json.obj(
    "message" -> Map(
      "text" -> message
    ),
    "keyboard" -> keyboardTemplate(buttons)
  )

  def nowIsApplicable() = {
    val time = ZonedDateTime.now(ZoneId.of(ZONEID))
    val dow = time.getDayOfWeek.getValue()
    val hour = time.getHour()
    dow <= 5 && dow >= 1 && hour >= 9 && hour < 17
  }
} 
开发者ID:yoo-haemin,项目名称:hufs-classroom,代码行数:51,代码来源:Global.scala

示例4: safeToken

//设置package包名称以及导入依赖的类
package com.atomist.rug.function.github

import java.time.{OffsetDateTime, ZoneId}
import java.util.Date

import com.atomist.rug.runtime.Rug

trait GitHubFunction extends Rug {

  
  def safeToken(token: String): String =
    if (token != null)
      token.charAt(0) + ("*" * (token.length() - 2)) + token.last
    else
      null
}

object GitHubFunction {

  val ApiUrl = "https://api.github.com"

  val Events = Seq(
    "commit_comment",
    "create",
    "delete",
    "deployment",
    "deployment_status",
    "download",
    "follow",
    "fork",
    "fork_apply",
    "gist",
    "gollum",
    "issue_comment",
    "issues",
    "member",
    "page_build",
    "public",
    "pull_request",
    "pull_request_review_comment",
    "push",
    "release",
    "repository",
    "status",
    "team_add",
    "watch",
    "ping")

  def convertDate(date: Date): OffsetDateTime =
    if (date == null) null else OffsetDateTime.ofInstant(date.toInstant, ZoneId.systemDefault())
} 
开发者ID:atomist,项目名称:rug-functions-github,代码行数:52,代码来源:GitHubFunction.scala

示例5: Rfc3339UtilTest

//设置package包名称以及导入依赖的类
package de.zalando.play.controllers

import java.time.{ LocalDateTime, ZoneId, ZoneOffset, ZonedDateTime }

import org.scalatest.{ FunSpec, MustMatchers }


class Rfc3339UtilTest extends FunSpec with MustMatchers {

  val dtz = ZoneId.of("UTC")
  val offset = ZoneOffset.UTC
  //noinspection ScalaStyle
  val date = ZonedDateTime.of(LocalDateTime.ofEpochSecond(1451911387L, 0, offset), dtz)

  describe("Rfc3339UtilTest") {

    it("should parse RFC3339 DateTime") {
      Rfc3339Util.parseDateTime("2007-05-01T15:43:26-00:00").withZoneSameInstant(dtz).toString mustBe "2007-05-01T15:43:26Z[UTC]"
      Rfc3339Util.parseDateTime("2007-05-01T15:43:26+00:00").withZoneSameInstant(dtz).toString mustBe "2007-05-01T15:43:26Z[UTC]"
      Rfc3339Util.parseDateTime("2007-05-01T15:43:26.3452-01:00").withZoneSameInstant(dtz).toString mustBe "2007-05-01T16:43:26.345200Z[UTC]"
      Rfc3339Util.parseDateTime("2007-05-01T15:43:26.3452+01:00").withZoneSameInstant(dtz).toString mustBe "2007-05-01T14:43:26.345200Z[UTC]"
      Rfc3339Util.parseDateTime("2007-05-01T15:43:26.3452+00:00").withZoneSameInstant(dtz).toString mustBe "2007-05-01T15:43:26.345200Z[UTC]"
    }
    it("should parse RFC3339 Date") {
      Rfc3339Util.parseDate("2007-05-01").toString mustBe "2007-05-01"
      Rfc3339Util.parseDate("2008-05-01").toString mustBe "2008-05-01"
      Rfc3339Util.parseDate("2007-08-01").toString mustBe "2007-08-01"
      Rfc3339Util.parseDate("2007-05-08").toString mustBe "2007-05-08"
    }
    it("should write DateTime") {
      Rfc3339Util.writeDateTime(date) mustBe "2016-01-04T12:43:07.0000+0000"
    }
    it("should write Date") {
      Rfc3339Util.writeDate(date.toLocalDate) mustBe "2016-01-04"
    }
  }
} 
开发者ID:LappleApple,项目名称:api-first-hand,代码行数:38,代码来源:Rfc3339UtilTest.scala

示例6: Twilio

//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.monitor.canary.sms.client

import java.time.{LocalDate, LocalDateTime, ZoneId}

import com.twilio
import com.twilio.base.Page
import com.twilio.rest.api.v2010.account
import org.joda.time.DateTime

import scala.annotation.tailrec
import scala.collection.JavaConverters._

object Twilio {

  case class TwilioConfig(accountSid: String, authToken: String, messageServiceSid: String)
  case class Message(messageId: String, body: String, from: String)

  def findSuccessfullyReceivedSMS(config: TwilioConfig): (String, LocalDateTime) => Option[Either[String, Message]] = {
    twilio.Twilio.init(config.accountSid, config.authToken)

    (traceToken: String, dateSent: LocalDateTime) =>
      {

        val jodaDateSent = new DateTime(dateSent.atZone(ZoneId.of("UTC")).toInstant.toEpochMilli).withTimeAtStartOfDay

        @tailrec
        def checkPageForMessage(page: Page[account.Message]): Option[Either[String, Message]] = {
          page.getRecords.asScala.find(message =>
            message.getBody.contains(traceToken) && message.getMessagingServiceSid == config.messageServiceSid) match {
            case Some(message) =>
              if (message.getStatus == account.Message.Status.FAILED || message.getStatus == account.Message.Status.UNDELIVERED) {
                Some(Left(message.getErrorMessage))
              } else if (message.getStatus == account.Message.Status.RECEIVED) {
                Some(Right(Message(message.getSid, message.getBody, message.getFrom.toString)))
              } else {
                None
              }

            case None =>
              if (page.hasNextPage) {
                val nextPage = account.Message.reader.setDateSent(jodaDateSent).nextPage(page)
                checkPageForMessage(nextPage)
              } else {
                None
              }
          }
        }

        val firstPage = account.Message.reader.setDateSent(jodaDateSent).firstPage()
        checkPageForMessage(firstPage)
      }
  }

} 
开发者ID:ovotech,项目名称:comms-monitor-service,代码行数:55,代码来源:Twilio.scala

示例7: LibratoActorStateSpec

//设置package包名称以及导入依赖的类
package com.ovoenergy.comms.monitor.pipeline.metrics.client.librato

import java.time.{ZoneId, ZonedDateTime}

import org.scalatest.{FlatSpec, Matchers}

class LibratoActorStateSpec extends FlatSpec with Matchers {
  val now = ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"))

  behavior of "LibratoActorState"

  it should "keep track of gauge metrics" in {
    val source1 = "source1"
    val source2 = "source2"

    val metric1 = "metric1"
    val metric2 = "metric2"

    val state = LibratoActorState()
      .addGaugeMetric(source1, metric1, 1, now)
      .addGaugeMetric(source2, metric1, 1, now)
      .addGaugeMetric(source1, metric2, 1, now)

    state.gaugeMetrics should be(
      Vector(LibratoMetric(source1, metric1, 1, now),
             LibratoMetric(source2, metric1, 1, now),
             LibratoMetric(source1, metric2, 1, now)))
  }

  it should "keep track of counter metrics" in {
    val source1 = "source1"
    val source2 = "source2"

    val metric1 = "metric1"
    val metric2 = "metric2"

    val state = LibratoActorState()
      .addCounterMetric(source1, metric1, 1, now)
      .addCounterMetric(source2, metric1, 1, now)
      .addCounterMetric(source1, metric2, 1, now)

    state.counterMetrics should be(
      Vector(LibratoMetric(source1, metric1, 1, now),
             LibratoMetric(source2, metric1, 1, now),
             LibratoMetric(source1, metric2, 1, now)))
  }

  it should "start with empty metrics" in {
    val state = LibratoActorState()

    state.counterMetrics shouldBe empty
    state.gaugeMetrics shouldBe empty
  }

} 
开发者ID:ovotech,项目名称:comms-monitor-service,代码行数:56,代码来源:LibratoActorStateSpec.scala

示例8: SpecSpec

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

import java.time.{ZoneId, ZonedDateTime}

import org.scalatest._


class SpecSpec extends FunSpec with Matchers {
  describe("Spec") {
    describe("dateTimes") {
      it("should return a stream of upcoming ZonedDateTimes for a spec") {
        val start = ZonedDateTime.of(2017, 1, 1, 0, 0, 0, 0, ZoneId.of("UTC"))
        val Right(spec) = Spec.parse("10-15 * * * Sun")
        val dateTimes = spec.dateTimes(start).take(10).toList

        dateTimes shouldEqual List(
          start.withHour(0).withMinute(10),
          start.withHour(0).withMinute(11),
          start.withHour(0).withMinute(12),
          start.withHour(0).withMinute(13),
          start.withHour(0).withMinute(14),
          start.withHour(0).withMinute(15),
          start.withHour(1).withMinute(10),
          start.withHour(1).withMinute(11),
          start.withHour(1).withMinute(12),
          start.withHour(1).withMinute(13)
        )
      }
    }
  }
} 
开发者ID:Bogdanp,项目名称:crontab,代码行数:32,代码来源:SpecSpec.scala

示例9: QuoteParser

//设置package包名称以及导入依赖的类
package openquant.yahoofinance.impl

import java.time.format.DateTimeFormatter
import java.time.{LocalDate, ZoneId, ZonedDateTime}

import com.github.tototoshi.csv._
import openquant.yahoofinance.Quote

import scala.io.Source


class QuoteParser {
  private[this] val df = DateTimeFormatter.ofPattern("yyyy-MM-dd")
  private[this] val zoneId = ZoneId.of("America/New_York")

  def parse(content: String): Vector[Quote] = {
    val csvReader = CSVReader.open(Source.fromString(content))
    val quotes: Vector[Quote] = csvReader.toStream.drop(1).map { fields ?
      parseCSVLine(fields.toVector)
    }.toVector
    quotes
  }

  private def parseCSVLine(field: Vector[String]): Quote = {
    require(field.length >= 7)
    Quote(
      parseDate(field(0)),
      BigDecimal(field(1)),
      BigDecimal(field(4)),
      BigDecimal(field(2)),
      BigDecimal(field(3)),
      BigDecimal(field(5)),
      BigDecimal(field(6))
    )
  }

  private def parseDate(date: String): ZonedDateTime = {
    LocalDate.parse(date, df).atStartOfDay().atZone(zoneId)
  }
}

object QuoteParser {
  def apply() = new QuoteParser
} 
开发者ID:openquant,项目名称:YahooFinanceScala,代码行数:45,代码来源:QuoteParser.scala

示例10: SunService

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

import model.SunInfo
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import play.api.libs.ws.WSClient

import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global


class SunService(wsClient: WSClient) {
  def getSunInfo(lat: Double, lon: Double): Future[SunInfo] = {
    val responseF = wsClient.url("http://api.sunrise-sunset.org/json?" +
      s"lat=$lat&lng=$lon&formatted=0").get()
    responseF.map { response =>
      val json = response.json
      val sunriseTimeStr = (json \ "results" \ "sunrise").as[String]
      val sunsetTimeStr = (json \ "results" \ "sunset").as[String]
      val sunriseTime = ZonedDateTime.parse(sunriseTimeStr)
      val sunsetTime = ZonedDateTime.parse(sunsetTimeStr)
      val formatter = DateTimeFormatter.ofPattern("HH:mm:ss").withZone(ZoneId.of("Australia/Sydney"))
      val sunInfo = SunInfo(sunriseTime.format(formatter), sunsetTime.format(formatter))
      sunInfo
    }
  }
} 
开发者ID:denisftw,项目名称:modern-web-scala,代码行数:29,代码来源:SunService.scala

示例11: AwsCredentialFilterTest

//设置package包名称以及导入依赖的类
package io.github.daviddenton.finagle.aws

import java.time.{Clock, Instant, ZoneId}

import com.twitter.finagle.Service
import com.twitter.finagle.http.Method.Get
import com.twitter.finagle.http.{Request, Response}
import com.twitter.util.Await.result
import com.twitter.util.Future
import org.jboss.netty.handler.codec.http.HttpHeaders.Names
import org.scalatest.{FunSpec, Matchers}

class AwsCredentialFilterTest extends FunSpec with Matchers {

  private val clock = Clock.fixed(Instant.ofEpochMilli(0), ZoneId.of("UTC"))

  private val filter = AwsCredentialFilter("somehost", clock,
    AwsSignatureV4Signer(AwsCredentialScope(AwsRegion.usEast, AwsService.s3), AwsCredentials("access", "secret")))

  private val mirrorHeaders = Service.mk {
    req: Request =>
      val response = Response()
      req.headerMap.foreach(response.headerMap += _)
      Future.value(response)
  }

  describe("AwsCredentialFilter") {
    it("adds host header") {
      result(filter(Request(Get, "/test"), mirrorHeaders)).headerMap(Names.HOST) shouldBe "somehost"
    }

    it("adds auth header") {
      result(filter(Request(Get, "/test"), mirrorHeaders)).headerMap(Names.AUTHORIZATION) shouldBe
        "AWS4-HMAC-SHA256 Credential=access/19700101/us-east/s3/aws4_request, SignedHeaders=content-length;host;x-amz-date, Signature=d7690ffa429d19877081491d5a325f564782998a3369a311a3dfcaa8cdeb9ecc"
    }

    it("adds time header") {
      result(filter(Request(Get, "/test"), mirrorHeaders)).headerMap(AwsHeaders.DATE) shouldBe "19700101T010000Z"
    }

    it("adds content sha256") {
      result(filter(Request(Get, "/test"), mirrorHeaders)).headerMap(AwsHeaders.CONTENT_SHA256) shouldBe "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
    }
  }
} 
开发者ID:daviddenton,项目名称:finagle-aws,代码行数:46,代码来源:AwsCredentialFilterTest.scala

示例12: LogTimestampFormatter

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

import java.time.format.{DateTimeFormatterBuilder, SignStyle}
import java.time.{Instant, ZoneId, ZonedDateTime}
import java.util.Locale


object LogTimestampFormatter {
  import java.time.temporal.ChronoField._

  val systemZone             = ZoneId.systemDefault().normalized()
  val noSpaceTimestampFormat = new DateTimeFormatterBuilder()
                               .parseCaseInsensitive()
                               .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
                               .appendLiteral('-')
                               .appendValue(MONTH_OF_YEAR, 2)
                               .appendLiteral('-')
                               .appendValue(DAY_OF_MONTH, 2)
                               .appendLiteral('T')
                               .appendValue(HOUR_OF_DAY, 2)
                               .appendLiteral(':')
                               .appendValue(MINUTE_OF_HOUR, 2)
                               .appendLiteral(':')
                               .appendValue(SECOND_OF_MINUTE, 2)
                               .appendLiteral('.')
                               .appendValue(MILLI_OF_SECOND, 3)
                               .appendOffset("+HHMM", "Z")
                               .toFormatter(Locale.US)

  val humanReadableTimestampFormatter = new DateTimeFormatterBuilder()
                                        .parseCaseInsensitive()
                                        .appendValue(YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
                                        .appendLiteral('-')
                                        .appendValue(MONTH_OF_YEAR, 2)
                                        .appendLiteral('-')
                                        .appendValue(DAY_OF_MONTH, 2)
                                        .appendLiteral(' ')
                                        .appendValue(HOUR_OF_DAY, 2)
                                        .appendLiteral(':')
                                        .appendValue(MINUTE_OF_HOUR, 2)
                                        .appendLiteral(':')
                                        .appendValue(SECOND_OF_MINUTE, 2)
                                        .appendOffset("+HHMM", "Z")
                                        .toFormatter(Locale.US)

  def formatTimestamp(timeMillis: Long): String = {
    val timestamp = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeMillis), systemZone)
    humanReadableTimestampFormatter.format(timestamp)
  }

  def formatTimestampWithNoSpaace(timeMillis:Long) : String = {
    val timestamp = ZonedDateTime.ofInstant(Instant.ofEpochMilli(timeMillis), systemZone)
    noSpaceTimestampFormat.format(timestamp)
  }
} 
开发者ID:wvlet,项目名称:log,代码行数:56,代码来源:LogTimestampFormatter.scala

示例13: localDateTimeJsonFormat

//设置package包名称以及导入依赖的类
import java.nio.file.{Files, Path}
import java.time.format.DateTimeFormatter
import java.time.{LocalDate, LocalDateTime, ZoneId}
import java.util.Date
import java.util.zip.GZIPInputStream

import spray.json.{JsString, JsValue, RootJsonFormat}

import scala.io.Source


package object vijar {

  implicit def localDateTimeJsonFormat = new RootJsonFormat[LocalDateTime] {
    val dateFormatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME
    override def read(json: JsValue): LocalDateTime = LocalDateTime.parse(json.asInstanceOf[JsString].value, dateFormatter)

    override def write(obj: LocalDateTime): JsValue = JsString(obj.format(dateFormatter))
  }

  implicit class RichStringsOps(s: String) {
    def fromLongToLocalDateTime = {
      val t = new Date(s.toLong).toInstant
      LocalDateTime.ofInstant(t, ZoneId.systemDefault())
    }
  }

  case class GZIPReader[+T](path: Path)(f: Array[String] => T) extends Iterable[T]  {
    override def iterator: Iterator[T] = {
      Source.fromInputStream(new GZIPInputStream(Files.newInputStream(path))).getLines().map(l => f(l.split(" ")))
    }
  }
} 
开发者ID:chauhraj,项目名称:akka-http-websockets-template,代码行数:34,代码来源:package.scala

示例14: receive

//设置package包名称以及导入依赖的类
package io.soheila.um.jobs

import java.time.ZoneId
import javax.inject.Inject

import akka.actor._
import io.soheila.um.jobs.AuthTokenCleaner.Clean
import io.soheila.um.services.auths.AuthTokenService
import io.soheila.um.utils.UMClock

import scala.concurrent.ExecutionContext.Implicits.global


  def receive: Receive = {
    case Clean =>
      val start = clock.now.atZone(ZoneId.systemDefault()).toInstant.toEpochMilli
      val msg = new StringBuffer("\n")
      msg.append("=================================\n")
      msg.append("Start to cleanup auth tokens\n")
      msg.append("=================================\n")
      service.clean.map { deleted =>
        val now = clock.now.atZone(ZoneId.systemDefault()).toInstant.toEpochMilli
        val seconds = (now - start) / 1000
        msg.append("Total of %s auth tokens(s) were deleted in %s seconds".format(deleted.length, seconds)).append("\n")
        msg.append("=================================\n")

        msg.append("=================================\n")
        logger.info(msg.toString)
      }.recover {
        case e =>
          msg.append("Couldn't cleanup auth tokens because of unexpected error\n")
          msg.append("=================================\n")
          logger.error(msg.toString, e)
      }
  }
}

object AuthTokenCleaner {
  case object Clean
} 
开发者ID:esfand-r,项目名称:soheila-um,代码行数:41,代码来源:AuthTokenCleaner.scala

示例15: TaskInput

//设置package包名称以及导入依赖的类
package io.github.maxkorolev.task

import java.time.{ Instant, LocalDateTime, OffsetDateTime, ZoneId }
import java.util.concurrent.Callable

import akka.http.scaladsl.model.StatusCodes
import akka.http.scaladsl.server.Directives._
import io.github.maxkorolev.base.BaseService
import io.github.maxkorolev.task.TaskManager.PushTask

import scala.concurrent.duration._

case class TaskInput(time: Long)

trait TaskService extends BaseService {

  protected val taskRoutes =
    pathPrefix("task") {
      post {
        entity(as[TaskInput]) { in =>
          log.info("/task executed")

          val time = Instant.ofEpochMilli(OffsetDateTime.now().toInstant.toEpochMilli + in.time * 1000L).atZone(ZoneId.systemDefault()).toLocalDateTime

          val millis = time.atZone(ZoneId.systemDefault()).toInstant.toEpochMilli
          val task = new Task {
            val time = millis
            val timeout = 10.seconds
            override def call(): Any = {
              Thread.sleep(3000)
            }
          }
          taskManager ! PushTask(task)

          complete(StatusCodes.OK)
        }
      }
    }
} 
开发者ID:maxkorolev,项目名称:pix,代码行数:40,代码来源:TaskService.scala


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