Example usage for java.time ZoneId systemDefault

List of usage examples for java.time ZoneId systemDefault

Introduction

In this page you can find the example usage for java.time ZoneId systemDefault.

Prototype

public static ZoneId systemDefault() 

Source Link

Document

Gets the system default time-zone.

Usage

From source file:com.teradata.benchto.service.BenchmarkService.java

public Duration getSuccessfulExecutionAge(String uniqueName) {
    Timestamp ended = benchmarkRunRepo.findTimeOfLatestSuccessfulExecution(uniqueName);
    if (ended == null) {
        return Duration.ofDays(Integer.MAX_VALUE);
    }//w  w w.j a v a 2  s.c o  m
    ZonedDateTime endedAsZDT = ZonedDateTime.of(ended.toLocalDateTime(), ZoneId.systemDefault());
    return Duration.between(endedAsZDT, currentDateTime());
}

From source file:us.colloquy.sandbox.TestExtractor.java

@Test
public void useJsoup() {

    String homeDir = System.getProperty("user.home");

    System.out.println(homeDir);/*  ww  w  .  j a  v  a2 s  .  c  o m*/

    //JSOUP API allows to extract all  elements of letters in files

    // File input = new File("samples/OEBPS/Text/0001_1006_2001.xhtml");

    File input = new File("samples/pisma-1904/OEBPS/Text/single_doc.html");

    try {
        Document doc = Jsoup.parse(input, "UTF-8");

        List<Letter> letters = new ArrayList<>(); //our model contains only a subset of fields

        String previousYear = "";

        for (Element element : doc.getElementsByClass("section")) {
            Letter letter = new Letter();

            StringBuilder content = new StringBuilder();

            for (Element child : element.children()) {

                for (Attribute att : child.attributes()) {
                    System.out.println(att.getKey() + " " + att.getValue());
                }

                if ("center".equalsIgnoreCase(child.className())) {
                    String toWhom = child.getElementsByTag("strong").text();

                    if (StringUtils.isEmpty(toWhom)) {
                        toWhom = child.text();
                        // System.out.println(toWhom);
                    }

                    String[] toWhomArray = toWhom.split("(\\s\\s)|(,)");

                    for (String to : toWhomArray) {
                        RussianDate.parseToWhom(letter, to); //here we need to recognize a russian name and store that but for now we store the content
                    }

                    //check if there is anything else here and find date and place - it will be replaced if exists below

                    String entireText = child.text();

                    String tail = entireText.replace(toWhom, "");

                    if (StringUtils.isNotEmpty(tail)) {
                        RussianDate.parseDateAndPlace(letter, tail, previousYear); //a parser that figures out date and place if they are present
                    }

                    // System.out.println("two whom\t " +  child.getElementsByTag("strong").text() );

                } else if ("Data".equalsIgnoreCase(child.className())) {

                    if (child.getElementsByTag("em") != null
                            && StringUtils.isNotEmpty(child.getElementsByTag("em").text())) {
                        RussianDate.parseDateAndPlace(letter, child.getElementsByTag("em").text(),
                                previousYear); //most often date and place are enclosed in em tag

                        if (letter.getDate() != null) {
                            LocalDate localDate = letter.getDate().toInstant().atZone(ZoneId.systemDefault())
                                    .toLocalDate();
                            int year = localDate.getYear();
                            previousYear = year + "";
                        }
                    }

                    // System.out.println("when and where\t " + child.getElementsByTag("em").text());

                } else if ("petit".equalsIgnoreCase(child.className())
                        || "Textpetit_otstup".equalsIgnoreCase(child.className())) {
                    letter.getNotes().add(child.text());

                } else {
                    //System.out.println(child.text() );

                    Elements elements = child.getElementsByTag("sup");

                    for (Element e : elements) {
                        String value = e.text();

                        e.replaceWith(new TextNode("[" + value + "]", null));
                    }

                    for (Element el : child.getAllElements()) {
                        // System.out.println(el.tagName());
                        if ("sup".equalsIgnoreCase(el.tagName())) {
                            content.append(" [" + el.text() + "] ");
                        } else {
                            content.append(el.text());
                        }

                    }

                    content.append("\n");

                }

                //                  System.out.println(child.tag() + "\n" );
                //                  System.out.println(child.outerHtml() + "\n" + child.text());
            }

            letter.setContent(content.toString());
            letters.add(letter);
        }

        ObjectWriter ow = new com.fasterxml.jackson.databind.ObjectMapper().writer().withDefaultPrettyPrinter();

        for (Letter letter : letters) {
            //                if (letter.getDate() == null)
            //                {

            //                        if (StringUtils.isNotEmpty(person.getLastName()))
            //                        {
            String json = ow.writeValueAsString(letter);

            System.out.println(json);
            //                        }

            //}

        }

    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:org.openhab.binding.dwdunwetter.internal.data.DwdWarningsData.java

public State getEffective(int number) {
    DwdWarningData data = getGemeindeData(number);
    if (data == null) {
        return UnDefType.NULL;
    }//from ww  w. java 2 s . co  m
    ZonedDateTime zoned = ZonedDateTime.ofInstant(data.getEffective(), ZoneId.systemDefault());
    return new DateTimeType(zoned);
}

From source file:com.orange.clara.cloud.servicedbdumper.task.job.JobFactoryTest.java

@Test
public void when_purge_finished_jobs_and_jobs_in_error_exist_it_should_delete_job_which_pass_expiration_and_have_null_database_target_and_source_and_service_instance() {
    Job jobNotExpired = new Job();
    jobNotExpired.setUpdatedAt(new Date());
    jobNotExpired.setDatabaseRefSrc(new DatabaseRef());

    Date date = new Date();
    LocalDateTime localDateTime = LocalDateTime.from(date.toInstant().atZone(ZoneId.systemDefault()))
            .minusMinutes(jobFinishedDeleteExpirationMinutes + 1);
    Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
    Job jobExpired = new Job();
    jobExpired.setUpdatedAt(Date.from(instant));

    when(jobRepo.findByJobEventOrderByUpdatedAtDesc(anyObject()))
            .thenReturn(Arrays.asList(jobNotExpired, jobExpired));
    jobFactory.purgeFinishedJob();/*from w  w w  .jav a2 s  . co m*/
    verify(jobRepo, times(1)).delete((Job) notNull());
}

From source file:com.epam.ta.reportportal.core.project.impl.ProjectInfoWidgetDataConverter.java

/**
 * Utility method for grouping input list of {@link Launch} by
 * {@link ProjectInfoGroup} criteria/* w  w  w . j a  va2  s . c  o  m*/
 * 
 * @param initial
 * @param criteria
 * @return
 */
private static Map<String, List<Launch>> groupBy(List<Launch> initial, ProjectInfoGroup criteria) {
    Map<String, List<Launch>> result = new LinkedHashMap<>();
    LocalDate prevDate = null;
    for (Launch launch : initial) {
        final LocalDate localDate = launch.getStartTime().toInstant().atZone(ZoneId.systemDefault())
                .toLocalDate();

        String key;
        switch (criteria) {
        case BY_NAME:
            key = launch.getName();
            break;
        default:
            key = formattedDate(criteria, localDate);
            if (prevDate != null) {
                while (!formattedDate(criteria, prevDate).equals(formattedDate(criteria, localDate))) {
                    if (!result.containsKey(formattedDate(criteria, prevDate)))
                        result.put(formattedDate(criteria, prevDate), new ArrayList<>());
                    prevDate = prevDate.plus(1, criteria == BY_DAY ? DAYS : WEEKS);
                }
            }
        }
        if (!result.keySet().contains(key))
            result.put(key, Lists.newArrayList(launch));
        else {
            List<Launch> prev = result.get(key);
            prev.add(launch);
            result.put(key, prev);
        }
        prevDate = localDate;
    }
    return result;
}

From source file:org.openhab.binding.dwdunwetter.internal.data.DwdWarningsData.java

public State getExpires(int number) {
    DwdWarningData data = getGemeindeData(number);
    if (data == null) {
        return UnDefType.NULL;
    }/*  w ww.j a  v  a 2  s . c  om*/
    ZonedDateTime zoned = ZonedDateTime.ofInstant(data.getExpires(), ZoneId.systemDefault());
    return new DateTimeType(zoned);
}

From source file:org.openlmis.fulfillment.web.OrderControllerIntegrationTest.java

@Before
public void setUp() {
    this.setUpBootstrapData();

    when(authenticationHelper.getCurrentUser()).thenReturn(user);

    when(dateHelper.getCurrentDateTimeWithSystemZone())
            .thenReturn(ZonedDateTime.of(2015, 5, 7, 10, 5, 20, 500, ZoneId.systemDefault()));

    program1 = new ProgramDataBuilder().withId(program1Id).build();
    program2 = new ProgramDataBuilder().withId(program2Id).build();

    period1 = new ProcessingPeriodDataBuilder().withId(period1Id).build();
    period2 = new ProcessingPeriodDataBuilder().withId(period2Id).build();

    facility = new FacilityDataBuilder().withId(facilityId)
            .withSupportedPrograms(Arrays.asList(program1, program2)).build();
    facility1 = new FacilityDataBuilder().withId(facility1Id)
            .withSupportedPrograms(Arrays.asList(program1, program2)).build();
    facility2 = new FacilityDataBuilder().withId(facility2Id)
            .withSupportedPrograms(Arrays.asList(program1, program2)).build();

    when(programService.findOne(eq(program1Id))).thenReturn(program1);
    when(programService.findOne(eq(program2Id))).thenReturn(program2);
    when(programService.findByIds(anySetOf(UUID.class))).thenReturn(Arrays.asList(program1, program2));

    when(facilityService.findOne(eq(facilityId))).thenReturn(facility);
    when(facilityService.findOne(eq(facility1Id))).thenReturn(facility1);
    when(facilityService.findOne(eq(facility2Id))).thenReturn(facility2);
    when(facilityService.findByIds(anySetOf(UUID.class)))
            .thenReturn(Arrays.asList(facility, facility1, facility2));

    when(shipmentRepository.save(any(Shipment.class)))
            .thenAnswer(invocation -> invocation.getArgumentAt(0, Shipment.class));

    product1 = new OrderableDataBuilder().withId(product1Id).build();
    product2 = new OrderableDataBuilder().withId(product2Id).build();

    when(orderableReferenceDataService.findByIds(anySetOf(UUID.class)))
            .thenReturn(Arrays.asList(product1, product2));

    when(userReferenceDataService.findByIds(anySetOf(UUID.class))).thenReturn(Collections.singletonList(user));

    when(periodReferenceDataService.findByIds(anyCollectionOf(UUID.class)))
            .thenReturn(Arrays.asList(period1, period2));

    when(periodReferenceDataService.findOne(period1Id)).thenReturn(period1);

    when(periodReferenceDataService.findOne(period2Id)).thenReturn(period2);

    firstOrder = createOrder(period1Id, program1Id, facilityId, facilityId, new BigDecimal("1.29"),
            createOrderLineItem(product1Id, 50L));

    secondOrder = createOrder(period1Id, program1Id, facility2Id, facility1Id, new BigDecimal(100),
            createOrderLineItem(product1Id, 50L), createOrderLineItem(product2Id, 15L));

    thirdOrder = createOrder(period2Id, program2Id, facility2Id, facility1Id, new BigDecimal(200),
            createOrderLineItem(product1Id, 50L), createOrderLineItem(product2Id, 10L));

    firstOrder.setExternalId(secondOrder.getExternalId());

    firstOrderDto = OrderDto.newInstance(firstOrder, exporter);
    secondOrderDto = OrderDto.newInstance(secondOrder, exporter);
}

From source file:org.openhab.binding.dwdunwetter.internal.data.DwdWarningsData.java

public State getOnset(int number) {
    DwdWarningData data = getGemeindeData(number);
    if (data == null) {
        return UnDefType.NULL;
    }/* w  ww  . j a  v a 2 s. co m*/
    ZonedDateTime zoned = ZonedDateTime.ofInstant(data.getOnset(), ZoneId.systemDefault());
    return new DateTimeType(zoned);
}

From source file:net.ceos.project.poi.annotated.core.CellFormulaHandler.java

/**
 * Apply a Date value to the cell./*from   w  w  w . j  a  v  a 2 s .  com*/
 * 
 * @param configCriteria
 *            the {@link XConfigCriteria}
 * @param object
 *            the object
 * @param cell
 *            the {@link Cell} to use
 * @throws IllegalAccessException
 * @throws ConverterException
 */
protected static void localDateTimeHandler(final XConfigCriteria configCriteria, final Object object,
        final Cell cell) throws IllegalAccessException, ConverterException {
    LocalDateTime date = (LocalDateTime) configCriteria.getField().get(object);
    if (StringUtils.isNotBlank(configCriteria.getElement().transformMask())) {
        // apply transformation mask
        String decorator = configCriteria.getElement().transformMask();
        convertDate(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()), decorator);
    } else if (StringUtils.isNotBlank(configCriteria.getElement().formatMask())) {
        // apply format mask
        CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
    } else {
        // apply default date mask
        CellValueHandler.consumeValue(cell, Date.from(date.atZone(ZoneId.systemDefault()).toInstant()));
    }
}

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

@Test
public void testWriteRoundTrip() throws Exception {
    Path path = Files.createTempFile("ReportGeneratorUnitTest", ".txt");
    reportGenerator.outputFile = path.toString();
    String expected = "2016-03-19T07:01:10,LONG,ABC,100,100.23,0,2016-03-20T06:01:10,101.23,0";

    Ticker longTicker = new StockTicker("ABC");
    Ticker shortTicker = new StockTicker("XYZ");
    int longSize = 100;
    int shortSize = 50;
    double longEntryFillPrice = 100.23;
    double longExitFillPrice = 101.23;
    ZonedDateTime entryTime = ZonedDateTime.of(2016, 3, 19, 7, 1, 10, 0, ZoneId.systemDefault());
    ZonedDateTime exitTime = ZonedDateTime.of(2016, 3, 20, 6, 1, 10, 0, ZoneId.systemDefault());

    TradeOrder longEntry = new TradeOrder("123", longTicker, longSize, TradeDirection.BUY);
    longEntry.setFilledPrice(longEntryFillPrice);
    longEntry.setOrderFilledTime(entryTime);
    TradeReferenceLine entryLine = new TradeReferenceLine();
    entryLine.correlationId = "123";
    entryLine.direction = Direction.LONG;
    entryLine.side = Side.ENTRY;/*from ww  w.j  ava2  s  .  com*/

    TradeOrder longExit = new TradeOrder("123", longTicker, longSize, TradeDirection.SELL);
    longExit.setFilledPrice(longExitFillPrice);
    longExit.setOrderFilledTime(exitTime);
    TradeReferenceLine exitLine = new TradeReferenceLine();
    exitLine.correlationId = "123";
    exitLine.direction = LONG;
    exitLine.side = Side.EXIT;

    RoundTrip roundTrip = new RoundTrip();
    roundTrip.addTradeReference(longEntry, entryLine);
    roundTrip.addTradeReference(longExit, exitLine);

    System.out.println("Writing out to file: " + path);

    reportGenerator.writeRoundTripToFile(roundTrip);

    List<String> lines = Files.readAllLines(path);
    assertEquals(1, lines.size());
    assertEquals(expected, lines.get(0));

    Files.deleteIfExists(path);

}