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


Scala Month类代码示例

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


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

示例1: parseYearMonthDayEra

//设置package包名称以及导入依赖的类
package epam.idobrovolskiy.wikipedia.trending.cli

import java.time.Month

import epam.idobrovolskiy.wikipedia.trending.time.WikiDate



  private val Aliases = Map("now" -> WikiDate.Now, "genesis" -> WikiDate.MinDate)

  private val YearMonthDayRe = """(\d{1,4})(?:[/\.]([01]\d)(?:[/\.](\d\d))?)?""".r

  private def parseYearMonthDayEra(lcDate: String): Option[WikiDate] = {
    val dateSB = new StringBuilder(lcDate)
    var isAd = true
    if (dateSB.endsWith("ad")) {
      dateSB.delete(dateSB.length - 2, dateSB.length)
    }
    else if (dateSB.endsWith("bc")) {
      dateSB.delete(dateSB.length - 2, dateSB.length)
      isAd = false
    }

    if (dateSB.length == 0) {
      Some(if (isAd) WikiDate.AD else WikiDate.BC)
    }
    else
      dateSB match {
        case YearMonthDayRe(year, month, day) =>
          Some(
            WikiDate(
              if (day == null) None else Some(day.toByte),
              if (month == null) None else Some(Month.of(month.toInt)),
              Some(year.toInt),
              None,
              None,
              None,
              Some(isAd)
            )
          )

        case _ => None
      }
  }

  private def parseDecade(lcDate: String): Option[WikiDate] = ???

  private def parseCentury(lcDate: String): Option[WikiDate] = ???

  private def parseThousandYearsAgo(lcDate: String): Option[WikiDate] = ???

  def parse(date: String): Option[WikiDate] = {
    val lcDate = date.toLowerCase

    Aliases.get(lcDate)
      .orElse(parseYearMonthDayEra(lcDate))
      .orElse(parseDecade(lcDate))
      .orElse(parseCentury(lcDate))
      .orElse(parseThousandYearsAgo(lcDate))
  }
} 
开发者ID:igor-dobrovolskiy-epam,项目名称:wikipedia-analysis-scala-core,代码行数:62,代码来源:WikiDateParser.scala

示例2: WikiDateParserTest

//设置package包名称以及导入依赖的类
package epam.idobrovolskiy.wikipedia.trending.cli

import java.time.Month

import epam.idobrovolskiy.wikipedia.trending.time.WikiDate
import org.scalatest.{FlatSpec, Matchers}


class WikiDateParserTest extends FlatSpec with Matchers {
  val parser = WikiDateParser

  "1971" should "parse correctly" in {
    parser.parse("1971") shouldEqual Some(WikiDate.AD(1971))
  }

  "123/03" should "parse correctly" in {
    parser.parse("123/03") shouldEqual Some(WikiDate.AD(123, Month.MARCH))
  }

  "2017.08.04" should "parse correctly" in {
    parser.parse("2017.08.04") shouldEqual Some(WikiDate.AD(2017, Month.AUGUST, 4))
  }

  "33BC" should "parse correctly" in {
    parser.parse("33BC") shouldEqual Some(WikiDate.BC(33))
  }

  "121.02BC" should "parse correctly" in {
    parser.parse("121.02BC") shouldEqual Some(WikiDate.BC(121, Month.FEBRUARY))
  }

  "202.12.31BC" should "parse correctly" in {
    parser.parse("202.12.31BC") shouldEqual Some(WikiDate.BC(202, Month.DECEMBER, 31))
  }

  "NOW" should "parse as WikiDate.Now" in {
    parser.parse("NOW") shouldEqual Some(WikiDate.Now)
  }

  "GENESIS" should "parse as WikiDate.MinDate" in {
    parser.parse("GENESIS") shouldEqual Some(WikiDate.MinDate)
  }
} 
开发者ID:igor-dobrovolskiy-epam,项目名称:wikipedia-analysis-scala-core,代码行数:44,代码来源:WikiDateParserTest.scala

示例3: WikiDateTest

//设置package包名称以及导入依赖的类
package epam.idobrovolskiy.wikipedia.trending.time

import java.time.Month

import epam.idobrovolskiy.wikipedia.trending.tokenizer.StopWordsTokenizer
import org.scalatest.FunSuite


class WikiDateTest extends FunSuite {
  test("Test WikiDate after Ser-De results in source value") {
    val wd = WikiDate.AD(123, Month.AUGUST, 31)

    assertResult(wd) {
      import java.io._

      // Serialize
      val bo = new ByteArrayOutputStream
      val o = new ObjectOutputStream(bo)
      o.writeObject(wd)
      val bytes = bo.toByteArray

      // Deserialize
      val bi = new ByteArrayInputStream(bytes)
      val i = new ObjectInputStream(bi)
      val t = i.readObject.asInstanceOf[WikiDate]

      t
    }

    //Although the test passes, t holds incorrect representation field values (for year, month, day, etc.). Test should be updated after Ser-De issue is fixed in WikiDate class.
  }

  test("ser calc") {
    val date = WikiDate.deserialize(2233824) // 2129364 //2567655

    println(date)

    println("a-".split('-').mkString("[",",","]"))

    val t = new StopWordsTokenizer
//    val tt = t.getTopNTokens(Seq("""In Ireland, the rebel Irish Catholics formed their own government – Confederate Ireland with the intention of helping the Royalists in return for religious toleration and political autonomy."""))
    val tt = t.getTopNTokens(Seq("""government – Confederate """))
    println(tt)
  }
} 
开发者ID:igor-dobrovolskiy-epam,项目名称:wikipedia-analysis-scala-core,代码行数:46,代码来源:WikiDateTest.scala

示例4: baseEnrichOutput

//设置package包名称以及导入依赖的类
package it.escopelliti.pipeline

import java.time.{LocalDate, Month}

import it.escopelliti.utils.ConfigurationProvider
import org.apache.spark.rdd.RDD

import scala.reflect.ClassTag

trait Pipeline extends Serializable {

  protected def baseEnrichOutput[K: ClassTag, V: ClassTag, W: ClassTag](left: RDD[(K, V)])
                                                                       (right: RDD[(K, W)],
                                                                        month: Month,
                                                                        updateOutput: (V, Option[W], Month) => V): RDD[(K, V)] = {
    left
      .leftOuterJoin(right) // we do not know beforehand if there will be stats for that month
      .mapValues { case (prevOutput, valueOpt) =>
      updateOutput(prevOutput, valueOpt, month)
    }
  }

}

abstract class BasePipeline[K: ClassTag, V: ClassTag, T: ClassTag, W: ClassTag]() extends Pipeline {

  def apply(input: RDD[(K, V)], data: RDD[(K, T)]): RDD[(K, V)] = {
    build(input, data, ConfigurationProvider.getRunDate())
  }

  protected def transform(data: RDD[(K, T)], month: Month, runDate: LocalDate): RDD[(K, W)]

  protected def updateOutput(kpiOut: V, valueOpt: Option[W], month: Month): V

  protected def build(input: RDD[(K, V)], data: RDD[(K, T)], date: LocalDate): RDD[(K, V)] = {

    Month.values().foldLeft(input) {
      case (acc, month) =>
        baseEnrichOutput[K, V, W](acc)(transform(data, month, date), month, updateOutput)
    }
  }
} 
开发者ID:escopelliti,项目名称:timeseries-extraction,代码行数:43,代码来源:Pipeline.scala

示例5: TimeSeriesStatsStep

//设置package包名称以及导入依赖的类
package it.escopelliti.pipeline

import java.time.{LocalDate, Month}

import it.escopelliti.domain.DataValues.{CrossSale, Output, Stats, TimeSeries}
import org.apache.spark.rdd.RDD
import it.escopelliti.utils.DataProcessingUtils._

object TimeSeriesStatsStep {
  def apply: TimeSeriesStatsStep = new TimeSeriesStatsStep()
}

class TimeSeriesStatsStep() extends BasePipeline[String, Output, CrossSale, Stats] {

  def transform(data: RDD[(String, CrossSale)], month: Month, runDate: LocalDate): RDD[(String, Stats)] = {

    data
      .filter {
        case (_, sale) =>
          val saleDate = sale.date
          isDateInMonth(saleDate, month) && isValidDate(saleDate, runDate)
      }
      .aggregateByKey(List.empty[CrossSale])(_ :+ _, _ ++ _)
      .mapValues(Stats(month))
  }

  override protected def updateOutput(previousOutput: Output, valueOpt: Option[Stats], month: Month): Output = {
    val newTimeSeries = valueOpt match {
      case Some(stats) =>
        previousOutput.timeSeries.months + (month.getValue() -> stats)
      case None =>
        previousOutput.timeSeries.months + (month.getValue() -> Stats.emptyStats(month))
    }
    previousOutput.copy(timeSeries = TimeSeries(newTimeSeries))
  }
} 
开发者ID:escopelliti,项目名称:timeseries-extraction,代码行数:37,代码来源:TimeSeriesStatsStep.scala

示例6: RunHistorical

//设置package包名称以及导入依赖的类
package com.temerev.mi.run

import java.io.{FileWriter, File}
import java.time.format.DateTimeFormatter
import java.time.{ZoneId, Duration, LocalDate, Month}

import com.miriamlaurel.fxcore._
import com.miriamlaurel.fxcore.market.Quote
import com.miriamlaurel.fxcore.portfolio.StrictPortfolio
import com.temerev.mi.analytics.{FutureView, Window}
import com.temerev.mi.io.TickReader
import com.temerev.mi.strategy.BreakoutStrategy

import scala.collection.immutable.Queue
import scala.io.Source

object RunHistorical extends App {
  val TZ = ZoneId.of("UTC")
  val reader = new TickReader(new File("/opt/data"))
  val startDate = LocalDate.of(2015, Month.OCTOBER, 1)
  val endDate = LocalDate.of(2015, Month.OCTOBER, 30)
  val format = DateTimeFormatter.ofPattern("yyyy-MM-dd-HH-mm-ss")
  println("Loading ticks...")
  val startTs = System.currentTimeMillis()
  val ticks = reader.getTicks(EURUSD, startDate, endDate).map(_.best)
  val smap = readSeasonalityMap(new File(args(0)))
  val outDir = new File(args(1))
  var view = FutureView(500, Window(Duration.ofHours(1), Duration.ofMinutes(5)), Queue.empty)
  var candidates = Vector.empty[FutureView]
  var count = 0
  var ts = 0L
  val strategy = BreakoutStrategy(new StrictPortfolio(), view.window, smap)
  val result = ticks.foldLeft(strategy)((s: BreakoutStrategy, q: Quote) => s.apply(q))
  result.deals.foreach(println)


  def readSeasonalityMap(file: File): Map[Int, BigDecimal] = {
    val pairs = Source.fromFile(file).getLines().map(s => {
      val tokens = s.split(",")
      (tokens(0).toInt, BigDecimal(tokens(1)))
    })
    Map(pairs.toSeq: _*)
  }
} 
开发者ID:atemerev,项目名称:mi,代码行数:45,代码来源:RunHistorical.scala

示例7: TZDBSpec

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

import java.time.{DayOfWeek, LocalTime, Month, LocalDateTime}

import kuyfi.TZDB._
import org.scalatest.{FlatSpec, Matchers}

import scalaz._
import Scalaz._

class TZDBSpec extends FlatSpec with Matchers {
  "Year ordering" should
    "orders given years" in {
      (GivenYear(2001): RuleYear) <= (GivenYear(2002): RuleYear) shouldBe true
      (GivenYear(2004): RuleYear) >= (GivenYear(2002): RuleYear) shouldBe true
      (GivenYear(2004): RuleYear) == (GivenYear(2004): RuleYear) shouldBe true
    }
    it should "make everything less than Maximum" in {
      (GivenYear(2001): RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Minimum: RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Only: RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Maximum: RuleYear) >= (Maximum: RuleYear) && (Maximum: RuleYear) <= (Maximum: RuleYear) shouldBe true
    }
    it should "make everything more than Maximum" in {
      (GivenYear(2001): RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Minimum: RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Only: RuleYear) <= (Maximum: RuleYear) shouldBe true
      (Minimum: RuleYear) >= (Minimum: RuleYear) && (Minimum: RuleYear) <= (Minimum: RuleYear) shouldBe true
    }
    it should "make everything equal to Only" in {
      (GivenYear(2001): RuleYear) >= (Only: RuleYear) shouldBe true
      (Minimum: RuleYear) >=(Only: RuleYear) shouldBe true
      (Maximum: RuleYear) >= (Only: RuleYear) shouldBe true
      (Only: RuleYear) <= (Only: RuleYear) && (Only: RuleYear) >= (Only: RuleYear) shouldBe true
    }

  "Until" should
    "calculate date time" in {
      val until = Until(1998,Some(Month.APRIL),Some(AfterWeekday(DayOfWeek.SUNDAY,1)),Some(AtWallTime(LocalTime.of(3, 0), endOfDay = false)))
      until.toDateTime shouldBe LocalDateTime.of(1998, Month.APRIL, 5, 3, 0)
      until.toDateTime shouldBe LocalDateTime.of(1998, Month.APRIL, 5, 3, 0)
    }

  "On" should
    "calculate day on a year" in {
      val on = AfterWeekday(DayOfWeek.SUNDAY, 1)
      on.dayOnYear(1998, Month.APRIL) shouldBe 5
      val on2 = DayOfTheMonth(5)
      on2.dayOnYear(1998, Month.APRIL) shouldBe 5
    }
} 
开发者ID:cquiroz,项目名称:kuyfi,代码行数:52,代码来源:TZDBSpec.scala

示例8: Main

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

import java.time.{LocalDate, LocalDateTime, LocalTime, Month}

import dtc.instances.localDateTime._

// scalastyle:off
object Main extends App {

  val calendar = Calendar(List(
    CalendarEvent(
      LocalDateTime.of(LocalDate.now(), LocalTime.of(10, 0)),
      LocalDateTime.of(LocalDate.now(), LocalTime.of(11, 0)),
      "Breakfast"
    ),
    CalendarEvent(
      LocalDateTime.of(LocalDate.now().minusDays(2), LocalTime.of(12, 0)),
      LocalDateTime.of(LocalDate.now().minusDays(2), LocalTime.of(14, 0)),
      "Meeting"
    ),
    CalendarEvent(
      LocalDateTime.of(2016, Month.OCTOBER, 9, 11, 0),
      LocalDateTime.of(2016, Month.OCTOBER, 9, 11, 0),
      "Birthday party"
    )
  ))

  println(calendar.eventsAfter(LocalDateTime.now().minusDays(1L)).mkString(", "))
  println(calendar.onlyWorkDays.mkString(", "))

  val period = Period(LocalDateTime.now(), LocalDateTime.now().plusDays(1L))
  println(period.durationInMinutes)
  println(period.durationInSeconds)
  println(period.hours.mkString("\n"))
} 
开发者ID:vpavkin,项目名称:dtc,代码行数:36,代码来源:Main.scala

示例9: EtcdJsonProtocolSpec

//设置package包名称以及导入依赖的类
package me.maciejb.etcd.client.impl

import java.time.Month

import me.maciejb.etcd.client.EtcdNode
import org.scalatest.{FlatSpec, Matchers}
import spray.json._

class EtcdJsonProtocolSpec extends FlatSpec with Matchers {

  import EtcdJsonProtocol._

  "EtcdJsonProtocol" should "deserialize node with defined expiration time" in {
    val node = """{
      "createdIndex": 17,
      "dir": true,
      "expiration": "2013-12-11T10:37:33.689275857-08:00",
      "key": "/dir",
      "modifiedIndex": 17,
      "ttl": 30
    }""".parseJson.convertTo[EtcdNode]
    node.expiration match {
      case Some(i) ?
        i.getYear shouldBe 2013
        i.getMonth shouldBe Month.DECEMBER
        i.getDayOfMonth shouldBe 11
      case _ ? fail
    }
  }

} 
开发者ID:maciej,项目名称:etcd-client,代码行数:32,代码来源:EtcdJsonProtocolSpec.scala

示例10: VolunteerCSVReader

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

import java.io.File
import java.time.Month

import Core.{Availability, Person}
import com.github.tototoshi.csv.CSVReader

case class VolunteerCSVReader(filename: String) {
  private val reader = CSVReader.open(new File(filename))
  private val raw: List[Map[String, String]] = reader.allWithHeaders()

  private def availability(row: Map[String,String], tentativeMeansAvailable: Boolean) : Availability = {
    val sun = "Available Sun 6/12"    -> Availability.AllDay(2016, Month.JUNE, 12)
    val mon = "Available Mon 6/13"    -> Availability.AllDay(2016, Month.JUNE, 13)
    val tue = "Available Tue 6/14"    -> Availability.AllDay(2016, Month.JUNE, 14)
    val wed = "Available Wed 6/15"    -> Availability.AllDay(2016, Month.JUNE, 15)
    val thu = "Available Thurs 6/16"  -> Availability.AllDay(2016, Month.JUNE, 16)
    val fri = "Available Fri 6/17"    -> Availability.AllDay(2016, Month.JUNE, 17)

    val days = List(sun, mon, tue, wed, thu, fri)

    // compute availability
    days.foldLeft(Availability.NotAvailable){ case (acc,(key,avail)) =>
        if (row(key) == "Y"
            || (if (tentativeMeansAvailable) { row(key) == "T" } else { false })) {
          acc + avail
        } else {
          acc
        }
    }
  }

  def people(tentativeMeansAvailable: Boolean) : (Set[Person],Set[Person]) = {
    val allPeople = raw.flatMap { row =>
      if (row("Can Serve (confirmed)") == "Y") {
        val avail = availability(row, tentativeMeansAvailable)

        Some(
          Person(
            row("First name"),
            row("Last name"),
            avail
          )
        )
      } else {
        None
      }
    }.toSet

    allPeople.partition { person => person.availability != Availability.NotAvailable }
  }
} 
开发者ID:dbarowy,项目名称:schedulous,代码行数:54,代码来源:VolunteerCSVReader.scala


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