Package org.threeten.bp

Examples of org.threeten.bp.OffsetDateTime


  @Test
  public void test_addWithTwoTrades_add() {
    Instant now = Instant.now(_posMaster.getClock());
   
    OffsetDateTime offsetDateTime = OffsetDateTime.now();
   
    ManageablePosition position = new ManageablePosition(BigDecimal.TEN, ExternalId.of("A", "B"));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "C"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(600).toOffsetTime(), ExternalId.of("CPS", "CPV")));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "D"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(500).toOffsetTime(), ExternalId.of("CPS", "CPV")));
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument test = _posMaster.add(doc);
   
View Full Code Here


  @Test
  public void test_addWithTwoTrades_addThenGet() {
    ManageablePosition position = new ManageablePosition(BigDecimal.valueOf(20), ExternalId.of("A", "B"));
   
    OffsetDateTime offsetDateTime = OffsetDateTime.now();
   
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "B"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(600).toOffsetTime(), ExternalId.of("CPS", "CPV")));
    position.getTrades().add(new ManageableTrade(BigDecimal.TEN, ExternalId.of("A", "C"), offsetDateTime.toLocalDate(), offsetDateTime.minusSeconds(500).toOffsetTime(), ExternalId.of("CPS", "CPV")));
   
    PositionDocument doc = new PositionDocument();
    doc.setPosition(position);
    PositionDocument added = _posMaster.add(doc);
    assertNotNull(added);
View Full Code Here

    final ComputationTarget expected = new ComputationTarget(ComputationTargetType.POSITION, POSITION);
    assertExpected(expected, test.resolve(spec, VersionCorrection.LATEST));
  }

  public void test_resolve_trade() {
    final OffsetDateTime now = OffsetDateTime.now();
    final InMemorySecuritySource secSource = new InMemorySecuritySource();
    final MockPositionSource posSource = new MockPositionSource();
    final SimplePortfolio portfolio = new SimplePortfolio(UniqueId.of("Test", "1"), "Name");
    final SimplePosition position = new SimplePosition(UniqueId.of("Test", "1"), new BigDecimal(1), ExternalIdBundle.EMPTY);
    final SimpleTrade trade = new SimpleTrade(new SimpleSecurityLink(), new BigDecimal(1), new SimpleCounterparty(ExternalId.of("CPARTY", "C100")), now.toLocalDate(), now.toOffsetTime());
    trade.setUniqueId(UniqueId.of("TradeScheme", "1"));
    position.addTrade(trade);
    portfolio.getRootNode().addPosition(position);
    posSource.addPortfolio(portfolio);
    final DefaultComputationTargetResolver test = new DefaultComputationTargetResolver(secSource, posSource);
View Full Code Here

  // FunctionDefinition

  @Override
  public CompiledFunctionDefinition compile(final FunctionCompilationContext context, final Instant atInstant) {
    final OffsetDateTime odt = atInstant.atOffset(ZoneOffset.UTC);
    final OffsetDateTime start = odt.withHour(0).withMinute(0).withSecond(0).withNano(0); // Start of the UTC day
    final OffsetDateTime end = start.plusDays(1).minusNanos(1); // End of the UTC day
    return new Compiled(start.toInstant(), end.toInstant());
  }
View Full Code Here

  private class SnapshotTask implements Runnable {

    @Override
    public void run() {
      for (Map.Entry<LiveDataSpecification, FudgeMsg> entry : _allValues.entrySet()) {
        OffsetDateTime atTheHour = OffsetDateTime.now(Clock.systemUTC()).truncatedTo(MINUTES);
        if (atTheHour.getMinute() >= 55) {
          // Assume we got triggered early.
          atTheHour = atTheHour.withMinute(0).plusHours(1);
        } else {
          atTheHour = atTheHour.withMinute(0);
        }
        String observationTimeName = atTheHour.toOffsetTime().toString();
        try {
          _storageExecutor.execute(new StorageTask(entry.getKey(), entry.getValue(), atTheHour.toLocalDate(), observationTimeName));
        } catch (Exception e) {
          s_logger.error("Unable to submit a storage task to store {} {}", entry.getKey(), entry.getValue());
        }
      }
    }
View Full Code Here

    int fieldWidth = OffsetDateTime.now().toString(dateTimeFormatter).length(); // Assumes all offset date times have same width

    header(fieldWidth);
    String id = TimeZone.getDefault().getID();
    for (VersionInfo versionInfo : snapshotVersions) {
      OffsetDateTime versionFrom = versionInfo.getVersionFrom() != null ? OffsetDateTime.ofInstant(versionInfo.getVersionFrom(), ZoneId.of(id)) : null;
      OffsetDateTime versionTo = versionInfo.getVersionTo() != null ? OffsetDateTime.ofInstant(versionInfo.getVersionTo(), ZoneId.of(id)) : null;
      OffsetDateTime correctionFrom = versionInfo.getCorrectionFrom() != null ? OffsetDateTime.ofInstant(versionInfo.getCorrectionFrom(), ZoneId.of(id)) : null;
      OffsetDateTime correctionTo = versionInfo.getCorrectionTo() != null ? OffsetDateTime.ofInstant(versionInfo.getCorrectionTo(), ZoneId.of(id)) : null;
      if (versionFrom != null) {
        System.out.print(versionFrom.toString(dateTimeFormatter));
      } else {
        notSpecified(fieldWidth);
      }
      spaces();
      if (versionTo != null) {
        System.out.print(versionTo.toString(dateTimeFormatter));
      } else {
        notSpecified(fieldWidth);
      }
      spaces();
      if (correctionFrom != null) {
        System.out.print(correctionFrom.toString(dateTimeFormatter));
      } else {
        notSpecified(fieldWidth);
      }
      spaces();
      if (correctionTo != null) {
        System.out.print(correctionTo.toString(dateTimeFormatter));
      } else {
        notSpecified(fieldWidth);
      }
      spaces();
      System.out.println(versionInfo.getUniqueId());
View Full Code Here

  public static ZonedDateTime fromFudgeMsg(final FudgeDeserializer deserializer, final FudgeMsg msg) {
    if (msg == null) {
      return null;
    }
    final OffsetDateTime odt = msg.getValue(OffsetDateTime.class, DATETIME_FIELD_NAME);
    final ZoneId zone = msg.getValue(ZoneId.class, ZONE_FIELD_NAME);
    return odt.atZoneSameInstant(zone);
  }
View Full Code Here

    final ZoneId zone = msg.getValue(ZoneId.class, ZONE_FIELD_NAME);
    final Object obj = msg.getValue(DATETIME_FIELD_NAME);
    if (obj instanceof FudgeDateTime) {
      FudgeDateTime fudge = (FudgeDateTime) obj;
      if (fudge.getTime().hasTimezoneOffset()) {
        OffsetDateTime odt = fudge.toOffsetDateTime();
        if (zone != null) {
          return FlexiDateTime.of(odt.atZoneSameInstant(zone));
        }
        return FlexiDateTime.of(odt);
      } else {
        return FlexiDateTime.of(fudge.toLocalDateTime());
      }
    } else if (obj instanceof FudgeDate) {
      FudgeDate fudge = (FudgeDate) obj;
      return FlexiDateTime.of(fudge.toLocalDate());
    } else if (obj instanceof OffsetDateTime) {
      OffsetDateTime odt = (OffsetDateTime) obj;
      if (zone != null) {
        return FlexiDateTime.of(odt.atZoneSameInstant(zone));
      }
      return FlexiDateTime.of(odt);
    } else if (obj instanceof LocalDateTime) {
      return FlexiDateTime.of((LocalDateTime) obj);
    } else if (obj instanceof LocalDate) {
View Full Code Here

   * @param instant  the instant to convert, not null
   * @return the SQL time-stamp, not null
   */
  public static Timestamp toSqlTimestamp(Instant instant) {
    ArgumentChecker.notNull(instant, "instant");
    OffsetDateTime utc = OffsetDateTime.ofInstant(instant, ZoneOffset.UTC);
    return toSqlDateTime(utc.toLocalDateTime());
  }
View Full Code Here

  }

  public void test_getTrade() throws Exception {
    final PortfolioMaster mockPortfolio = mock(PortfolioMaster.class);
    final PositionMaster mockPosition = mock(PositionMaster.class);
    final OffsetDateTime now = OffsetDateTime.now();
    final ManageableTrade doc = new ManageableTrade(BigDecimal.TEN, ExternalId.of("B", "C"), now.toLocalDate(), now.toOffsetTime().minusSeconds(100), ExternalId.of("CPARTY", "C100"));
    doc.setUniqueId(UID);
    when(mockPosition.getTrade(UID)).thenReturn(doc);
    MasterPositionSource test = new MasterPositionSource(mockPortfolio, mockPosition);
    Trade testResult = test.getTrade(UID);
    verify(mockPosition, times(1)).getTrade(UID);
View Full Code Here

TOP

Related Classes of org.threeten.bp.OffsetDateTime

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.