Example usage for java.time ZonedDateTime now

List of usage examples for java.time ZonedDateTime now

Introduction

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

Prototype

public static ZonedDateTime now() 

Source Link

Document

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

Usage

From source file:com.sumzerotrading.eod.trading.strategy.ReportGeneratorTest.java

@Test
public void testLoadSaveDeletePartial() throws Exception {
    ReportGenerator generator = new ReportGenerator(tmpDir);

    RoundTrip roundTrip = new RoundTrip();
    TradeReferenceLine tradeReferenceLine = buildReferenceLine("123", LONG, ENTRY);
    tradeReferenceLine.correlationId = "123";
    tradeReferenceLine.direction = TradeReferenceLine.Direction.LONG;
    tradeReferenceLine.side = TradeReferenceLine.Side.ENTRY;
    roundTrip.addTradeReference(order, tradeReferenceLine);

    order.setCurrentStatus(OrderStatus.Status.FILLED);
    OrderEvent orderEvent = new OrderEvent(order,
            new OrderStatus(OrderStatus.Status.NEW, "", "", new StockTicker("QQQ"), ZonedDateTime.now()));

    TradeReferenceLine longExitLine = buildReferenceLine("123", LONG, EXIT);
    TradeReferenceLine shortEntryLine = buildReferenceLine("123", SHORT, ENTRY);
    TradeReferenceLine shortExitLine = buildReferenceLine("123", SHORT, EXIT);

    roundTrip.addTradeReference(order, longExitLine);
    roundTrip.addTradeReference(order, shortEntryLine);

    File[] files = new File(partialDir).listFiles();
    assertEquals(0, files.length);/*from  w w  w.j ava 2  s.c om*/

    generator.savePartial("123", roundTrip);

    files = new File(partialDir).listFiles();
    assertEquals(1, files.length);

    generator.roundTripMap.clear();
    assertTrue(generator.roundTripMap.isEmpty());

    generator.loadPartialRoundTrips();
    assertEquals(1, generator.roundTripMap.size());
    assertEquals(roundTrip, generator.roundTripMap.get("123"));

    generator.deletePartial("123");
    files = new File(partialDir).listFiles();
    assertEquals(0, files.length);

}

From source file:de.pksoftware.springstrap.core.service.AccountServiceBase.java

/**
 * Triggered on account login./*from   www  .jav a  2 s .c o  m*/
 * @param event The Spring interactive authentication event.
 * TODO implement lastLoginIp and lastVisitIp
 */
@Override
@Transactional
public void onApplicationEvent(InteractiveAuthenticationSuccessEvent event) {
    Authentication userAuth = event.getAuthentication();

    logger.info("Authenticated using {}", userAuth);

    String remoteAddress = null;

    WebAuthenticationDetails details = (WebAuthenticationDetails) userAuth.getDetails();
    if (null != details) {
        remoteAddress = details.getRemoteAddress();
    } else {
        logger.warn("Cannot determine remote address!");
    }

    IAccount account = (IAccount) userAuth.getPrincipal();

    ZonedDateTime now = ZonedDateTime.now();

    ZonedDateTime lastLoginDate = account.getLastLoginDate();
    String lastLoginIp = account.getLastLoginIp();

    if (null != lastLoginDate) {
        account.setLastVisitDate(lastLoginDate);
    }

    if (null != lastLoginIp) {
        account.setLastVisitIp(lastLoginIp);
    }

    account.setLastLoginDate(now);
    account.setLastLoginIp(remoteAddress);

    this.saveAccount(account);

    logger.info("SUCCESSFUL Authentication with {}", account);
}

From source file:com.sumzerotrading.reporting.csv.ReportGeneratorTest.java

@Test
public void testLoadSaveDeletePartial() throws Exception {
    ReportGenerator generator = new ReportGenerator(strategy, tmpDir, pairRoundtripBuilder);

    PairTradeRoundTrip roundTrip = new PairTradeRoundTrip();
    TradeReferenceLine tradeReferenceLine = buildReferenceLine("123", LONG, ENTRY);
    roundTrip.addTradeReference(order, tradeReferenceLine);

    order.setCurrentStatus(OrderStatus.Status.FILLED);
    OrderEvent orderEvent = new OrderEvent(order,
            new OrderStatus(OrderStatus.Status.NEW, "", "", new StockTicker("QQQ"), ZonedDateTime.now()));

    TradeReferenceLine longExitLine = buildReferenceLine("123", LONG, EXIT);
    TradeReferenceLine shortEntryLine = buildReferenceLine("123", SHORT, ENTRY);
    TradeReferenceLine shortExitLine = buildReferenceLine("123", SHORT, EXIT);

    roundTrip.addTradeReference(order, longExitLine);
    roundTrip.addTradeReference(order, shortEntryLine);

    File[] files = new File(partialDir).listFiles();
    assertEquals(0, files.length);/*w  ww.ja  v a  2s  .c o  m*/

    generator.savePartial("123", roundTrip);

    files = new File(partialDir).listFiles();
    assertEquals(1, files.length);

    generator.roundTripMap.clear();
    assertTrue(generator.roundTripMap.isEmpty());

    generator.loadPartialRoundTrips();
    assertEquals(1, generator.roundTripMap.size());
    assertEquals(roundTrip, generator.roundTripMap.get("123"));

    generator.deletePartial("123");
    files = new File(partialDir).listFiles();
    assertEquals(0, files.length);

}

From source file:org.edgexfoundry.scheduling.ScheduleContext.java

public void reset(Schedule schedule) {
    if ((this.schedule != null) && (this.schedule.getName() != schedule.getName())) {
        scheduleEvents.clear();/* www.j  av  a2s .c  om*/
    }
    this.schedule = schedule;
    // update this if/when iterations are added to the schedule
    this.maxIterations = (schedule.getRunOnce()) ? 1 : 0;
    this.iterations = 0;

    String start = schedule.getStart();
    String end = schedule.getEnd();
    // if start is empty, then use now (need to think about ever-spawning tasks)
    if (start == null || start.isEmpty()) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Schedule.DATETIME_FORMATS[0])
                .withZone(ZoneId.systemDefault());
        start = formatter.format(Instant.now());
    }
    this.startTime = parseTime(start);

    // if end is empty, then use max
    if (end == null || end.isEmpty()) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Schedule.DATETIME_FORMATS[0])
                .withZone(ZoneId.systemDefault());
        end = formatter.format(ZonedDateTime.of(LocalDateTime.MAX, ZoneId.systemDefault()));
    }
    this.endTime = parseTime(end);

    // get the period and duration from the frequency string
    parsePeriodAndDuration(schedule.getFrequency());

    // setup the next time the schedule will run
    this.nextTime = initNextTime(startTime, ZonedDateTime.now(), period, duration);

    // clear any schedule events as required

    logger.debug("reset() " + this.toString());
}

From source file:org.codice.ddf.registry.federationadmin.service.impl.RegistryPublicationServiceImpl.java

@Override
public void unpublish(String registryId, String destinationRegistryId) throws FederationAdminException {
    Metacard metacard = getMetacard(registryId);

    List<String> locations = RegistryUtility.getListOfStringAttribute(metacard,
            RegistryObjectMetacardType.PUBLISHED_LOCATIONS);
    if (!locations.contains(destinationRegistryId)) {
        return;//from   w w w  . j  a va2 s. c  om
    }

    locations.remove(destinationRegistryId);
    if (locations.isEmpty()) {
        locations.add(NO_PUBLICATIONS);
    }

    ArrayList<String> locArr = new ArrayList<>();
    locArr.addAll(locations);

    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.PUBLISHED_LOCATIONS, locArr));
    metacard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.LAST_PUBLISHED,
            Date.from(ZonedDateTime.now().toInstant())));

    federationAdminService.updateRegistryEntry(metacard);

    String sourceId = getSourceIdFromRegistryId(destinationRegistryId);

    if (sourceId == null) {
        throw new FederationAdminException(
                "Could not find a source id for registry-id " + destinationRegistryId);
    }

    LOGGER.info("Unpublishing registry entry {}:{} from {}", metacard.getTitle(), registryId, sourceId);

    federationAdminService.deleteRegistryEntriesByRegistryIds(Collections.singletonList(registryId),
            Collections.singleton(sourceId));
}

From source file:com.mh2c.LogGenerator.java

private String generateLogLine() {
    String ipAddress = faker.internet().privateIpV4Address();
    String dateTime = TIMESTAMP_FORMATTER.format(ZonedDateTime.now());
    String method = METHODS.sample();
    String resource = RESOURCES.sample();
    String status = RESPONSES.sample();
    int bytes = random.nextInt(10000);
    String referer = faker.internet().url();
    String userAgent = USER_AGENTS.sample();

    return String.format(FORMAT, ipAddress, dateTime, method, resource, status, bytes, referer, userAgent);
}

From source file:org.mascherl.example.service.ComposeMailService.java

@Transactional
public String composeNewMail(User currentUser) {
    MailEntity mailEntity = new MailEntity(MailType.DRAFT);
    mailEntity.setUser(em.getReference(UserEntity.class, currentUser.getUuid()));
    mailEntity.setDateTime(ZonedDateTime.now());
    mailEntity.setUnread(false);/*from   w  w w.j a  v  a 2 s . c o m*/
    mailEntity.setFrom(new MailAddress(currentUser.getEmail()));
    em.persist(mailEntity);
    em.flush();

    return mailEntity.getUuid();
}

From source file:org.cgiar.ccafs.marlo.action.center.summaries.CapdevSummaryAction.java

@Override
public String execute() throws Exception {

    final ByteArrayOutputStream os = new ByteArrayOutputStream();

    final Resource reportResource = resourceManager
            .createDirectly(this.getClass().getResource("/pentaho/center/Capdev.prpt"), MasterReport.class);

    final MasterReport masterReport = (MasterReport) reportResource.getResource();
    String center = this.getCurrentCrp().getAcronym();

    // Get datetime
    ZonedDateTime timezone = ZonedDateTime.now();
    DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d 'at' HH:mm ");
    String zone = timezone.getOffset() + "";
    if (zone.equals("Z")) {
        zone = "+0";
    }// ww  w. j av a2 s .  c  o  m
    String currentDate = timezone.format(format) + "(GMT" + zone + ")";

    // Set Main_Query
    CompoundDataFactory cdf = CompoundDataFactory.normalize(masterReport.getDataFactory());
    String masterQueryName = "main";
    TableDataFactory sdf = (TableDataFactory) cdf.getDataFactoryForQuery(masterQueryName);
    TypedTableModel model = this.getMasterTableModel(center, currentDate);
    sdf.addTable(masterQueryName, model);
    masterReport.setDataFactory(cdf);

    // Get details band
    final ItemBand masteritemBand = masterReport.getItemBand();
    // Create new empty subreport hash map
    final HashMap<String, Element> hm = new HashMap<String, Element>();
    // method to get all the subreports in the prpt and store in the HashMap
    this.getAllSubreports(hm, masteritemBand);
    // Uncomment to see which Subreports are detecting the method getAllSubreports

    // Subreport list of capdev
    this.fillSubreport((SubReport) hm.get("capdev_interventions"), "capdev_interventions");
    this.fillSubreport((SubReport) hm.get("capdev_participants"), "capdev_participants");
    this.fillSubreport((SubReport) hm.get("individual_types"), "individual_types");
    this.fillSubreport((SubReport) hm.get("groupTypes"), "groupTypes");
    this.fillSubreport((SubReport) hm.get("disciplines"), "disciplines");
    this.fillSubreport((SubReport) hm.get("target_groups"), "target_groups");
    this.fillSubreport((SubReport) hm.get("programs"), "programs");
    this.fillSubreport((SubReport) hm.get("crp"), "crp");
    this.fillSubreport((SubReport) hm.get("capdevSummary"), "capdevSummary");
    this.fillSubreport((SubReport) hm.get("citizenship"), "citizenship");
    this.fillSubreport((SubReport) hm.get("funding_type"), "funding_type");
    this.fillSubreport((SubReport) hm.get("institution"), "institution");
    this.fillSubreport((SubReport) hm.get("institutions_type"), "institutions_type");

    ExcelReportUtil.createXLSX(masterReport, os);
    bytesXLS = os.toByteArray();
    os.close();

    return SUCCESS;
}

From source file:lumbermill.internal.aws.AWSV4SignerImpl.java

public AWSV4SignerImpl(AWSCredentialsProvider credentialsProvider, String region, String service) {
    this.credentialsProvider = credentialsProvider;
    this.region = region;
    this.service = service;
    clock = () -> ZonedDateTime.ofInstant(ZonedDateTime.now().toInstant(), ZoneId.of("UTC")).toLocalDateTime();
}

From source file:nu.yona.server.analysis.service.AnalysisEngineService.java

private Duration determineDeviceTimeOffset(AppActivitiesDto appActivities) {
    Duration offset = Duration.between(ZonedDateTime.now(), appActivities.getDeviceDateTime());
    return (offset.abs().compareTo(DEVICE_TIME_INACCURACY_MARGIN) > 0) ? offset : Duration.ZERO; // Ignore if less than 10
    // seconds//w w w. ja  v  a 2 s  . c  o  m
}