本文整理汇总了Scala中org.joda.time.DateTimeUtils类的典型用法代码示例。如果您正苦于以下问题:Scala DateTimeUtils类的具体用法?Scala DateTimeUtils怎么用?Scala DateTimeUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTimeUtils类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: Id64
//设置package包名称以及导入依赖的类
package utils
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
object Id64 {
val EPOCH = 1288834974657L //Twepoch (4 Nov 2010 01:42:54.657 GMT)
val RANDOM_BIT = 22
val MAX_RANDOM = 1 << RANDOM_BIT
val MAX_TIME = 1L << (63 - RANDOM_BIT)
private val sr = new SecureRandom()
private val counterStart = Random.nextInt(MAX_RANDOM)
private val counter = new AtomicLong(counterStart)
def time() = DateTimeUtils.currentTimeMillis()
def nextAscId() = nextSeqAscId()
def nextDescId() = nextSeqDescId()
def nextSeqAscId(now: Long = time()) =
makeAscId(now, (counter.getAndIncrement % MAX_RANDOM).toInt)
def nextSeqDescId(now: Long = time()) = {
val r = (counterStart - counter.getAndIncrement) % MAX_RANDOM
makeDescId(now, (if (r < 0) r + MAX_RANDOM else r).toInt)
}
def nextPseRandId(make: (Long, Int) => Long = makeAscId, now: Long = time()) =
make(now, Random.nextInt(MAX_RANDOM))
def nextSecRandId(make: (Long, Int) => Long = makeAscId, now: Long = time()) =
make(now, sr.nextInt(MAX_RANDOM))
def parseId(id: Long, descending: Boolean = false): (Long, Int) = {
val ts = id >> RANDOM_BIT
val time = if (descending) MAX_TIME - (ts - EPOCH) else EPOCH + ts
val rand = id & (MAX_RANDOM - 1)
(time, rand.toInt)
}
def makeAscId(now: Long, rnd: Int): Long = {
val sinceEpoch = now - EPOCH
(sinceEpoch << RANDOM_BIT) | rnd
}
def makeDescId(now: Long, rnd: Int): Long = {
val ts = MAX_TIME - (now - EPOCH)
(ts << RANDOM_BIT) | rnd
}
}
开发者ID:FScoward,项目名称:ticketman,代码行数:56,代码来源:Id64.scala
示例2: HalfDayTopicManagerSpec
//设置package包名称以及导入依赖的类
package articlestreamer.shared.kafka
import articlestreamer.shared.BaseSpec
import articlestreamer.shared.configuration.ConfigLoader
import org.joda.time.DateTimeUtils
class HalfDayTopicManagerSpec extends BaseSpec {
class TestConfig extends ConfigLoader {
override val kafkaFirstTopic: String = "topic1"
override val kafkaSecondTopic: String = "topic2"
}
val config = new TestConfig
val topicManager = new HalfDayTopicManager(config)
"HalfDayTopicManager" should "give first topic as current topic during morning" in {
DateTimeUtils.setCurrentMillisFixed(1182128400000l)
topicManager.getCurrentTopic() shouldBe "topic1"
DateTimeUtils.setCurrentMillisSystem()
}
it should "give second topic as current topic during afternoon" in {
DateTimeUtils.setCurrentMillisFixed(1182171600000l)
topicManager.getCurrentTopic() shouldBe "topic2"
DateTimeUtils.setCurrentMillisSystem()
}
it should "give second topic as not current topic during morning" in {
DateTimeUtils.setCurrentMillisFixed(1182128400000l)
topicManager.getNotCurrentTopic() shouldBe "topic2"
DateTimeUtils.setCurrentMillisSystem()
}
it should "give first topic as not current topic during afternoon" in {
DateTimeUtils.setCurrentMillisFixed(1182171600000l)
topicManager.getNotCurrentTopic() shouldBe "topic1"
DateTimeUtils.setCurrentMillisSystem()
}
it should "give first topic as current topic at midnight" in {
DateTimeUtils.setCurrentMillisFixed(1182124800000l)
topicManager.getCurrentTopic() shouldBe "topic1"
DateTimeUtils.setCurrentMillisSystem()
}
it should "return second topic at noon" in {
DateTimeUtils.setCurrentMillisFixed(1182168000000l)
topicManager.getCurrentTopic() shouldBe "topic2"
DateTimeUtils.setCurrentMillisSystem()
}
}
开发者ID:firens,项目名称:article-streamer,代码行数:54,代码来源:HalfDayTopicManagerSpec.scala
示例3: Id64
//设置package包名称以及导入依赖的类
package util
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
object Id64 {
val EPOCH = 1288834974657L //Twepoch (4 Nov 2010 01:42:54.657 GMT)
val RANDOM_BIT = 22
val MAX_RANDOM = 1 << RANDOM_BIT
val MAX_TIME = 1L << (63 - RANDOM_BIT)
private val sr = new SecureRandom()
private val counterStart = Random.nextInt(MAX_RANDOM)
private val counter = new AtomicLong(counterStart)
def time() = DateTimeUtils.currentTimeMillis()
def nextAscId() = nextSeqAscId()
def nextDescId() = nextSeqDescId()
def nextSeqAscId(now: Long = time()) =
makeAscId(now, (counter.getAndIncrement % MAX_RANDOM).toInt)
def nextSeqDescId(now: Long = time()) = {
val r = (counterStart - counter.getAndIncrement) % MAX_RANDOM
makeDescId(now, (if (r < 0) r + MAX_RANDOM else r).toInt)
}
def nextPseRandId(make: (Long, Int) => Long = makeAscId, now: Long = time()) =
make(now, Random.nextInt(MAX_RANDOM))
def nextSecRandId(make: (Long, Int) => Long = makeAscId, now: Long = time()) =
make(now, sr.nextInt(MAX_RANDOM))
def parseId(id: Long, descending: Boolean = false): (Long, Int) = {
val ts = id >> RANDOM_BIT
val time = if (descending) MAX_TIME - (ts - EPOCH) else EPOCH + ts
val rand = id & (MAX_RANDOM - 1)
(time, rand.toInt)
}
def makeAscId(now: Long, rnd: Int): Long = {
val sinceEpoch = now - EPOCH
(sinceEpoch << RANDOM_BIT) | rnd
}
def makeDescId(now: Long, rnd: Int): Long = {
val ts = MAX_TIME - (now - EPOCH)
(ts << RANDOM_BIT) | rnd
}
}
开发者ID:FScoward,项目名称:billets-en-concert,代码行数:56,代码来源:Id64.scala
示例4: Configuration
//设置package包名称以及导入依赖的类
import cjp.catalogue.mongo.MongoConnector
import cjp.catalogue.mongo.SalatContext._
import cjp.catalogue.repository._
import cjp.catalogue.resource._
import cjp.catalogue.service._
import cjp.catalogue.util.BuildInfo
import com.typesafe.config.{Config, ConfigFactory}
import org.joda.time.DateTimeUtils
import play.api._
import play.api.mvc.Controller
object Configuration {
val conf: Config = ConfigFactory.load()
val dbHosts = conf.getString("mongo.catalogue.hosts")
val dbName = conf.getString("mongo.catalogue.db")
val dbOptions = conf.getString("mongo.catalogue.options")
val dbUrl = s"mongodb://$dbHosts/$dbName?$dbOptions"
val enableTimemachine = conf.getBoolean("enableTimemachine")
}
object ComponentRegistry {
defaultCtx.registerClassLoader(Play.classloader(Play.current))
defaultCtx.registerClassLoader(Play.classloader(Play.current))
private val mongo = new MongoConnector(Configuration.dbUrl)
private val productRepository = new ProductRepository(mongo)
private val productTimelineRepository = new ProductTimelineRepository(mongo)
private val attributeRepository = new AttributeRepository(mongo)
private val effectiveDateRepository = new EffectiveDateRepository(mongo)
private val attributeService = new AttributeService(attributeRepository)
private val productService = new ProductManagementService(productRepository, productTimelineRepository, attributeService)
private val exportImportService = new ExportImportService(productRepository, productTimelineRepository, attributeService)
private val addOnsService = new AddOnService(productRepository)
if (Configuration.enableTimemachine) {
DateTimeUtils.setCurrentMillisProvider(new TimeMachineMillisProvider(effectiveDateRepository))
}
private val controllers: Map[Class[_], Controller] = Seq(
new ProductResource(productService, attributeService),
new ManageProductResource(productService),
new AttributeResource(attributeService),
new EffectiveDateResource(effectiveDateRepository, Configuration.enableTimemachine),
new ExportImportResource(exportImportService, new CatalogueImportValidator),
new HealthCheckResource(new MongoHealthCheck(mongo), BuildInfo.fromApplicationConfig),
new AddOnsResource(addOnsService)
).map { c =>
c.getClass -> c
}.toMap[Class[_], Controller]
def getController[A](controllerClass: Class[A]): A = controllers(controllerClass).asInstanceOf[A]
}
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:59,代码来源:ComponentRegistry.scala
示例5: ExportImportServiceSpec
//设置package包名称以及导入依赖的类
package cjp.catalogue.service
import cjp.catalogue.model.{CatalogueAttributeDefinition, PersistedCatalogueProduct, ProductTimeline, TimelineVersion}
import cjp.catalogue.repository.{ProductRepository, ProductTimelineRepository}
import cjp.catalogue.test.builder.{CatalogueProductBuilder, ServiceAddOnBuilder}
import org.joda.time.{DateTime, DateTimeUtils}
import org.mockito.Mockito._
import org.scalatest.mock.MockitoSugar
import org.scalatest.{BeforeAndAfter, Matchers, WordSpec}
class ExportImportServiceSpec extends WordSpec with BeforeAndAfter with Matchers with MockitoSugar {
val productRepository = mock[ProductRepository]
val productTimelineRepository = mock[ProductTimelineRepository]
val attributeService = mock[AttributeService]
val exportImportService = new ExportImportService(productRepository, productTimelineRepository, attributeService)
val now = DateTime.now()
before {
reset(productRepository, productTimelineRepository)
DateTimeUtils.setCurrentMillisFixed(now.getMillis)
}
after {
DateTimeUtils.setCurrentMillisSystem()
}
"export" should {
"include attributes service addOns and all product versions referenced by time line" in {
when(productTimelineRepository.findAll).thenReturn(List(ProductTimeline(productName = "A", versions = List(
TimelineVersion(0, now.minusDays(20)),
TimelineVersion(1, now)
))))
val catalogueProduct0: PersistedCatalogueProduct = CatalogueProductBuilder(title = "0 title").toPersistedCatalogueProduct(0)
val catalogueProduct1: PersistedCatalogueProduct = CatalogueProductBuilder(title = "1 title").toPersistedCatalogueProduct(1)
val catalogueAttributes = List(CatalogueAttributeDefinition("attr", "", "very kind", false, "facet"))
when(productRepository.findByNameAndVersion("A", 0)).thenReturn(Some(catalogueProduct0))
when(productRepository.findByNameAndVersion("A", 1)).thenReturn(Some(catalogueProduct1))
when(attributeService.catalogueAttributes).thenReturn(catalogueAttributes)
exportImportService.export shouldBe CatalogueData(
attributes = catalogueAttributes,
products = Map("A" -> ProductExport(Map("0" -> catalogueProduct0, "1" -> catalogueProduct1), List(TimelineVersion(0, now.minusDays(20)), TimelineVersion(1, now))))
)
}
}
}
开发者ID:UKHomeOffice,项目名称:product-catalogue,代码行数:53,代码来源:ExportImportServiceSpec.scala
示例6: Id64
//设置package包名称以及导入依赖的类
package util
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
object Id64 {
val EPOCH = 1288834974657L //Twepoch (4 Nov 2010 01:42:54.657 GMT)
val RANDOM_BIT = 22
val MAX_RANDOM = 1 << RANDOM_BIT
val MAX_TIME = 1L << (63 - RANDOM_BIT)
private val sr = new SecureRandom()
private val counterStart = Random.nextInt(MAX_RANDOM)
private val counter = new AtomicLong(counterStart)
def time() = DateTimeUtils.currentTimeMillis()
def nextAscId() = nextSeqAscId()
def nextDescId() = nextSeqDescId()
def nextSeqAscId(now: Long = time()) =
makeAscId(now, (counter.getAndIncrement % MAX_RANDOM).toInt)
def nextSeqDescId(now: Long = time()) = {
val r = (counterStart - counter.getAndIncrement) % MAX_RANDOM
makeDescId(now, (if (r < 0) r + MAX_RANDOM else r).toInt)
}
def nextPseRandId(make: (Long,Int) => Long = makeAscId, now: Long = time()) =
make(now, Random.nextInt(MAX_RANDOM))
def nextSecRandId(make: (Long,Int) => Long = makeAscId, now: Long = time()) =
make(now, sr.nextInt(MAX_RANDOM))
def parseId(id: Long, descending: Boolean = false): (Long, Int) = {
val ts = id >> RANDOM_BIT
val time = if (descending) MAX_TIME - (ts - EPOCH) else EPOCH + ts
val rand = id & (MAX_RANDOM - 1)
(time, rand.toInt)
}
def makeAscId(now: Long, rnd: Int): Long = {
val sinceEpoch = now - EPOCH
(sinceEpoch << RANDOM_BIT) | rnd
}
def makeDescId(now: Long, rnd: Int): Long = {
val ts = MAX_TIME - (now - EPOCH)
(ts << RANDOM_BIT) | rnd
}
}
开发者ID:FScoward,项目名称:tuner,代码行数:55,代码来源:Id64.scala
示例7: Id64
//设置package包名称以及导入依赖的类
package utils
import scala.util.Random
import java.security.SecureRandom
import java.util.concurrent.atomic.AtomicLong
import org.joda.time.DateTimeUtils
object Id64 {
val EPOCH = 1288834974657L //Twepoch (4 Nov 2010 01:42:54.657 GMT)
val RANDOM_BIT = 22
val MAX_RANDOM = 1 << RANDOM_BIT
val MAX_TIME = 1L << (63 - RANDOM_BIT)
private val sr = new SecureRandom()
private val counterStart = Random.nextInt(MAX_RANDOM)
private val counter = new AtomicLong(counterStart)
def time() = DateTimeUtils.currentTimeMillis()
def nextAscId() = nextSeqAscId()
def nextDescId() = nextSeqDescId()
def nextSeqAscId(now: Long = time()) =
makeAscId(now, (counter.getAndIncrement % MAX_RANDOM).toInt)
def nextSeqDescId(now: Long = time()) = {
val r = (counterStart - counter.getAndIncrement) % MAX_RANDOM
makeDescId(now, (if (r < 0) r + MAX_RANDOM else r).toInt)
}
def nextPseRandId(make: (Long,Int) => Long = makeAscId, now: Long = time()) =
make(now, Random.nextInt(MAX_RANDOM))
def nextSecRandId(make: (Long,Int) => Long = makeAscId, now: Long = time()) =
make(now, sr.nextInt(MAX_RANDOM))
def parseId(id: Long, descending: Boolean = false): (Long, Int) = {
val ts = id >> RANDOM_BIT
val time = if (descending) MAX_TIME - (ts - EPOCH) else EPOCH + ts
val rand = id & (MAX_RANDOM - 1)
(time, rand.toInt)
}
def makeAscId(now: Long, rnd: Int): Long = {
val sinceEpoch = now - EPOCH
(sinceEpoch << RANDOM_BIT) | rnd
}
def makeDescId(now: Long, rnd: Int): Long = {
val ts = MAX_TIME - (now - EPOCH)
(ts << RANDOM_BIT) | rnd
}
}
开发者ID:FScoward,项目名称:group-communicator-api,代码行数:56,代码来源:Id64.scala
注:本文中的org.joda.time.DateTimeUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论