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.sumzerotrading.eod.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  ww w.j ava2  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("EOD-Pair-Strategy:guid-123:Entry:Long*");
    longEntryOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    longEntryOrder.setOrderFilledTime(entryOrderTime);

    TradeOrder shortEntryOrder = new TradeOrder("234", shortTicker, 50, TradeDirection.SELL);
    shortEntryOrder.setFilledPrice(50.00);
    shortEntryOrder.setReference("EOD-Pair-Strategy:guid-123:Entry:Short*");
    shortEntryOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    shortEntryOrder.setOrderFilledTime(entryOrderTime);

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

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

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

    TradeOrder shortExitOrder = new TradeOrder("2345", shortTicker, 50, TradeDirection.BUY);
    shortExitOrder.setFilledPrice(40.00);
    shortExitOrder.setReference("EOD-Pair-Strategy:guid-123:Exit:Short*");
    shortExitOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    shortExitOrder.setOrderFilledTime(exitOrderTime);

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

    generator.orderEvent(new OrderEvent(shortExitOrder, 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,Short,XYZ,50,50.0,0,40.0,0";
    assertEquals(expected, line);

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

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

}

From source file:org.openhab.binding.ntp.test.NtpOSGiTest.java

@Test
@Ignore("https://github.com/eclipse/smarthome/issues/5224")
public void testDateTimeChannelCalendarDefaultTimeZoneUpdate() {
    Configuration configuration = new Configuration();
    // Initialize with configuration with no time zone property set.
    initialize(configuration, NtpBindingConstants.CHANNEL_DATE_TIME, ACCEPTED_ITEM_TYPE_DATE_TIME, null, null);

    ZonedDateTime timeZoneIdFromItemRegistry = ((DateTimeType) getItemState(ACCEPTED_ITEM_TYPE_DATE_TIME))
            .getZonedDateTime();//ww w. j a  v a 2s .  c  om

    ZoneOffset expectedOffset = ZoneId.systemDefault().getRules()
            .getOffset(timeZoneIdFromItemRegistry.toInstant());
    assertEquals(expectedOffset, timeZoneIdFromItemRegistry.getOffset());
}

From source file:org.nuxeo.apidoc.browse.Distribution.java

protected Map<String, Serializable> readFormData(FormData formData) {
    Map<String, Serializable> properties = new HashMap<>();

    // Release date
    String released = formData.getString("released");
    if (StringUtils.isNotBlank(released)) {
        LocalDate date = LocalDate.parse(released);
        Instant instant = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        properties.put(PROP_RELEASED, Date.from(instant));
    }/*from  w ww . j av  a  2s  .  c o  m*/

    return properties;
}

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

@Override
public Region getContent() {
    if (hBox == null) {
        VBox statedInferredToggleGroupVBox = new VBox();
        statedInferredToggleGroupVBox.setSpacing(4.0);

        //Instantiate Everything
        pathComboBox = new ComboBox<>(); //Path
        statedInferredToggleGroup = new ToggleGroup(); //Stated / Inferred
        List<RadioButton> statedInferredOptionButtons = new ArrayList<>();
        datePicker = new DatePicker(); //Date
        timeSelectCombo = new ComboBox<Long>(); //Time

        //Radio buttons
        for (StatedInferredOptions option : StatedInferredOptions.values()) {
            RadioButton optionButton = new RadioButton();
            if (option == StatedInferredOptions.STATED) {
                optionButton.setText("Stated");
            } else if (option == StatedInferredOptions.INFERRED_THEN_STATED) {
                optionButton.setText("Inferred Then Stated");
            } else if (option == StatedInferredOptions.INFERRED) {
                optionButton.setText("Inferred");
            } else {
                throw new RuntimeException("oops");
            }// w  w w  . j av  a  2 s  .  co m
            optionButton.setUserData(option);
            optionButton.setTooltip(
                    new Tooltip("Default StatedInferredOption is " + getDefaultStatedInferredOption()));
            statedInferredToggleGroup.getToggles().add(optionButton);
            statedInferredToggleGroupVBox.getChildren().add(optionButton);
            statedInferredOptionButtons.add(optionButton);
        }
        statedInferredToggleGroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
            @Override
            public void changed(ObservableValue<? extends Toggle> observable, Toggle oldValue,
                    Toggle newValue) {
                currentStatedInferredOptionProperty.set((StatedInferredOptions) newValue.getUserData());
            }
        });

        //Path Combo Box
        pathComboBox.setCellFactory(new Callback<ListView<UUID>, ListCell<UUID>>() {
            @Override
            public ListCell<UUID> call(ListView<UUID> param) {
                final ListCell<UUID> cell = new ListCell<UUID>() {
                    @Override
                    protected void updateItem(UUID c, boolean emptyRow) {
                        super.updateItem(c, emptyRow);
                        if (c == null) {
                            setText(null);
                        } else {
                            String desc = OTFUtility.getDescription(c);
                            setText(desc);
                        }
                    }
                };
                return cell;
            }
        });

        pathComboBox.setButtonCell(new ListCell<UUID>() { // Don't know why this should be necessary, but without this the UUID itself is displayed
            @Override
            protected void updateItem(UUID c, boolean emptyRow) {
                super.updateItem(c, emptyRow);
                if (emptyRow) {
                    setText("");
                } else {
                    String desc = OTFUtility.getDescription(c);
                    setText(desc);
                }
            }
        });
        pathComboBox.setOnAction((event) -> {
            if (!pathComboFirstRun) {
                UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem();
                if (selectedPath != null) {
                    int path = OTFUtility.getConceptVersion(selectedPath).getPathNid();

                    StampBdb stampDb = Bdb.getStampDb();
                    NidSet nidSet = new NidSet();
                    nidSet.add(path);
                    //TODO: Make this multi-threaded and possibly implement setTimeOptions() here also
                    NidSetBI stamps = stampDb.getSpecifiedStamps(nidSet, Long.MIN_VALUE, Long.MAX_VALUE);

                    pathDatesList.clear();
                    //                  disableTimeCombo(true);
                    timeSelectCombo.setValue(Long.MAX_VALUE);

                    for (Integer thisStamp : stamps.getAsSet()) {
                        try {
                            Position stampPosition = stampDb.getPosition(thisStamp);
                            this.stampDate = new Date(stampPosition.getTime());
                            stampDateInstant = stampDate.toInstant().atZone(ZoneId.systemDefault())
                                    .toLocalDate();
                            this.pathDatesList.add(stampDateInstant); //Build DatePicker
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                    datePicker.setValue(LocalDate.now());
                }
            } else {
                pathComboFirstRun = false;
            }
        });

        pathComboBox.setTooltip(
                new Tooltip("Default path is \"" + OTFUtility.getDescription(getDefaultPath()) + "\""));

        //Calendar Date Picker
        final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
            @Override
            public DateCell call(final DatePicker datePicker) {
                return new DateCell() {
                    @Override
                    public void updateItem(LocalDate thisDate, boolean empty) {
                        super.updateItem(thisDate, empty);
                        if (pathDatesList != null) {
                            if (pathDatesList.contains(thisDate)) {
                                setDisable(false);
                            } else {
                                setDisable(true);
                            }
                        }
                    }
                };
            }
        };
        datePicker.setDayCellFactory(dayCellFactory);
        datePicker.setOnAction((event) -> {
            if (!datePickerFirstRun) {
                UUID selectedPath = pathComboBox.getSelectionModel().getSelectedItem();

                Instant instant = Instant.from(datePicker.getValue().atStartOfDay(ZoneId.systemDefault()));
                Long dateSelected = Date.from(instant).getTime();

                if (selectedPath != null && dateSelected != 0) {

                    int path = OTFUtility.getConceptVersion(selectedPath).getPathNid();
                    setTimeOptions(path, dateSelected);
                    try {
                        timeSelectCombo.setValue(times.first()); //Default Dropdown Value
                    } catch (Exception e) {
                        // Eat it.. like a sandwich! TODO: Create Read Only Property Conditional for checking if Time Combo is disabled
                        // Right now, Sometimes Time Combo is disabled, so we catch this and eat it
                        // Otherwise make a conditional from the Read Only Boolean Property to check first
                    }
                } else {
                    disableTimeCombo(false);
                    logger.debug("The path isn't set or the date isn't set. Both are needed right now");
                }
            } else {
                datePickerFirstRun = false;
            }
        });

        //Commit-Time ComboBox
        timeSelectCombo.setMinWidth(200);
        timeSelectCombo.setCellFactory(new Callback<ListView<Long>, ListCell<Long>>() {
            @Override
            public ListCell<Long> call(ListView<Long> param) {
                final ListCell<Long> cell = new ListCell<Long>() {
                    @Override
                    protected void updateItem(Long item, boolean emptyRow) {
                        super.updateItem(item, emptyRow);
                        if (item == null) {
                            setText("");
                        } else {
                            if (item == Long.MAX_VALUE) {
                                setText("LATEST TIME");
                            } else {
                                setText(timeFormatter.format(new Date(item)));
                            }
                        }
                    }
                };
                return cell;
            }
        });
        timeSelectCombo.setButtonCell(new ListCell<Long>() {
            @Override
            protected void updateItem(Long item, boolean emptyRow) {
                super.updateItem(item, emptyRow);
                if (item == null) {
                    setText("");
                } else {
                    if (item == Long.MAX_VALUE) {
                        setText("LATEST TIME");
                    } else {
                        setText(timeFormatter.format(new Date(item)));
                    }
                }
            }
        });

        try {
            currentPathProperty.bind(pathComboBox.getSelectionModel().selectedItemProperty()); //Set Path Property
            currentTimeProperty.bind(timeSelectCombo.getSelectionModel().selectedItemProperty());
        } catch (Exception e) {
            e.printStackTrace();
        }

        // DEFAULT VALUES
        UserProfile loggedIn = ExtendedAppContext.getCurrentlyLoggedInUserProfile();
        storedTimePref = loggedIn.getViewCoordinateTime();
        storedPathPref = loggedIn.getViewCoordinatePath();

        if (storedPathPref != null) {
            pathComboBox.getItems().clear(); //Set the path Dates by default
            pathComboBox.getItems().addAll(getPathOptions());
            final UUID storedPath = getStoredPath();
            if (storedPath != null) {
                pathComboBox.getSelectionModel().select(storedPath);
            }

            if (storedTimePref != null) {
                final Long storedTime = loggedIn.getViewCoordinateTime();
                Calendar cal = Calendar.getInstance();
                cal.setTime(new Date(storedTime));
                cal.set(Calendar.MILLISECOND, 0); //Strip milliseconds
                Long storedTruncTime = cal.getTimeInMillis();

                if (!storedTime.equals(Long.MAX_VALUE)) { //***** FIX THIS, not checking default vc time value
                    int path = OTFUtility.getConceptVersion(storedPathPref).getPathNid();
                    setTimeOptions(path, storedTimePref);
                    timeSelectCombo.setValue(storedTruncTime);
                    //                  timeSelectCombo.getItems().addAll(getTimeOptions()); //The correct way, but doesen't work

                    Date storedDate = new Date(storedTime);
                    datePicker.setValue(storedDate.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
                } else {
                    datePicker.setValue(LocalDate.now());
                    timeSelectCombo.getItems().addAll(Long.MAX_VALUE); //The correct way, but doesen't work
                    timeSelectCombo.setValue(Long.MAX_VALUE);
                    //                  disableTimeCombo(false);
                }
            } else { //Stored Time Pref == null
                logger.error("ERROR: Stored Time Preference = null");
            }
        } else { //Stored Path Pref == null
            logger.error("We could not load a stored path, ISAAC cannot run");
            throw new Error("No stored PATH could be found. ISAAC can't run without a path");
        }

        GridPane gridPane = new GridPane();
        gridPane.setHgap(10);
        gridPane.setVgap(10);

        Label pathLabel = new Label("View Coordinate Path");
        gridPane.add(pathLabel, 0, 0); //Path Label - Row 0
        GridPane.setHalignment(pathLabel, HPos.LEFT);
        gridPane.add(statedInferredToggleGroupVBox, 1, 0, 1, 2); //--Row 0, span 2

        gridPane.add(pathComboBox, 0, 1); //Path Combo box - Row 2
        GridPane.setValignment(pathComboBox, VPos.TOP);

        Label datePickerLabel = new Label("View Coordinate Dates");
        gridPane.add(datePickerLabel, 0, 2); //Row 3
        GridPane.setHalignment(datePickerLabel, HPos.LEFT);
        gridPane.add(datePicker, 0, 3); //Row 4

        Label timeSelectLabel = new Label("View Coordinate Times");
        gridPane.add(timeSelectLabel, 1, 2); //Row 3
        GridPane.setHalignment(timeSelectLabel, HPos.LEFT);
        gridPane.add(timeSelectCombo, 1, 3); //Row 4

        // FOR DEBUGGING CURRENTLY SELECTED PATH, TIME AND POLICY
        /*         
                 UserProfile userProfile = ExtendedAppContext.getCurrentlyLoggedInUserProfile();
                 StatedInferredOptions chosenPolicy = userProfile.getStatedInferredPolicy();
                 UUID chosenPathUuid = userProfile.getViewCoordinatePath();
                 Long chosenTime = userProfile.getViewCoordinateTime();
                         
                 Label printSelectedPathLabel = new Label("Path: " + OTFUtility.getDescription(chosenPathUuid));
                 gridPane.add(printSelectedPathLabel, 0, 4);
                 GridPane.setHalignment(printSelectedPathLabel, HPos.LEFT);
                 Label printSelectedTimeLabel = null;
                 if(chosenTime != getDefaultTime()) {
                    printSelectedTimeLabel = new Label("Time: " + dateFormat.format(new Date(chosenTime)));
                 } else {
                    printSelectedTimeLabel = new Label("Time: LONG MAX VALUE");
                 }
                 gridPane.add(printSelectedTimeLabel, 1, 4);
                 GridPane.setHalignment(printSelectedTimeLabel, HPos.LEFT);
                 Label printSelectedPolicyLabel = new Label("Policy: " + chosenPolicy);
                 gridPane.add(printSelectedPolicyLabel, 2, 4);
                 GridPane.setHalignment(printSelectedPolicyLabel, HPos.LEFT);
                 */
        hBox = new HBox();
        hBox.getChildren().addAll(gridPane);

        allValid_ = new ValidBooleanBinding() {
            {
                bind(currentStatedInferredOptionProperty, currentPathProperty, currentTimeProperty);
                setComputeOnInvalidate(true);
            }

            @Override
            protected boolean computeValue() {
                if (currentStatedInferredOptionProperty.get() == null) {
                    this.setInvalidReason("Null/unset/unselected StatedInferredOption");
                    for (RadioButton button : statedInferredOptionButtons) {
                        TextErrorColorHelper.setTextErrorColor(button);
                    }
                    return false;
                } else {
                    for (RadioButton button : statedInferredOptionButtons) {
                        TextErrorColorHelper.clearTextErrorColor(button);
                    }
                }
                if (currentPathProperty.get() == null) {
                    this.setInvalidReason("Null/unset/unselected path");
                    TextErrorColorHelper.setTextErrorColor(pathComboBox);

                    return false;
                } else {
                    TextErrorColorHelper.clearTextErrorColor(pathComboBox);
                }
                if (OTFUtility.getConceptVersion(currentPathProperty.get()) == null) {
                    this.setInvalidReason("Invalid path");
                    TextErrorColorHelper.setTextErrorColor(pathComboBox);

                    return false;
                } else {
                    TextErrorColorHelper.clearTextErrorColor(pathComboBox);
                }
                //               if(currentTimeProperty.get() == null && currentTimeProperty.get() != Long.MAX_VALUE)
                //               {
                //                  this.setInvalidReason("View Coordinate Time is unselected");
                //                  TextErrorColorHelper.setTextErrorColor(timeSelectCombo);
                //                  return false;
                //               }
                this.clearInvalidReason();
                return true;
            }
        };
    }
    //      createButton.disableProperty().bind(saveButtonValid.not()));

    // Reload persisted values every time
    final StatedInferredOptions storedStatedInferredOption = getStoredStatedInferredOption();
    for (Toggle toggle : statedInferredToggleGroup.getToggles()) {
        if (toggle.getUserData() == storedStatedInferredOption) {
            toggle.setSelected(true);
        }
    }

    //      pathComboBox.setButtonCell(new ListCell<UUID>() {
    //         @Override
    //         protected void updateItem(UUID c, boolean emptyRow) {
    //            super.updateItem(c, emptyRow); 
    //            if (emptyRow) {
    //               setText("");
    //            } else {
    //               String desc = OTFUtility.getDescription(c);
    //               setText(desc);
    //            }
    //         }
    //      });
    //      timeSelectCombo.setButtonCell(new ListCell<Long>() {
    //         @Override
    //         protected void updateItem(Long item, boolean emptyRow) {
    //            super.updateItem(item, emptyRow); 
    //            if (emptyRow) {
    //               setText("");
    //            } else {
    //               setText(timeFormatter.format(new Date(item)));
    //            }
    //         }
    //      });

    //      datePickerFirstRun = false;
    //      pathComboFirstRun = false;

    return hBox;
}

From source file:io.stallion.dataAccess.file.TextFilePersister.java

protected void setProperty(TextItem item, String key, Object value) {
    if (key.equals("slug")) {
        item.setSlug(value.toString());//w  w w  .  jav a2 s . c  o m
    } else if (key.equals("title")) {
        item.setTitle(value.toString());
    } else if (key.equals("publishDate")) {
        for (DateTimeFormatter formatter : localDateFormats) {
            if (item.getSlug().equals("/future-dated")) {
                Log.info("future");
            }
            try {
                LocalDateTime dt = LocalDateTime.parse(value.toString(), formatter);
                ZoneId zoneId = ZoneId.systemDefault();
                if (Context.getSettings() != null && Context.getSettings().getTimeZoneId() != null) {
                    zoneId = Context.getSettings().getTimeZoneId();
                }
                item.setPublishDate(ZonedDateTime.of(dt, zoneId));
                return;
            } catch (DateTimeParseException e) {

            }
        }
        for (DateTimeFormatter formatter : zonedDateFormats) {
            try {
                ZonedDateTime dt = ZonedDateTime.parse(value.toString(), formatter);
                item.setPublishDate(dt);
                return;
            } catch (DateTimeParseException e) {

            }
        }

    } else if (key.equals("draft")) {
        item.setDraft(value.equals("true"));
    } else if (key.equals("template")) {
        item.setTemplate(value.toString());
    } else if (key.equals("author")) {
        item.setAuthor(value.toString());
    } else if (key.equals("tags")) {
        if (value instanceof List) {
            item.setTags((List<String>) value);
        } else {
            ArrayList<String> tags = new ArrayList<String>();
            for (String tag : value.toString().split("(;|,)")) {
                tags.add(tag.trim());
            }
            item.setTags(tags);

        }
    } else if (key.equals("contentType")) {
        item.setContentType(value.toString());
    } else {
        item.put(key, value);
    }

}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static LocalDate toLocalDate(Date date) throws BusinessException {
    return date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static Date toDate(LocalDate localDate) throws BusinessException {
    return Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}

From source file:com.sumzerotrading.reporting.csv.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  w  w w. ja v a 2s .  co  m
    Path reportPath = Paths.get(directory + "report.csv");
    Files.deleteIfExists(reportPath);
    System.out.println("Creating directory at: " + directory);
    ReportGenerator generator = new ReportGenerator("EOD-Pair-Strategy", directory, pairRoundtripBuilder);

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

    TradeOrder shortEntryOrder = new TradeOrder("234", shortTicker, 50, TradeDirection.SELL);
    shortEntryOrder.setFilledPrice(50.00);
    shortEntryOrder.setReference("EOD-Pair-Strategy:guid-123:Entry:Short*");
    shortEntryOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    shortEntryOrder.setOrderFilledTime(entryOrderTime);

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

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

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

    TradeOrder shortExitOrder = new TradeOrder("2345", shortTicker, 50, TradeDirection.BUY);
    shortExitOrder.setFilledPrice(40.00);
    shortExitOrder.setReference("EOD-Pair-Strategy:guid-123:Exit:Short*");
    shortExitOrder.setCurrentStatus(OrderStatus.Status.FILLED);
    shortExitOrder.setOrderFilledTime(exitOrderTime);

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

    generator.orderEvent(new OrderEvent(shortExitOrder, 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,Short,XYZ,50,50.0,0,40.0,0";
    assertEquals(expected, line);

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

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

}

From source file:com.basp.trabajo_al_minuto.model.business.BusinessUtils.java

public static Date toDate(LocalDateTime localDateTime) throws BusinessException {
    return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
}

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

/**
 * Read a date time value from the Cell.
 * /*from   ww w.j  a v  a 2 s  .c  o m*/
 * @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 localDateTimeReader(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()).toLocalDateTime());
            } 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()).toLocalDateTime());
            }
        } catch (ParseException | IllegalArgumentException | IllegalAccessException e) {
            /*
             * if date decorator do not match with a valid mask launch
             * exception
             */
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATETIME.getMessage(), e);
        }
    }
}