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


Java OffsetTime类代码示例

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


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

示例1: testSerialisation

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
/**
 * Tests that serialising to JSON works.
 */
@Test
public void testSerialisation() throws Exception
{
  final Gson gson = Converters.registerAll(new GsonBuilder()).create();

  final Container container = new Container();
  container.ld = LocalDate.of(1969, 7, 21);
  container.lt = LocalTime.of(12, 56, 0);
  container.ldt = LocalDateTime.of(container.ld, container.lt);
  container.odt = OffsetDateTime.of(container.ld, container.lt, ZoneOffset.ofHours(10));
  container.ot = OffsetTime.of(container.lt, ZoneOffset.ofHours(10));
  container.zdt = ZonedDateTime.of(container.ld, container.lt, ZoneId.of("Australia/Brisbane"));
  container.i = container.odt.toInstant();

  final String jsonString = gson.toJson(container);
  final JsonObject json = gson.fromJson(jsonString, JsonObject.class).getAsJsonObject();

  assertThat(json.get("ld").getAsString(), is("1969-07-21"));
  assertThat(json.get("lt").getAsString(), is("12:56:00"));
  assertThat(json.get("ldt").getAsString(), is("1969-07-21T12:56:00"));
  assertThat(json.get("odt").getAsString(), is("1969-07-21T12:56:00+10:00"));
  assertThat(json.get("ot").getAsString(), is("12:56:00+10:00"));
  assertThat(json.get("zdt").getAsString(), is("1969-07-21T12:56:00+10:00[Australia/Brisbane]"));
  assertThat(json.get("i").getAsString(), is("1969-07-21T02:56:00Z"));
}
 
开发者ID:gkopff,项目名称:gson-threeten-serialisers,代码行数:29,代码来源:ConvertersTest.java

示例2: convert

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
public InterestRateFutureTransactionDefinition convert(final Trade trade) {
  Validate.notNull(trade, "trade");
  Validate.isTrue(trade.getSecurity() instanceof InterestRateFutureSecurity, "Can only handle trades with security type InterestRateFutureSecurity");
  final InterestRateFutureSecurityDefinition securityDefinition = _securityConverter.visitInterestRateFutureSecurity((InterestRateFutureSecurity) trade.getSecurity());
  final int quantity = trade.getQuantity().intValue();
  final LocalDate tradeDate = trade.getTradeDate();
  if (tradeDate == null) {
    throw new OpenGammaRuntimeException("Trade date should not be null");
  }
  final OffsetTime tradeTime = trade.getTradeTime();
  if (tradeTime == null) {
    throw new OpenGammaRuntimeException("Trade time should not be null");
  }
  final ZonedDateTime tradeDateTime = tradeDate.atTime(tradeTime).atZoneSameInstant(ZoneOffset.UTC);
  Double tradePrice = trade.getPremium(); // TODO: [PLAT-1958] The trade price is stored in the trade premium.
  if (tradePrice == null) {
    throw new OpenGammaRuntimeException("Trade premium should not be null.");
  }
  return new InterestRateFutureTransactionDefinition(securityDefinition, quantity, tradeDateTime, tradePrice);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:InterestRateFutureTradeConverterDeprecated.java

示例3: convert

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
public InstrumentDefinitionWithData<?, Double> convert(Trade trade) {
  ArgumentChecker.notNull(trade, "trade");
  final Security security = trade.getSecurity();
  if (security instanceof DeliverableSwapFutureSecurity) {
    final SwapFuturesPriceDeliverableSecurityDefinition securityDefinition = (SwapFuturesPriceDeliverableSecurityDefinition) ((DeliverableSwapFutureSecurity) security).accept(_securityConverter);
    Double tradePrice = trade.getPremium(); // TODO: [PLAT-1958] The trade price is stored in the trade premium. 
    if (tradePrice == null) {
      throw new OpenGammaRuntimeException("Trade premium should not be null.");
    }
    final LocalDate tradeDate = trade.getTradeDate();
    if (tradeDate == null) {
      throw new OpenGammaRuntimeException("Trade date should not be null");
    }
    final OffsetTime tradeTime = trade.getTradeTime();
    if (tradeTime == null) {
      throw new OpenGammaRuntimeException("Trade time should not be null");
    }
    final ZonedDateTime tradeDateTime = tradeDate.atTime(tradeTime).atZoneSameInstant(ZoneOffset.UTC);
    final int quantity = trade.getQuantity().intValue();
    return new SwapFuturesPriceDeliverableTransactionDefinition(securityDefinition, quantity, tradeDateTime, tradePrice);
  }
  throw new IllegalArgumentException("Can only handle DeliverableSwapFutureSecurity");
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:DeliverableSwapFutureTradeConverter.java

示例4: convert

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
public InstrumentDefinitionWithData<?, DoubleTimeSeries<ZonedDateTime>[]> convert(final Trade trade) { //CSIGNORE
  ArgumentChecker.notNull(trade, "trade");
  final Security security = trade.getSecurity();
  if (security instanceof FederalFundsFutureSecurity) {
    final FederalFundsFutureSecurityDefinition securityDefinition = (FederalFundsFutureSecurityDefinition) ((FederalFundsFutureSecurity) security).accept(_securityConverter);
    Double tradePrice = trade.getPremium(); // TODO: [PLAT-1958] The trade price is stored in the trade premium. 
    if (tradePrice == null) {
      throw new OpenGammaRuntimeException("Trade premium should not be null.");
    }
    final LocalDate tradeDate = trade.getTradeDate();
    if (tradeDate == null) {
      throw new OpenGammaRuntimeException("Trade date should not be null");
    }
    final OffsetTime tradeTime = trade.getTradeTime();
    if (tradeTime == null) {
      throw new OpenGammaRuntimeException("Trade time should not be null");
    }
    final ZonedDateTime tradeDateTime = tradeDate.atTime(tradeTime).atZoneSameInstant(ZoneOffset.UTC);
    final int quantity = trade.getQuantity().intValue();
    return new FederalFundsFutureTransactionDefinition(securityDefinition, quantity, tradeDateTime, tradePrice);
  }
  throw new IllegalArgumentException("Can only handle FederalFundsFutureSecurity");
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:FederalFundsFutureTradeConverter.java

示例5: convert

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
public InstrumentDefinitionWithData<?, Double> convert(Trade trade) {
  ArgumentChecker.notNull(trade, "trade");
  final Security security = trade.getSecurity();
  if (security instanceof InterestRateFutureSecurity) {
    final InterestRateFutureSecurityDefinition securityDefinition = (InterestRateFutureSecurityDefinition) ((InterestRateFutureSecurity) security).accept(_securityConverter);
    Double tradePrice = trade.getPremium(); // TODO: [PLAT-1958] The trade price is stored in the trade premium. 
    if (tradePrice == null) {
      throw new OpenGammaRuntimeException("Trade premium should not be null.");
    }
    final LocalDate tradeDate = trade.getTradeDate();
    if (tradeDate == null) {
      throw new OpenGammaRuntimeException("Trade date should not be null");
    }
    final OffsetTime tradeTime = trade.getTradeTime();
    if (tradeTime == null) {
      throw new OpenGammaRuntimeException("Trade time should not be null");
    }
    final ZonedDateTime tradeDateTime = tradeDate.atTime(tradeTime).atZoneSameInstant(ZoneOffset.UTC);
    final int quantity = trade.getQuantity().intValue();
    return new InterestRateFutureTransactionDefinition(securityDefinition, quantity, tradeDateTime, tradePrice);
  }
  throw new IllegalArgumentException("Can only handle InterestRateFutureSecurity");
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:InterestRateFutureTradeConverter.java

示例6: createInterestRateFutureTrade

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
private InterestRateFutureTrade createInterestRateFutureTrade(InterestRateFutureSecurity security,
                                                              SimpleCounterparty counterparty,
                                                              boolean pass) {
  BigDecimal tradeQuantity = BigDecimal.valueOf(10);
  LocalDate tradeDate = LocalDate.of(2000, 1, 1);
  OffsetTime tradeTime = OffsetTime.of(LocalTime.of(0, 0), ZoneOffset.UTC);
  SimpleTrade trade = new SimpleTrade(security, tradeQuantity, counterparty, tradeDate, tradeTime);
  trade.setPremium(0.0);
  trade.setPremiumCurrency(security.getCurrency());
  if (pass) {
    trade.addAttribute("TEST", "PASS");
  } else {
    trade.addAttribute("TEST", "FAIL");
  }

  return new InterestRateFutureTrade(trade);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:ExposureFunctionTest.java

示例7: testEmptyCurveConfigs

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
@Test
public void testEmptyCurveConfigs() {
  ConfigMaster configMaster = new InMemoryConfigMaster();
  ConfigSource configSource = new MasterConfigSource(configMaster);
  SecuritySource securitySource = new MasterSecuritySource(new InMemorySecurityMaster());

  String name = "test";
  List<String> exposureFunctions = Lists.newArrayList(CurrencyExposureFunction.NAME);
  Map<ExternalId, String> idsToNames = Maps.newHashMap();
  ExposureFunctions exposures = new ExposureFunctions(name, exposureFunctions, idsToNames);
  ConfigMasterUtils.storeByName(configMaster, ConfigItem.of(exposures));

  ConfigDBInstrumentExposuresProvider provider = new ConfigDBInstrumentExposuresProvider(configSource, securitySource, VersionCorrection.LATEST);

  FRASecurity security = ExposureFunctionTestHelper.getFRASecurity();
  Trade trade = new SimpleTrade(security, BigDecimal.ONE, new SimpleCounterparty(ExternalId.of(Counterparty.DEFAULT_SCHEME, "TEST")), LocalDate.now(), OffsetTime.now());
  try {
    provider.getCurveConstructionConfigurationsForConfig(name, trade);
    fail("Expected exception for empty curve configs");
  } catch (OpenGammaRuntimeException e) {
    // test has passed
  }
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:ConfigDBInstrumentExposuresProviderTest.java

示例8: test_addWithOneTrade_addThenGet

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
@Test
public void test_addWithOneTrade_addThenGet() {
  ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
  
  LocalDate tradeDate = _now.toLocalDate();
  OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
  
  ManageableTrade trade = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
  trade.setProviderId(ExternalId.of("TRD", "123"));
  position.getTrades().add(trade);
  
  PositionDocument doc = new PositionDocument();
  doc.setPosition(position);
  PositionDocument added = _posMaster.add(doc);
  assertNotNull(added);
  assertNotNull(added.getUniqueId());
  
  PositionDocument fromDb = _posMaster.get(added.getUniqueId());
  assertNotNull(fromDb);
  assertNotNull(fromDb.getUniqueId());
  
  assertEquals(added, fromDb);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:24,代码来源:ModifyPositionDbPositionMasterWorkerAddPositionTest.java

示例9: test_addTradeDeal_addThenGet

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
@Test
  public void test_addTradeDeal_addThenGet() {
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    
    LocalDate tradeDate = _now.toLocalDate();
    OffsetTime tradeTime = _now.toOffsetTime().minusSeconds(500);
    ManageableTrade trade = new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), tradeDate, tradeTime, ExternalId.of("CPS", "CPV"));
    trade.addAttribute("TA1", "C");
    trade.addAttribute("TA2", "D");
//    trade.setDeal(new MockDeal("propOne", "propTwo"));  // TODO: test deal persistence
    position.getTrades().add(trade);
    
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument added = _posMaster.add(doc);
    assertNotNull(added);
    assertNotNull(added.getUniqueId());
    
    PositionDocument fromDb = _posMaster.get(added.getUniqueId());
    assertNotNull(fromDb);
    assertNotNull(fromDb.getUniqueId());
    
    assertEquals(added, fromDb);
  }
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:25,代码来源:ModifyPositionDbPositionMasterWorkerAddPositionTest.java

示例10: testInstanceOf

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
/**
 * Tests if the validation check for the security type is working correctly.
 */
public void testInstanceOf() {
  Expiry expiry = new Expiry(ZonedDateTime.of(LocalDate.of(2014, 6, 18), LocalTime.of(0, 0), ZoneOffset.UTC));
  String tradingExchange = "";
  String settlementExchange = "";
  Currency currency = Currency.USD;
  double unitAmount = 1000;
  ExternalId underlyingId = ExternalId.of("first", "second");
  String category = "";
  InterestRateFutureSecurity irFuture = new InterestRateFutureSecurity(expiry, tradingExchange, settlementExchange, currency, unitAmount, underlyingId, category);
  Counterparty counterparty = new SimpleCounterparty(ExternalId.of(Counterparty.DEFAULT_SCHEME, "COUNTERPARTY"));
  BigDecimal tradeQuantity = BigDecimal.valueOf(10);
  LocalDate tradeDate = LocalDate.of(2000, 1, 1);
  OffsetTime tradeTime = OffsetTime.of(LocalTime.of(0, 0), ZoneOffset.UTC);
  SimpleTrade trade = new SimpleTrade(irFuture, tradeQuantity, counterparty, tradeDate, tradeTime);
  
  new InterestRateFutureTrade(trade);
  
  try {
    new BondFutureTrade(trade);
    fail("TradeWrapper instanceof validation is not working");
  } catch(Exception e) {
    // expected
  }
  
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:29,代码来源:TradeWrapperTest.java

示例11: testFull

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
public void testFull() {
  SimpleTrade trade = new SimpleTrade();
  trade.setUniqueId(UniqueId.of("A", "B"));
  trade.setQuantity(BigDecimal.valueOf(12.34d));
  trade.setSecurityLink(new SimpleSecurityLink(ExternalId.of("E", "F")));
  trade.setCounterparty(new SimpleCounterparty(ExternalId.of("G", "H")));
  trade.setTradeDate(LocalDate.of(2011, 1, 5));
  trade.setTradeTime(OffsetTime.parse("14:30+02:00"));
  
  //set premium
  trade.setPremium(100.00);
  trade.setPremiumCurrency(Currency.USD);
  trade.setPremiumDate(LocalDate.of(2011, 1, 6));
  trade.setPremiumTime(OffsetTime.parse("15:30+02:00"));
  
  //set attributes
  trade.addAttribute("A", "B");
  trade.addAttribute("C", "D");
  assertEncodeDecodeCycle(Trade.class, trade);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:21,代码来源:TradeFudgeEncodingTest.java

示例12: testTrade_withPremium

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
@SuppressWarnings("deprecation")
public void testTrade_withPremium() {
  SimpleTrade trade = new SimpleTrade();
  trade.setUniqueId(UniqueId.of("A", "B"));
  trade.setQuantity(BigDecimal.valueOf(12.34d));
  trade.setSecurityLink(new SimpleSecurityLink(ObjectId.of("E", "F")));
  trade.setCounterparty(new SimpleCounterparty(ExternalId.of("G", "H")));
  trade.setTradeDate(LocalDate.of(2011, 1, 5));
  trade.setTradeTime(OffsetTime.parse("14:30+02:00"));
  
  //set premium
  trade.setPremium(100.00);
  trade.setPremiumCurrency(Currency.USD);
  trade.setPremiumDate(LocalDate.of(2011, 1, 6));
  trade.setPremiumTime(OffsetTime.parse("15:30+02:00"));
  assertEncodeDecodeCycle(Trade.class, trade);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:18,代码来源:TradeFudgeEncodingTest.java

示例13: testCannotInsertTradeWithEmptySecurityIdBundle

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
@Test(expectedExceptions = OpenGammaRuntimeException.class)
public void testCannotInsertTradeWithEmptySecurityIdBundle() {

  PortfolioWriter persister = new PortfolioWriter(true, mockPortfolioMaster(), mockPositionMaster(),
                                                  mockSecurityMaster());

  String portfolioName = "TestPortfolio";
  SimplePortfolioNode root = new SimplePortfolioNode(portfolioName);
  ExternalIdBundle securityKey = ExternalIdBundle.of("TEST", "1234");
  ManageableSecurity security = new ManageableSecurity("SEC_TYPE_TEST");
  security.setName("TestSec");
  security.setExternalIdBundle(securityKey);
  Set<ManageableSecurity> securities = ImmutableSet.of(security);

  // Create position with empty Id bundle
  SimplePosition position = new SimplePosition(BigDecimal.valueOf(1000), securityKey);
  position.addTrade(new SimpleTrade(new SimpleSecurityLink(ExternalIdBundle.EMPTY), BigDecimal.valueOf(1000),
                                    new SimpleCounterparty(ExternalId.of("CP", "123")), LocalDate.of(2014, 5, 1),
                                    OffsetTime.MAX));

  root.addPosition(position);

  SimplePortfolio pf = new SimplePortfolio(portfolioName, root);

  persister.write(pf, securities);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:PortfolioWriterTest.java

示例14: updateTrade

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
/**
 * update a trade - the position's quantity should also be adjusted
 */
@Test
public void updateTrade() {
  ManageableTrade previousTrade = _savedPosition.getTrades().get(0);
  BeanDataSource tradeData = createTradeData("AAPL US Equity", previousTrade.getUniqueId().toString());
  UniqueId updatedId = _tradeBuilder.updateTrade(tradeData);

  ManageableTrade updatedTrade = _positionMaster.getTrade(updatedId);
  assertEquals(LocalDate.of(2012, 12, 21), updatedTrade.getTradeDate());
  assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), updatedTrade.getTradeTime());
  assertEquals(APPLE_BUNDLE, updatedTrade.getSecurityLink().getExternalId());
  assertEquals(1234d, updatedTrade.getPremium());
  assertEquals(Currency.USD, updatedTrade.getPremiumCurrency());
  assertEquals(LocalDate.of(2012, 12, 22), updatedTrade.getPremiumDate());
  assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), updatedTrade.getPremiumTime());
  assertEquals(BigDecimal.valueOf(30), updatedTrade.getQuantity());
  assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), updatedTrade.getCounterpartyExternalId());
  assertTrue(updatedTrade.getAttributes().isEmpty());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:FungibleTradeBuilderTest.java

示例15: updatePositionWithNoTrades

import org.threeten.bp.OffsetTime; //导入依赖的package包/类
/**
 * update a position that doesn't have any trades. position's quantity should match trade and trade should be added
 */
@Test
public void updatePositionWithNoTrades() {
  ManageablePosition position = new ManageablePosition(BigDecimal.valueOf(42), APPLE_SECURITY.getExternalIdBundle());
  ManageablePosition savedPosition = _positionMaster.add(new PositionDocument(position)).getPosition();
  assertEquals(BigDecimal.valueOf(42), savedPosition.getQuantity());

  _tradeBuilder.updatePosition(createTradeData("AAPL US Equity", null), savedPosition.getUniqueId());
  ManageablePosition updatedPosition = _positionMaster.get(savedPosition.getUniqueId().getObjectId(),
                                                           VersionCorrection.LATEST).getPosition();
  assertEquals(BigDecimal.valueOf(30), updatedPosition.getQuantity());
  assertEquals(1, updatedPosition.getTrades().size());
  ManageableTrade trade = updatedPosition.getTrades().get(0);
  assertEquals(LocalDate.of(2012, 12, 21), trade.getTradeDate());
  assertEquals(OffsetTime.of(LocalTime.of(14, 25), ZoneOffset.UTC), trade.getTradeTime());
  assertEquals(APPLE_BUNDLE, trade.getSecurityLink().getExternalId());
  assertEquals(1234d, trade.getPremium());
  assertEquals(Currency.USD, trade.getPremiumCurrency());
  assertEquals(LocalDate.of(2012, 12, 22), trade.getPremiumDate());
  assertEquals(OffsetTime.of(LocalTime.of(13, 30), ZoneOffset.UTC), trade.getPremiumTime());
  assertEquals(BigDecimal.valueOf(30), trade.getQuantity());
  assertEquals(ExternalId.of(AbstractTradeBuilder.CPTY_SCHEME, "cptyName"), trade.getCounterpartyExternalId());
  assertTrue(trade.getAttributes().isEmpty());
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:27,代码来源:FungibleTradeBuilderTest.java


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