@Test public void test1() { final LocalDate startDate = LocalDate.of(2000, 1, 1); final LocalDate endDate = LocalDate.of(2002, 2, 9); final int months = 25; final LocalDate[] forward = CALCULATOR.getSchedule(startDate, endDate, false, true); assertEquals(forward.length, months); final LocalDate firstDate = LocalDate.of(2000, 1, 31); assertEquals(forward[0], firstDate); final LocalDate lastDate = LocalDate.of(2002, 1, 31); assertEquals(forward[months - 1], lastDate); LocalDate d1; for (int i = 1; i < months; i++) { d1 = forward[i]; if (d1.getYear() == forward[i - 1].getYear()) { assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), 1); } else { assertEquals(d1.getMonthValue() - forward[i - 1].getMonthValue(), -11); } assertEquals(d1.getDayOfMonth(), d1.lengthOfMonth()); } assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, false), forward); assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, true, true), forward); assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, false), forward); assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate, false, true), forward); assertArrayEquals(CALCULATOR.getSchedule(startDate, endDate), forward); }
@Test public void testGetAge() { LocalDate now = LocalDate.now(); int currentYear = now.getYear(); LocalDate birthDate = LocalDate.of(2010, 2, 1); Period age = AgeUtils.getAge(birthDate); // P6Y1M21D Assert.assertEquals(currentYear - birthDate.getYear(), age.getYears()); Assert.assertEquals(now.getMonthValue() - birthDate.getMonthValue(), age.getMonths()); Assert.assertEquals(now.getDayOfMonth() - birthDate.getDayOfMonth(), age.getDays()); }
private int diff360EIsma(final LocalDate start, final LocalDate end) { int dayStart = start.getDayOfMonth(); int dayEnd = end.getDayOfMonth(); if (dayEnd == MONTH_31_DAYS) { dayEnd = MONTH_30_DAYS; } if (dayStart == MONTH_31_DAYS) { dayStart = MONTH_30_DAYS; } return (end.getYear() - start.getYear()) * YEAR_360 + (end.getMonthValue() - start.getMonthValue()) * MONTH_30_DAYS + dayEnd - dayStart; }
private String getStringDate(LocalDate issueDate) { return String.format("%02d", issueDate.getDayOfMonth()) + "/" + String.format("%02d", issueDate.getMonthValue()) + "/" + String.format("%02d", issueDate.getYear()); }
// See https://en.wikipedia.org/wiki/Day_count_convention#30E.2F360_ISDA private int diff360EIsda(final LocalDate start, final LocalDate end) { if (start.equals(end)) { return 0; } int dayStart = start.getDayOfMonth(); int dayEnd = end.getDayOfMonth(); if (start.getMonth().length(start.isLeapYear()) == dayStart) { dayStart = MONTH_30_DAYS; } if (end.getMonth() != Month.FEBRUARY && end.getMonth().length(end.isLeapYear()) == dayEnd) { dayEnd = MONTH_30_DAYS; } return (end.getYear() - start.getYear()) * YEAR_360 + (end.getMonthValue() - start.getMonthValue()) * MONTH_30_DAYS + dayEnd - dayStart; }
@Override public void serialize( LocalDate localDate, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { jsonGenerator.writeObject( new JSONDateFormat( localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth(), localDate.getDayOfWeek().toString())); }
public String generateName(final Entity product) { LocalDate date = LocalDate.now(); String currentDateString = String.format("%s.%s", date.getYear(), date.getMonthValue()); String productName = product.getStringField(ProductFields.NAME); String productNumber = product.getStringField(ProductFields.NUMBER); return translationService.translate( "technologies.operation.name.default", LocaleContextHolder.getLocale(), productName, productNumber, currentDateString); }
@FXML private void saveNewMatch() throws RemoteException { if (validateInput()) { MatchDTO newMatch = new MatchDTOImpl(); newMatch.setDuration(_duration); Calendar cal = new GregorianCalendar(); cal.set( _localDate.getYear(), _localDate.getMonthValue(), _localDate.getDayOfMonth(), _localTime.getHour(), _localTime.getMinute(), _localTime.getSecond()); newMatch.setStart(cal.getTime()); MatchDTOImpl.SimpleMatchTeamDTO team1 = new MatchDTOImpl.SimpleMatchTeamDTO( _allTeamsTableView.getSelectionModel().getSelectedItem().getId()); team1.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId()); team1.setName(_allTeamsTableView.getSelectionModel().getSelectedItem().getName()); team1.setVersion(_allTeamsTableView.getSelectionModel().getSelectedItem().getVersion()); MatchDTOImpl.SimpleMatchTeamDTO team2 = new MatchDTOImpl.SimpleMatchTeamDTO( _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId()); team2.setId(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getId()); team2.setName(_allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getName()); team2.setVersion( _allTeamsOpponentTableView.getSelectionModel().getSelectedItem().getVersion()); newMatch.setTeam1(team1); newMatch.setTeam2(team2); newMatch.setTournamentId(_tournament.getId()); newMatch.setMatchStatus("Planned"); _tournament.addMatch(newMatch); initSuccessAlert(); // todo fix correct weiterleitung if (_newTournament) { SportifyGUI.getSharedMainApp().loadNewTournamentView(_tournament, _externalDisplayTeamDTOs); } else { SportifyGUI.getSharedMainApp().loadEditTournamentForm(_tournament); } } }
public void changes(ActionEvent event) throws IOException { String new_cat, new_money, temp, dates; int new_money1; localdate = date.getValue(); dates = date.getValue().toString(); new_cat = cat.getText(); new_money = money.getText(); if (new_cat == "" || new_money == "") { lb2.setText("Enter values"); } new_money1 = Integer.parseInt(new_money); if (new_money1 > Available1) { lb2.setText("Budget Exceeded"); lb2.setTextFill(Color.ORANGE); } else { expense = expense + new_money1; lb2.setText("Added"); lb2.setTextFill(Color.GREEN); Available1 = Available1 - new_money1; temp = Integer.toString(Available1); Expense_Available.setText(temp); RandomAccessFile q = new RandomAccessFile("./src/Expenses.txt", "rw"); q.readLine(); q.write(("AvailableRs. " + temp).getBytes()); q.seek(0); while (q.readLine() != null) { q.readLine(); } q.write( (new_cat + " " + new_money + " " + localdate.getYear() + "/" + localdate.getMonthValue() + "/" + localdate.getDayOfMonth() + "\n") .getBytes()); q.close(); data.add(new Expense(new_cat, new_money1, dates)); table.setItems(data); } }
public TransactionRow( LocalDate transactionDate, Double transactionVolume, Double transactionAmount, Double transactionBalance, TransactionType transactionType, String securityName) { this.transactionDate = transactionDate; this.transactionVolume = transactionVolume; this.transactionAmount = transactionAmount; this.transactionBalance = transactionBalance; this.transactionType = transactionType; if (securityName.equals("880013")) securityName = ""; this.securityName = securityName; Integer year = transactionDate.getYear(); Integer month = transactionDate.getMonthValue(); this.yearMonth = year.toString() + month.toString(); }
@FXML private void initialize() { ObservableList<String> kunden = FXCollections.observableArrayList(KundeSession.getAllKundenNamen()); kunden.add(0, "Alle"); kundenChoiceBox.setItems(kunden); kundenChoiceBox.setValue("Alle"); String dm = now.getDayOfMonth() + "." + now.getMonthValue() + "."; day1Label.setText("1.1. - " + dm); day2Label.setText("1.1. - " + dm); List<Auftrag> auftraege = AuftragSession.getAllAuftraege(); auftraege.sort(Comparator.comparing(Auftrag::getErstellung)); LocalDate oldestAuftrag = auftraege.get(0).getErstellung(); ObservableList<Number> years = FXCollections.observableArrayList(); for (int i = now.getYear(); i >= oldestAuftrag.getYear(); i--) { years.add(i); } year1ChoiceBox.setItems(years); year1ChoiceBox.setValue(years.get(1)); year2ChoiceBox.setItems(years); year2ChoiceBox.setValue(years.get(0)); calculate(); pNrColumn.setCellValueFactory(cellData -> cellData.getValue().produktNr); bezColumn.setCellValueFactory(cellData -> cellData.getValue().bezeichnung); bildColumn.setCellValueFactory(cellData -> cellData.getValue().bild); bildColumn.setCellFactory(imageCellFactory); s1Column.setCellValueFactory(cellData -> cellData.getValue().stuckzahl1); u1Column.setCellValueFactory(cellData -> cellData.getValue().umsatz1); s2Column.setCellValueFactory(cellData -> cellData.getValue().stuckzahl2); u2Column.setCellValueFactory(cellData -> cellData.getValue().umsatz2); pInfoTable.setItems(dataShow); kundenChoiceBox.valueProperty().addListener(observable -> calculate()); year1ChoiceBox.valueProperty().addListener(observable -> calculate()); year2ChoiceBox.valueProperty().addListener(observable -> calculate()); }
public static List<Descriptor> getDescriptors( @NotNull ReportPeriod reportPeriod, @NotNull LocalDate startDate, @NotNull LocalDate endDate) { final List<Descriptor> descriptors = new ArrayList<>(); LocalDate start = startDate; LocalDate end = startDate; switch (reportPeriod) { case YEARLY: while (end.isBefore(endDate)) { end = end.with(TemporalAdjusters.lastDayOfYear()); descriptors.add(new Descriptor(start, end, " " + start.getYear())); start = end.plusDays(1); } break; case QUARTERLY: int i = DateUtils.getQuarterNumber(start) - 1; while (end.isBefore(endDate)) { end = DateUtils.getLastDayOfTheQuarter(start); descriptors.add(new Descriptor(start, end, " " + start.getYear() + "-Q" + (1 + i++ % 4))); start = end.plusDays(1); } break; case MONTHLY: while (end.isBefore(endDate)) { end = DateUtils.getLastDayOfTheMonth(start); final int month = start.getMonthValue(); descriptors.add( new Descriptor( start, end, " " + start.getYear() + (month < 10 ? "/0" + month : "/" + month))); start = end.plusDays(1); } break; default: } return descriptors; }
public static void main(String[] args) { /* try { Class<HelloWorld> t = (Class<HelloWorld>) Class.forName("com.gaohuan.HelloWorld"); HelloWorld h = t.newInstance(); h.hello(); } catch (Exception e) { e.printStackTrace(); } */ LocalDate localDate = LocalDate.now(); System.out.println(localDate.getYear()); System.out.println(localDate.getMonthValue()); System.out.println(localDate.getDayOfMonth()); User user = new User(); user.setUid("aaaa"); user.setName("bbbb"); user.setSex("1"); BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(user); source.getReadablePropertyNames(); }
private void updateViewModel() { setText(null); setGraphic(null); if (getItem() != null) { BorderPane mainBox = new BorderPane(); mainBox.setPadding(new Insets(3.0, 5.0, 3.0, 3.0)); VBox taskNameDisplay = new VBox(); taskNameDisplay.setAlignment(Pos.CENTER_LEFT); Text taskNameText = new Text(); taskNameDisplay.getChildren().addAll(taskNameText); HBox priorityDueDateDisplay = new HBox(); priorityDueDateDisplay.setAlignment(Pos.CENTER_RIGHT); Text taskPriorityText = new Text(); Text taskDueDateText = new Text(); taskPriorityText.setScaleX(1.25); taskPriorityText.setScaleY(1.25); priorityDueDateDisplay.setSpacing(40); priorityDueDateDisplay.getChildren().addAll(taskDueDateText, taskPriorityText); mainBox.leftProperty().set(taskNameDisplay); mainBox.rightProperty().set(priorityDueDateDisplay); mainBox.setMargin(mainBox.getLeft(), new Insets(0, 20, 0, 0)); Task currentTask = getItem(); int currentTaskPriority = currentTask.getPriority(); // setting task name to be displayed by the cell taskNameText.setText(currentTask.getTaskTitle()); // setting task due date to be displayed by the cell if (currentTask.getTaskDueDate() != null) { LocalDate currentDueDate = currentTask.getTaskDueDate(); taskDueDateText.setText( currentDueDate.getMonthValue() + "/" + currentDueDate.getDayOfMonth() + "/" + currentDueDate.getYear()); } // setting task priority to be displayed by the cell switch (currentTaskPriority) { case 1: { taskPriorityText.setText("!"); taskPriorityText.setFill(Color.web("#28ae33")); break; } case 2: { taskPriorityText.setText("!!"); taskPriorityText.setFill(Color.web("#babf23")); break; } case 3: { taskPriorityText.setText("!!!"); taskPriorityText.setFill(Color.web("#ee0606")); break; } default: { } } if (!currentTask.getComplete()) { taskNameText.setStrikethrough(false); } else { // if task is completed, strike out the task name mainBox.setOpacity(0.5); taskNameText.setStrikethrough(true); } setText(null); setGraphic(mainBox); } }
public static List<SecurityHistoryNode> downloadHistory( final SecurityNode securityNode, final LocalDate startDate, final LocalDate endDate) { final List<SecurityHistoryNode> newSecurityNodes = new ArrayList<>(); final String s = securityNode.getSymbol().toLowerCase(); final String a = Integer.toString(startDate.getMonthValue() - 1); final String b = Integer.toString(startDate.getDayOfMonth()); final String c = Integer.toString(startDate.getYear()); final String d = Integer.toString(endDate.getMonthValue() - 1); final String e = Integer.toString(endDate.getDayOfMonth()); final String f = Integer.toString(endDate.getYear()); // http://ichart.finance.yahoo.com/table.csv?s=AMD&d=1&e=14&f=2007&g=d&a=2&b=21&c=1983&ignore=.csv << new URL 2.14.07 StringBuilder r = new StringBuilder("http://ichart.finance.yahoo.com/table.csv?a="); r.append(a).append("&b=").append(b).append("&c=").append(c); r.append("&d=").append(d).append("&e=").append(e); r.append("&f=").append(f).append("&s=").append(s); r.append("&y=0&g=d&ignore=.csv"); URLConnection connection = null; try { /* Yahoo uses the English locale for the date... force the locale */ final SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); connection = ConnectionFactory.openConnection(r.toString()); if (connection != null) { // Read, parse, and load the new history nodes into a list to be persisted later. A // relational // database may stall and cause the network connection to timeout if persisted inline try (final BufferedReader in = new BufferedReader( new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) { String line = in.readLine(); // make sure that we have valid data format. if (RESPONSE_HEADER.equals(line)) { // Date,Open,High,Low,Close,Volume,Adj Close // 2007-02-13,14.75,14.86,14.47,14.60,17824500,14.60 line = in.readLine(); // prime the first read while (line != null) { if (Thread.currentThread().isInterrupted()) { Thread.currentThread().interrupt(); } if (line.charAt(0) != '<') { // may have comments in file final String[] fields = COMMA_DELIMITER_PATTERN.split(line); final LocalDate date = DateUtils.asLocalDate(df.parse(fields[0])); final BigDecimal high = new BigDecimal(fields[2]); final BigDecimal low = new BigDecimal(fields[3]); final BigDecimal close = new BigDecimal(fields[4]); final long volume = Long.parseLong(fields[5]); newSecurityNodes.add(new SecurityHistoryNode(date, close, volume, high, low)); } line = in.readLine(); } } } logger.info(ResourceUtils.getString("Message.UpdatedPrice", securityNode.getSymbol())); } } catch (NullPointerException | IOException | ParseException | NumberFormatException ex) { logger.log(Level.SEVERE, null, ex); } finally { if (connection != null) { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).disconnect(); } } } return newSecurityNodes; }
private MonthDay convertFromDate(Date ts) { LocalDate localDate = ts.toLocalDate(); return MonthDay.of(localDate.getMonthValue(), localDate.getDayOfMonth()); }