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:software.coolstuff.springframework.owncloud.service.impl.rest.OwncloudRestResourceServiceImpl.java

private OwncloudRestResourceExtension createOwncloudResourceFrom(DavResource davResource,
        OwncloudResourceConversionProperties conversionProperties) {
    log.debug("Create OwncloudResource based on DavResource {}", davResource.getHref());
    MediaType mediaType = MediaType.valueOf(davResource.getContentType());
    URI rootPath = conversionProperties.getRootPath();
    URI href = rootPath.resolve(davResource.getHref());
    String name = davResource.getName();
    if (davResource.isDirectory() && href.equals(rootPath)) {
        name = SLASH;/*  w  ww  . j  a  va  2  s  . c o  m*/
    }
    LocalDateTime lastModifiedAt = LocalDateTime.ofInstant(davResource.getModified().toInstant(),
            ZoneId.systemDefault());
    href = rootPath.relativize(href);
    href = URI.create(SLASH).resolve(href).normalize(); // prepend "/" to the href
    OwncloudRestResourceExtension owncloudResource = OwncloudRestResourceImpl.builder().href(href).name(name)
            .lastModifiedAt(lastModifiedAt).mediaType(mediaType)
            .eTag(StringUtils.strip(davResource.getEtag(), QUOTE)).build();
    if (davResource.isDirectory()) {
        return owncloudResource;
    }
    return OwncloudRestFileResourceImpl.fileBuilder().owncloudResource(owncloudResource)
            .contentLength(davResource.getContentLength()).build();
}

From source file:org.helioviewer.jhv.plugins.hekplugin.HEKPlugin.java

public void mouseMoved(MouseEvent e, Vector3d point) {
    HEKEvent lastHEKEvent = mouseOverHEKEvent;

    LocalDateTime in = Plugins.SINGLETON.getCurrentDateTime();
    if (in != null) {
        Date currentDate = Date.from(in.atZone(ZoneId.systemDefault()).toInstant());

        mouseOverHEKEvent = null;//from   ww  w.  ja  va  2  s  .c  o  m
        mouseOverPosition = null;

        List<HEKEvent> toDraw = HEKCache.getSingletonInstance().getModel().getActiveEvents(currentDate);
        if (toDraw.size() > 0) {
            for (HEKEvent evt : toDraw) {
                SphericalCoord stony = evt.getStony(currentDate);
                Vector3d coords = HEKEvent.convertToSceneCoordinates(stony, currentDate);

                double deltaX = Math.abs(point.x - coords.x);
                double deltaY = Math.abs(-point.y - coords.y);
                double deltaZ = Math.abs(point.z - coords.z);
                if (deltaX < 10000000 && deltaZ < 10000000 && deltaY < 10000000) {
                    mouseOverHEKEvent = evt;
                    mouseOverPosition = new Point(e.getX(), e.getY());
                }

            }

            if (lastHEKEvent == null && mouseOverHEKEvent != null) {
                lastCursor = Plugins.getCursor();
                Plugins.setCursor(CURSOR_HELP);
            } else if (lastHEKEvent != null && mouseOverHEKEvent == null) {
                Plugins.setCursor(lastCursor);
            }
        }
    }

}

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

/**
 * Read a date time value from the Cell.
 * /*from   ww  w  .  j ava 2 s .  com*/
 * @param object
 *            the object
 * @param field
 *            the {@link Field} to set
 * @param cell
 *            the {@link Cell} to read
 * @param xlsAnnotation
 *            the {@link XlsElement} element
 * @throws ConverterException
 *             the conversion exception type
 */
protected static void localDateReader(final Object object, final Field field, final Cell cell,
        final XlsElement xlsAnnotation) throws ConverterException {

    if (StringUtils.isNotBlank(readCell(cell))) {
        try {
            if (StringUtils.isBlank(xlsAnnotation.transformMask())) {
                field.set(object,
                        cell.getDateCellValue().toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
            } else {
                String date = cell.getStringCellValue();

                String tM = xlsAnnotation.transformMask();
                String fM = xlsAnnotation.formatMask();
                String decorator = StringUtils.isEmpty(tM)
                        ? (StringUtils.isEmpty(fM) ? CellStyleHandler.MASK_DECORATOR_DATE : fM)
                        : tM;

                SimpleDateFormat dt = new SimpleDateFormat(decorator);

                Date dateConverted = dt.parse(date);
                field.set(object, dateConverted.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
            }
        } catch (ParseException | IllegalArgumentException | IllegalAccessException e) {
            /*
             * if date decorator do not match with a valid mask launch
             * exception
             */
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATE.getMessage(), e);
        }
    }
}

From source file:software.coolstuff.springframework.owncloud.service.impl.local.OwncloudLocalResourceServiceImpl.java

private OwncloudLocalResourceExtension createOwncloudResourceOf(Path path) {
    Path rootPath = getRootLocationOfAuthenticatedUser();
    Path relativePath = rootPath.toAbsolutePath().relativize(path.toAbsolutePath());
    URI href = URI.create(UriComponentsBuilder.fromPath("/").path(relativePath.toString()).toUriString());
    String name = path.getFileName().toString();
    MediaType mediaType = MediaType.APPLICATION_OCTET_STREAM;
    if (Files.isDirectory(path)) {
        href = URI.create(UriComponentsBuilder.fromUri(href).path("/").toUriString());
        mediaType = OwncloudUtils.getDirectoryMediaType();
    } else {/*from  w  w w  . j  a v a  2s.c  o  m*/
        FileNameMap fileNameMap = URLConnection.getFileNameMap();
        String contentType = fileNameMap.getContentTypeFor(path.getFileName().toString());
        if (StringUtils.isNotBlank(contentType)) {
            mediaType = MediaType.valueOf(contentType);
        }
    }
    try {
        LocalDateTime lastModifiedAt = LocalDateTime.ofInstant(Files.getLastModifiedTime(path).toInstant(),
                ZoneId.systemDefault());
        Optional<String> checksum = checksumService.getChecksum(path);
        if (Files.isSameFile(rootPath, path)) {
            name = "/";
            checksum = Optional.empty();
        }
        OwncloudLocalResourceExtension resource = OwncloudLocalResourceImpl.builder().href(href).name(name)
                .eTag(checksum.orElse(null)).mediaType(mediaType).lastModifiedAt(lastModifiedAt).build();
        if (Files.isDirectory(path)) {
            return resource;
        }

        return OwncloudLocalFileResourceImpl.fileBuilder().owncloudResource(resource)
                .contentLength(Files.size(path)).build();
    } catch (NoSuchFileException e) {
        throw new OwncloudResourceNotFoundException(href, getUsername());
    } catch (IOException e) {
        val logMessage = String.format("Cannot create OwncloudResource from Path %s", path);
        log.error(logMessage, e);
        throw new OwncloudLocalResourceException(logMessage, e);
    }
}

From source file:com.bdb.weather.display.summary.HighLowMedianTempPanel.java

@Override
public void chartMouseClicked(ChartMouseEventFX event) {
    ChartEntity entity = event.getEntity();
    ///*from   ww  w.ja v a2 s.c  om*/
    // Was a point on the plot selected?
    //
    if (entity instanceof XYItemEntity) {
        XYItemEntity itemEntity = (XYItemEntity) entity;
        XYDataset dataset = itemEntity.getDataset();
        Number x = dataset.getXValue(itemEntity.getSeriesIndex(), itemEntity.getItem());

        //ZoneId id = ZoneId.of(ZoneId.systemDefault().getId());
        //ZoneOffset offset = ZoneOffset.of(ZoneId.systemDefault().getId());
        LocalDateTime time = LocalDateTime.ofInstant(Instant.ofEpochSecond(x.longValue() / 1000),
                ZoneId.systemDefault());

        boolean doubleClick = event.getTrigger().getClickCount() == 2;
        if (doubleClick)
            supporter.launchView(viewLauncher, time.toLocalDate());
    }
}

From source file:org.tightblog.rendering.generators.WeblogEntryListGeneratorTest.java

@Test
public void getChronoPager() {
    String dateString = "20180110";
    String catName = "stamps";
    String tag = "airmail";
    int pageNum = 2;
    int maxEntries = 3;

    Map<LocalDate, List<WeblogEntry>> entryMap = createSampleEntriesMap();

    when(mockWEM.getDateToWeblogEntryMap(any())).thenReturn(entryMap);
    when(mockUrlService.getWeblogCollectionURL(weblog, catName, dateString, tag, pageNum - 1))
            .thenReturn("nextUrl");
    when(mockUrlService.getWeblogCollectionURL(weblog, catName, dateString, tag, pageNum + 1))
            .thenReturn("prevUrl");

    WeblogEntryListData data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries,
            false);//from  w  ww  .  j ava2 s  .  c o m

    Map<LocalDate, List<WeblogEntry>> results = data.getEntries();
    assertEquals(2, results.size());
    assertEquals(2, results.get(nowLD).size());
    assertEquals(1, results.get(yesterdayLD).size());
    assertEquals("day1story1", results.get(nowLD).get(0).getAnchor());
    assertEquals("day1story2", results.get(nowLD).get(1).getAnchor());
    assertEquals("day2story1", results.get(yesterdayLD).get(0).getAnchor());
    assertEquals("prevUrl", data.getPrevLink());
    assertNotNull(data.getPrevLabel());
    assertEquals("nextUrl", data.getNextLink());
    assertNotNull(data.getNextLabel());

    // test wesc correctly populated
    ArgumentCaptor<WeblogEntrySearchCriteria> captor = ArgumentCaptor.forClass(WeblogEntrySearchCriteria.class);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    WeblogEntrySearchCriteria wesc = captor.getValue();
    assertEquals(weblog, wesc.getWeblog());
    assertEquals(LocalDate.of(2018, 1, 10).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getStartDate());
    assertEquals(
            LocalDate.of(2018, 1, 11).atStartOfDay().minusNanos(1).atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getEndDate());
    assertEquals("stamps", wesc.getCategoryName());
    assertEquals("airmail", wesc.getTag());
    assertEquals(pageNum * maxEntries, wesc.getOffset());
    assertEquals(WeblogEntry.PubStatus.PUBLISHED, wesc.getStatus());
    assertEquals(maxEntries + 1, wesc.getMaxResults());

    // test maxEntries honored
    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, 1, false);
    assertEquals(1, data.getEntries().size());

    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, 0, false);
    assertEquals(0, data.getEntries().size());

    // another wesc test:
    // if sitewide, no weblog
    // if no datestring, no start or end
    // page 0, so no next links
    // moreResults = false so no prev links
    Mockito.clearInvocations(mockWEM);
    dateString = null;
    pageNum = 0;
    maxEntries = 10;
    data = generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertNull(wesc.getWeblog());
    assertNull(wesc.getStartDate());
    assertNull(wesc.getEndDate());
    assertNull(data.getPrevLink());
    assertNull(data.getPrevLabel());
    assertNull(data.getNextLink());
    assertNull(data.getNextLabel());

    // check month format (YYYYMM) correctly processed in search criteria
    Mockito.clearInvocations(mockWEM);
    dateString = "201805";
    generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertEquals(LocalDate.of(2018, 5, 1).atStartOfDay().atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getStartDate());
    assertEquals(
            LocalDate.of(2018, 6, 1).atStartOfDay().minusNanos(1).atZone(ZoneId.systemDefault()).toInstant(),
            wesc.getEndDate());

    // check invalid length of date format (YYYYMMD) ignored in search criteria
    Mockito.clearInvocations(mockWEM);
    dateString = "2018051";
    generator.getChronoPager(weblog, dateString, catName, tag, pageNum, maxEntries, true);
    verify(mockWEM).getDateToWeblogEntryMap(captor.capture());
    wesc = captor.getValue();
    assertNull(wesc.getStartDate());
    assertNull(wesc.getEndDate());
}

From source file:gov.va.isaac.gui.preferences.plugins.ViewCoordinatePreferencesPluginViewController.java

private void setDatePickerFromCurrentTimeProperty() {
    if (currentTimeProperty.get() != Long.MAX_VALUE) {
        runLaterIfNotFXApplicationThread(
                () -> datePicker.setValue(getPriorDay(new Date(currentTimeProperty.get())).toInstant()
                        .atZone(ZoneId.systemDefault()).toLocalDate()));
    } else {/*  ww  w. jav  a2 s  . c  o  m*/
        runLaterIfNotFXApplicationThread(
                () -> datePicker.setValue(new Date().toInstant().atZone(ZoneId.systemDefault()).toLocalDate()));
    }
}

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

@Test
public void testReportGeneratorEndToEnd() throws Exception {
    StockTicker longTicker = new StockTicker("ABC");
    StockTicker shortTicker = new StockTicker("XYZ");

    ZonedDateTime entryOrderTime = ZonedDateTime.of(2016, 3, 25, 6, 18, 35, 0, ZoneId.systemDefault());
    ZonedDateTime exitOrderTime = ZonedDateTime.of(2016, 3, 25, 6, 19, 35, 0, ZoneId.systemDefault());

    String directory = System.getProperty("java.io.tmpdir");
    if (!directory.endsWith("/")) {
        directory += "/";
    }/*from   www .  j  a v a2  s  . c o  m*/
    Path reportPath = Paths.get(directory + "report.csv");
    Files.deleteIfExists(reportPath);
    System.out.println("Creating directory at: " + directory);
    ReportGenerator generator = new ReportGenerator(directory);

    TradeOrder longEntryOrder = new TradeOrder("123", longTicker, 100, TradeDirection.BUY);
    longEntryOrder.setFilledPrice(100.00);
    longEntryOrder.setReference("Intraday-Strategy:guid-123:Entry:Long*");
    longEntryOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    longEntryOrder.setOrderFilledTime(entryOrderTime);

    generator.orderEvent(new OrderEvent(longEntryOrder, null));
    assertFalse(Files.exists(reportPath));

    TradeOrder longExitOrder = new TradeOrder("1234", longTicker, 100, TradeDirection.SELL);
    longExitOrder.setFilledPrice(105.00);
    longExitOrder.setReference("Intraday-Strategy:guid-123:Exit:Long*");
    longExitOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    longExitOrder.setOrderFilledTime(exitOrderTime);

    generator.orderEvent(new OrderEvent(longExitOrder, null));
    assertTrue(Files.exists(reportPath));

    List<String> lines = Files.readAllLines(reportPath);
    assertEquals(1, lines.size());

    String line = lines.get(0);
    String expected = "2016-03-25T06:18:35,LONG,ABC,100,100.0,0,2016-03-25T06:19:35,105.0,0";
    assertEquals(expected, line);

    generator.orderEvent(new OrderEvent(longEntryOrder, null));
    generator.orderEvent(new OrderEvent(longExitOrder, null));

    lines = Files.readAllLines(reportPath);
    assertEquals(2, lines.size());
    assertEquals(expected, lines.get(0));
    assertEquals(expected, lines.get(1));

}

From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java

@Override
@Transactional(readOnly = true)/*from  w w w .j  a va 2  s.  co m*/
public List<DayOfWeek> getJourOuvertCantine(final LocalDate startDate, final Famille famille)
        throws TechnicalException {
    final List<DayOfWeek> jours = new ArrayList<>();
    final Activite activite = getCantineActivite();
    final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille);
    icts.forEach(ict -> {
        final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndDateDebut(
                activite, ict.getGroupe(),
                Date.from(Instant.from(startDate.atStartOfDay(ZoneId.systemDefault()))));
        ouvertures.forEach(o -> {
            final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate());
            if (!jours.contains(date.getDayOfWeek())) {
                jours.add(date.getDayOfWeek());
            }
        });
    });

    return jours;
}