Java Code Examples for java.time.LocalDate#toString()
The following examples show how to use
java.time.LocalDate#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PDTFromStringTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testDefaultToStringAndBack () { final ZonedDateTime aDT = PDTFactory.getCurrentZonedDateTime (); String sDT = aDT.toString (); assertEquals (aDT, ZonedDateTime.parse (sDT)); final LocalDateTime aLDT = PDTFactory.getCurrentLocalDateTime (); sDT = aLDT.toString (); assertEquals (aLDT, LocalDateTime.parse (sDT)); final LocalDate aLD = PDTFactory.getCurrentLocalDate (); sDT = aLD.toString (); assertEquals (aLD, LocalDate.parse (sDT)); final LocalTime aLT = PDTFactory.getCurrentLocalTime (); sDT = aLT.toString (); assertEquals (aLT, LocalTime.parse (sDT)); }
Example 2
Source File: PeriodServiceImpl.java From axelor-open-suite with GNU Affero General Public License v3.0 | 6 votes |
/** * Fetches the active period with the date, company and type in parameter * * @param date * @param company * @param typeSelect * @return * @throws AxelorException */ public Period getActivePeriod(LocalDate date, Company company, int typeSelect) throws AxelorException { Period period = this.getPeriod(date, company, typeSelect); if (period == null || (period.getStatusSelect() == PeriodRepository.STATUS_CLOSED)) { String dateStr = date != null ? date.toString() : ""; throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), dateStr); } LOG.debug("Period : {}", period); return period; }
Example 3
Source File: DbJob.java From litemall with MIT License | 6 votes |
@Scheduled(cron = "0 0 5 * * ?") public void backup() throws IOException { logger.info("系统开启定时任务数据库备份"); String user = environment.getProperty("spring.datasource.druid.username"); String password = environment.getProperty("spring.datasource.druid.password"); String url = environment.getProperty("spring.datasource.druid.url"); int index1 = url.indexOf("3306/"); int index2 = url.indexOf("?"); String db = url.substring(index1+5, index2); LocalDate localDate = LocalDate.now(); String fileName = localDate.toString(); File file = new File("backup", fileName); file.getParentFile().mkdirs(); file.createNewFile(); // 备份今天数据库 DbUtil.backup(file, user, password, db); // 删除七天前数据库备份文件 LocalDate before = localDate.minusDays(7); File fileBefore = new File("backup", fileName); fileBefore.deleteOnExit(); logger.info("系统结束定时任务数据库备份"); }
Example 4
Source File: LegalEntityRatesCurvesCsvLoader.java From Strata with Apache License 2.0 | 5 votes |
private static Curve queryCurve( CurveName name, Map<CurveName, Curve> curves, LocalDate date, CurveGroupName groupName, String curveType) { Curve curve = curves.get(name); if (curve == null) { throw new IllegalArgumentException( curveType + " curve values for " + name.toString() + " in group " + groupName.getName() + " are missing on " + date.toString()); } return curve; }
Example 5
Source File: TCKLocalDate.java From j2objc with Apache License 2.0 | 5 votes |
@Test() @UseDataProvider("provider_sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 6
Source File: DbTest.java From litemall with MIT License | 5 votes |
@Test public void testFileDelete() throws IOException { LocalDate localDate = LocalDate.now(); String fileName = localDate.toString() + ".sql"; System.out.println(fileName); File file = new File("backup", fileName); file.deleteOnExit(); }
Example 7
Source File: LocalDateXmlAdapter.java From kogito-runtimes with Apache License 2.0 | 5 votes |
@Override public String marshal( LocalDate localDateObject ) throws Exception { if ( localDateObject == null ) { return null; } return localDateObject.toString(); }
Example 8
Source File: SqlDialect.java From sqlg with MIT License | 4 votes |
default String toRDBSStringLiteral(PropertyType propertyType, Object value) { switch (propertyType.ordinal()) { case BOOLEAN_ORDINAL: Boolean b = (Boolean) value; return b.toString(); case BYTE_ORDINAL: Byte byteValue = (Byte) value; return byteValue.toString(); case SHORT_ORDINAL: Short shortValue = (Short) value; return shortValue.toString(); case INTEGER_ORDINAL: Integer intValue = (Integer) value; return intValue.toString(); case LONG_ORDINAL: Long longValue = (Long) value; return longValue.toString(); case FLOAT_ORDINAL: Float floatValue = (Float) value; return floatValue.toString(); case DOUBLE_ORDINAL: Double doubleValue = (Double) value; return doubleValue.toString(); case STRING_ORDINAL: return "'" + value.toString() + "'"; case LOCALDATE_ORDINAL: LocalDate localDateValue = (LocalDate) value; return "'" + localDateValue.toString() + "'"; case LOCALDATETIME_ORDINAL: LocalDateTime localDateTimeValue = (LocalDateTime) value; return "'" + localDateTimeValue.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME) + "'"; case LOCALTIME_ORDINAL: LocalTime localTimeValue = (LocalTime) value; return "'" + localTimeValue.toString() + "'"; case ZONEDDATETIME_ORDINAL: break; case PERIOD_ORDINAL: break; case DURATION_ORDINAL: break; case JSON_ORDINAL: break; case POINT_ORDINAL: break; case LINESTRING_ORDINAL: break; case POLYGON_ORDINAL: break; case GEOGRAPHY_POINT_ORDINAL: break; case GEOGRAPHY_POLYGON_ORDINAL: break; case boolean_ARRAY_ORDINAL: break; case BOOLEAN_ARRAY_ORDINAL: break; case byte_ARRAY_ORDINAL: break; case BYTE_ARRAY_ORDINAL: break; case short_ARRAY_ORDINAL: break; case SHORT_ARRAY_ORDINAL: break; case int_ARRAY_ORDINAL: break; case INTEGER_ARRAY_ORDINAL: break; case long_ARRAY_ORDINAL: break; case LONG_ARRAY_ORDINAL: break; case float_ARRAY_ORDINAL: break; case FLOAT_ARRAY_ORDINAL: break; case double_ARRAY_ORDINAL: break; case DOUBLE_ARRAY_ORDINAL: break; case STRING_ARRAY_ORDINAL: break; case LOCALDATETIME_ARRAY_ORDINAL: break; case LOCALDATE_ARRAY_ORDINAL: break; case LOCALTIME_ARRAY_ORDINAL: break; case ZONEDDATETIME_ARRAY_ORDINAL: break; case DURATION_ARRAY_ORDINAL: break; case PERIOD_ARRAY_ORDINAL: break; case JSON_ARRAY_ORDINAL: break; } return "'" + value.toString() + "'"; }
Example 9
Source File: AlgorithmServiceImplIT.java From molgenis with GNU Lesser General Public License v3.0 | 4 votes |
static Object[][] testApplyProvider() { String april20DMY = "2017-04-20"; LocalDate april20 = LocalDate.parse(april20DMY); Instant april20defaultTimezone = april20.atStartOfDay(systemDefault()).toInstant(); Instant april20UTC = april20.atStartOfDay(UTC).toInstant(); return new Object[][] { {INT, 25, "$('source').value()", INT, 25, "map INT value"}, {LONG, 529387981723498L, "$('source').value()", LONG, 529387981723498L, "map LONG value"}, {BOOL, false, "$('source').value()", BOOL, false, "map BOOL value false"}, {BOOL, true, "$('source').value()", BOOL, true, "map BOOL value true"}, {DATE, april20, "$('source').value()", DATE, april20, "map DATE to DATE"}, { DATE, april20, "$('source').value()", DATE_TIME, april20defaultTimezone, "DATE should map to DATE_TIME containing start of day in default timezone" }, { STRING, april20DMY, "new Date($('source').value())", DATE_TIME, april20UTC, "ymd STRING to DATE_TIME parsed by JavaScript returns start of day in UTC (BEWARE!)" }, { STRING, april20DMY, "var date = $('source').value().split('-'); new Date(date[0], date[1]-1, date[2])", DATE_TIME, april20defaultTimezone, "ymd STRING to DATE_TIME parsed manually returns start of day in default timezone" }, { STRING, april20DMY, "var date = $('source').value().split('-'); new Date(date[0], date[1]-1, date[2])", DATE, april20, "ymd STRING to DATE parsed manually returns correct day" }, { STRING, april20DMY, "new Date($('source').value())", DATE, april20UTC.atZone(ZoneId.systemDefault()).toLocalDate(), "ymd STRING to DATE parsed by JavaScript returns wrong day, depending on default timezone (BEWARE!)" }, { STRING, april20.toString(), "var date = $('source').value().split('-'); new Date(date[0], date[1]-1, date[2])", DATE_TIME, april20defaultTimezone, "ymd STRING to DATE_TIME parsed manually returns start of day in system default timezone" }, { DATE_TIME, april20defaultTimezone, "$('source').value()", DATE, april20, "DATE_TIME to DATE returns day in default timeZone" }, { DATE_TIME, april20UTC, "$('source').value()", LONG, april20UTC.toEpochMilli(), "DATE_TIME to LONG returns epoch millis" }, { DATE, april20, "$('source').value()", LONG, april20defaultTimezone.toEpochMilli(), "DATE to LONG returns epoch millis at start of day in default timezone" } }; }
Example 10
Source File: LocalDateXmlAdapter.java From nextcloud-java-api with GNU General Public License v3.0 | 4 votes |
@Override public String marshal(LocalDate date) { return date.toString(); }
Example 11
Source File: TCKLocalDate.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 12
Source File: TCKLocalDate.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 13
Source File: DoubtfulCustomerService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
/** * Fonction permettant de récupérer les écritures de facture à transférer sur le compte client * douteux * * @param rule Le règle à appliquer : * <ul> * <li>0 = Créance de + 6 mois * <li>1 = Créance de + 3 mois * </ul> * * @param doubtfulCustomerAccount Le compte client douteux * @param company La société * @return Les écritures de facture à transférer sur le compte client douteux */ public List<Move> getMove(int rule, Account doubtfulCustomerAccount, Company company) { LocalDate date = null; switch (rule) { // Créance de + 6 mois case 0: date = Beans.get(AppBaseService.class) .getTodayDate() .minusMonths(company.getAccountConfig().getSixMonthDebtMonthNumber()); break; // Créance de + 3 mois case 1: date = Beans.get(AppBaseService.class) .getTodayDate() .minusMonths(company.getAccountConfig().getThreeMonthDebtMontsNumber()); break; default: break; } log.debug("Date de créance prise en compte : {} ", date); String request = "SELECT DISTINCT m FROM MoveLine ml, Move m WHERE ml.move = m AND m.company.id = " + company.getId() + " AND ml.account.useForPartnerBalance = 'true' " + "AND m.invoice IS NOT NULL AND ml.amountRemaining > 0.00 AND ml.debit > 0.00 AND ml.dueDate < '" + date.toString() + "' AND ml.account.id != " + doubtfulCustomerAccount.getId() + " AND m.invoice.operationTypeSelect = " + InvoiceRepository.OPERATION_TYPE_CLIENT_SALE; log.debug("Requete : {} ", request); Query query = JPA.em().createQuery(request); @SuppressWarnings("unchecked") List<Move> moveList = query.getResultList(); return moveList; }
Example 14
Source File: TCKLocalDate.java From hottub with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 15
Source File: MoveCreateService.java From axelor-open-suite with GNU Affero General Public License v3.0 | 4 votes |
/** * Creating a new generic accounting move * * @param journal * @param company * @param currency * @param partner * @param date * @param paymentMode * @param technicalOriginSelect * @param ignoreInDebtRecoveryOk * @param ignoreInAccountingOk * @return * @throws AxelorException */ public Move createMove( Journal journal, Company company, Currency currency, Partner partner, LocalDate date, PaymentMode paymentMode, int technicalOriginSelect, boolean ignoreInDebtRecoveryOk, boolean ignoreInAccountingOk, boolean autoYearClosureMove) throws AxelorException { log.debug( "Creating a new generic accounting move (journal : {}, company : {}", new Object[] {journal.getName(), company.getName()}); Move move = new Move(); move.setJournal(journal); move.setCompany(company); move.setIgnoreInDebtRecoveryOk(ignoreInDebtRecoveryOk); move.setIgnoreInAccountingOk(ignoreInAccountingOk); move.setAutoYearClosureMove(autoYearClosureMove); if (autoYearClosureMove) { move.setPeriod(periodService.getPeriod(date, company, YearRepository.TYPE_FISCAL)); if (move.getPeriod() == null) { throw new AxelorException( TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.PERIOD_1), company.getName(), date.toString()); } } else { move.setPeriod(periodService.getActivePeriod(date, company, YearRepository.TYPE_FISCAL)); } move.setDate(date); move.setMoveLineList(new ArrayList<MoveLine>()); Currency companyCurrency = companyConfigService.getCompanyCurrency(company); if (companyCurrency != null) { move.setCompanyCurrency(companyCurrency); move.setCompanyCurrencyCode(companyCurrency.getCode()); } if (currency == null) { currency = move.getCompanyCurrency(); } if (currency != null) { move.setCurrency(currency); move.setCurrencyCode(currency.getCode()); } move.setPartner(partner); move.setPaymentMode(paymentMode); move.setTechnicalOriginSelect(technicalOriginSelect); moveRepository.save(move); move.setReference(Beans.get(SequenceService.class).getDraftSequenceNumber(move)); return move; }
Example 16
Source File: DatePickerTableCell.java From tornadofx-controls with Apache License 2.0 | 4 votes |
public String toString(LocalDate date) { return date != null ? date.toString() : ""; }
Example 17
Source File: TCKLocalDate.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 18
Source File: TCKLocalDate.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Test(dataProvider="sampleToString") public void test_toString(int y, int m, int d, String expected) { LocalDate t = LocalDate.of(y, m, d); String str = t.toString(); assertEquals(str, expected); }
Example 19
Source File: DateColumnLocalDateMapper.java From jadira with Apache License 2.0 | 4 votes |
@Override public String toNonNullString(LocalDate value) { return value.toString(); }
Example 20
Source File: DatePicker.java From LGoodDatePicker with MIT License | 2 votes |
/** * getDateStringOrEmptyString, This returns the last valid date in an ISO-8601 formatted string * "uuuu-MM-dd". For any CE years that are between 0 and 9999 inclusive, the output will have a * fixed length of 10 characters. Years before or after that range will output longer strings. * If the last valid date is empty, this will return an empty string (""). */ public String getDateStringOrEmptyString() { LocalDate date = getDate(); return (date == null) ? "" : date.toString(); }