Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

In this page you can find the example usage for java.time LocalDate now.

Prototype

public static LocalDate now() 

Source Link

Document

Obtains the current date from the system clock in the default time-zone.

Usage

From source file:ch.algotrader.service.LookupServiceTest.java

@Test
public void testGetOpenPositionsByStrategyTypeAndUnderlyingType() {

    SecurityFamily family1 = new SecurityFamilyImpl();
    family1.setName("Forex1");
    family1.setTickSizePattern("0<0.1");
    family1.setCurrency(Currency.USD);

    Forex forex1 = new ForexImpl();
    forex1.setSymbol("EUR.USD");
    forex1.setBaseCurrency(Currency.EUR);
    forex1.setSecurityFamily(family1);/* ww w  .j a v  a2  s .c  o m*/

    this.session.save(family1);
    this.session.save(forex1);

    FutureFamily futurefamily1 = new FutureFamilyImpl();
    futurefamily1.setName("Future1");
    futurefamily1.setTickSizePattern("0<0.1");
    futurefamily1.setCurrency(Currency.USD);
    futurefamily1.setExpirationType(ExpirationType.NEXT_3_RD_FRIDAY);
    futurefamily1.setExpirationDistance(Duration.DAY_1);

    futurefamily1.setUnderlying(forex1);
    this.session.save(futurefamily1);

    Future future1 = new FutureImpl();
    future1.setSecurityFamily(futurefamily1);
    LocalDate expiration = LocalDate.now().plusMonths(1);
    future1.setExpiration(DateTimeLegacy.toLocalDate(expiration));
    future1.setMonthYear(DateTimePatterns.MONTH_YEAR.format(expiration));
    this.session.save(future1);

    Strategy strategy1 = new StrategyImpl();
    strategy1.setName("Strategy1");

    this.session.save(strategy1);

    Position position1 = new PositionImpl();
    position1.setQuantity(222);
    position1.setSecurity(future1);
    position1.setStrategy(strategy1);
    position1.setCost(new BigDecimal(0.0));
    position1.setRealizedPL(new BigDecimal(0.0));

    this.session.save(position1);
    this.session.flush();

    List<Position> positions1 = lookupService.getOpenPositionsByStrategyTypeAndUnderlyingType("Dummy",
            FutureImpl.class, ForexImpl.class);

    Assert.assertEquals(0, positions1.size());

    List<Position> positions2 = lookupService.getOpenPositionsByStrategyTypeAndUnderlyingType("Strategy1",
            FutureImpl.class, ForexImpl.class);

    Assert.assertEquals(1, positions2.size());

    Assert.assertEquals(222, positions2.get(0).getQuantity());
    Assert.assertSame(future1, positions2.get(0).getSecurity());
    Assert.assertSame(strategy1, positions2.get(0).getStrategy());
}

From source file:org.apache.phoenix.end2end.DateTimeIT.java

@Test
public void testCastTimeStampToDate() throws Exception {
    String tablename = generateUniqueName();
    String ddl = "CREATE TABLE IF NOT EXISTS " + tablename + " (PK INTEGER PRIMARY KEY, A_TIMESTAMP TIMESTAMP)";
    Properties props = new Properties();
    props.setProperty("phoenix.query.dateFormatTimeZone", TimeZone.getDefault().toString());
    Connection conn = DriverManager.getConnection(getUrl(), props);
    conn.createStatement().execute(ddl);

    String localTime = LocalDate.now().toString();
    conn.createStatement().execute("UPSERT INTO " + tablename + " VALUES(1,TO_TIMESTAMP('" + localTime + "'))");

    conn.setAutoCommit(true);/*from   w  ww . j  a  v a 2  s  .  com*/
    try {
        PreparedStatement statement = conn
                .prepareStatement("SELECT CAST(A_TIMESTAMP AS DATE) as A_DATE FROM " + tablename);

        ResultSet rs = statement.executeQuery();
        assertTrue(rs.next());
        assertTrue(rs.getString(1).contains(localTime));
        assertFalse(rs.next());
    } finally {
        conn.close();
    }
}