Java Code Examples for org.joda.time.format.DateTimeFormatter#parseLocalDate()
The following examples show how to use
org.joda.time.format.DateTimeFormatter#parseLocalDate() .
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: CustomConfigRuntimeTest.java From activiti6-boot2 with Apache License 2.0 | 6 votes |
@Test @DmnDeploymentAnnotation(resources = "org/activiti/dmn/engine/test/deployment/post_custom_expression_function_expression_1.dmn") public void executeDecision_custom_expression_function_missing_default_function() { DmnEngine dmnEngine = activitiRule2.getDmnEngine(); DmnRuleService ruleService = dmnEngine.getDmnRuleService(); Map<String, Object> processVariablesInput = new HashMap<String, Object>(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); processVariablesInput.put("input1", localDate.toDate()); RuleEngineExecutionResult result = ruleService.executeDecisionByKey("decision", processVariablesInput); Assert.assertEquals(0, result.getResultVariables().size()); Assert.assertNotEquals(true, StringUtils.isEmpty(result.getAuditTrail().getRuleExecutions().get(1).getConditionResults().get(0).getException())); }
Example 2
Source File: CustomConfigRuntimeTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @DmnDeployment(resources = "org/flowable/dmn/engine/test/deployment/post_custom_expression_function_expression_1.dmn") public void postCustomExpressionFunction() { DmnEngine dmnEngine = flowableRule1.getDmnEngine(); DmnDecisionService ruleService = dmnEngine.getDmnDecisionService(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); Map<String, Object> result = ruleService.createExecuteDecisionBuilder() .decisionKey("decision") .variable("input1", localDate.toDate()) .executeWithSingleResult(); assertThat(result.get("output1")).isEqualTo("test2"); }
Example 3
Source File: CustomConfigRuntimeTest.java From flowable-engine with Apache License 2.0 | 6 votes |
@Test @DmnDeployment(resources = "org/flowable/dmn/engine/test/deployment/post_custom_expression_function_expression_1.dmn") public void customExpressionFunctionMissingDefaultFunction() { DmnEngine dmnEngine = flowableRule2.getDmnEngine(); DmnDecisionService ruleService = dmnEngine.getDmnDecisionService(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); DecisionExecutionAuditContainer result = ruleService.createExecuteDecisionBuilder() .decisionKey("decision") .variable("input1", localDate.toDate()) .executeWithAuditTrail(); assertThat(result.getDecisionResult()).isEmpty(); assertThat(result.isFailed()).isTrue(); }
Example 4
Source File: DateUtil.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
public static Date toDate(String dateString) { if (StringUtils.isEmpty(dateString)) { throw new IllegalArgumentException("date string cannot be empty"); } DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate dateTime = dtf.parseLocalDate(dateString); return dateTime.toDate(); }
Example 5
Source File: RuntimeTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test @DmnDeploymentAnnotation(resources = "org/activiti/dmn/engine/test/deployment/dates_2.dmn") public void executeDecision_dynamic_dates_add() { Map<String, Object> processVariablesInput = new HashMap<String, Object>(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); processVariablesInput.put("input1", localDate.toDate()); RuleEngineExecutionResult result = ruleService.executeDecisionByKey("decision", processVariablesInput); Assert.assertNotNull(result); Assert.assertSame(result.getResultVariables().get("output1").getClass(), String.class); Assert.assertEquals(result.getResultVariables().get("output1"), "test2"); }
Example 6
Source File: RuntimeTest.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
@Test @DmnDeploymentAnnotation(resources = "org/activiti/dmn/engine/test/deployment/dates_3.dmn") public void executeDecision_dynamic_dates_subtract() { Map<String, Object> processVariablesInput = new HashMap<String, Object>(); DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); processVariablesInput.put("input1", localDate.toDate()); RuleEngineExecutionResult result = ruleService.executeDecisionByKey("decision", processVariablesInput); Assert.assertNotNull(result); Assert.assertSame(result.getResultVariables().get("output1").getClass(), String.class); Assert.assertEquals(result.getResultVariables().get("output1"), "test2"); }
Example 7
Source File: RuntimeTest.java From flowable-engine with Apache License 2.0 | 5 votes |
@Test @DmnDeployment(resources = "org/flowable/dmn/engine/test/deployment/reservered_word.dmn") public void reservedWord() { DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate localDate = dateTimeFormatter.parseLocalDate("2015-09-18"); Map<String, Object> result = ruleService.createExecuteDecisionBuilder() .decisionKey("decision") .variable("date", localDate.toDate()) .executeWithSingleResult(); assertThat(result.get("output1")).isEqualTo("test2"); }
Example 8
Source File: DateUtil.java From flowable-engine with Apache License 2.0 | 5 votes |
public static Date toDate(Object dateString) { if (dateString == null) { throw new IllegalArgumentException("date string cannot be empty"); } DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate dateTime = dtf.parseLocalDate((String) dateString); return dateTime.toDate(); }
Example 9
Source File: JodaLocalDateCodec.java From actframework with Apache License 2.0 | 4 votes |
@Override protected LocalDate parse(DateTimeFormatter formatter, String value) { return formatter.parseLocalDate(value); }
Example 10
Source File: ParserUtils.java From substitution-schedule-parser with Mozilla Public License 2.0 | 4 votes |
static LocalDate parseDate(String string) { if (string == null) return null; reinitIfNeeded(); string = string .replace("Stand:", "") .replace("Import:", "") .replaceAll(", Woche [A-Z]", "") .replaceAll(", .*unterricht Gruppe .*", "") .replaceAll(", Unterrichts.* Gruppe .*", "") .trim(); int i = 0; for (DateTimeFormatter f : dateFormatters) { try { LocalDate d = f.parseLocalDate(string); if (dateFormats[i].contains("yyyy")) { return d; } else { Duration currentYearDifference = abs(new Duration(DateTime.now(), d.toDateTimeAtCurrentTime())); Duration lastYearDifference = abs(new Duration(DateTime.now(), d.minusYears(1).toDateTimeAtCurrentTime())); Duration nextYearDifference = abs(new Duration(DateTime.now(), d.plusYears(1).toDateTimeAtCurrentTime())); if (lastYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() - 1) .parseLocalDate(string); } else if (nextYearDifference.isShorterThan(currentYearDifference)) { return DateTimeFormat.forPattern(dateFormats[i]) .withLocale(Locale.GERMAN).withDefaultYear(f.getDefaultYear() + 1) .parseLocalDate(string); } else { return d; } } } catch (IllegalArgumentException e) { // Does not match this format, try the next one } i++; } // Does not match any known format :( return null; }
Example 11
Source File: CollectionsContainsTest.java From flowable-engine with Apache License 2.0 | 4 votes |
@Test @DmnDeployment(resources = "org/flowable/dmn/engine/test/runtime/contains_IN_types.dmn") public void testContainsTypeCheck() { Map<String, Object> processVariablesInput = new HashMap<>(); DateTimeFormatter dtf = DateTimeFormat.forPattern("yyyy-MM-dd"); LocalDate date1 = dtf.parseLocalDate("2017-12-25"); LocalDate date2 = dtf.parseLocalDate("2018-12-25"); List<String> collectionString = Arrays.asList("test1", "test2", "test3"); List<Boolean> collectionBoolean = Arrays.asList(Boolean.TRUE, Boolean.FALSE); List<Date> collectionDate = Arrays.asList(date1.toDate(), date2.toDate()); List<LocalDate> collectionLocalDate = Arrays.asList(date1, date2); List<Integer> collectionInteger = Arrays.asList(5, 10, 20, 50); List<Long> collectionLong = Arrays.asList(5L, 10L, 20L, 50L); List<Float> collectionFloat = Arrays.asList(5F, 10F, 20F, 50F); List<Double> collectionDouble = Arrays.asList(5D, 10D, 20D, 50D); processVariablesInput.put("collectionString", collectionString); processVariablesInput.put("collectionBoolean", collectionBoolean); processVariablesInput.put("collectionDate", collectionDate); processVariablesInput.put("collectionLocalDate", collectionLocalDate); processVariablesInput.put("collectionInteger", collectionInteger); processVariablesInput.put("collectionLong", collectionLong); processVariablesInput.put("collectionFloat", collectionFloat); processVariablesInput.put("collectionDouble", collectionDouble); DmnEngine dmnEngine = flowableDmnRule.getDmnEngine(); DmnDecisionService dmnRuleService = dmnEngine.getDmnDecisionService(); DecisionExecutionAuditContainer result = dmnRuleService.createExecuteDecisionBuilder() .decisionKey("decision") .variables(processVariablesInput) .executeWithAuditTrail(); assertThat(result.isFailed()).isFalse(); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(0).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(1).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(2).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(3).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(4).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(5).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(6).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(1).getConditionResults().get(7).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(0).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(1).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(2).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(3).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(4).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(5).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(6).getResult()).isEqualTo(true); assertThat(result.getRuleExecutions().get(2).getConditionResults().get(7).getResult()).isEqualTo(true); }
Example 12
Source File: LocalDateConverter.java From gson-jodatime-serialisers with MIT License | 3 votes |
/** * Gson invokes this call-back method during deserialization when it encounters a field of the * specified type. <p> * * In the implementation of this call-back method, you should consider invoking * {@link com.google.gson.JsonDeserializationContext#deserialize(com.google.gson.JsonElement, java.lang.reflect.Type)} method to create objects * for any non-trivial field of the returned object. However, you should never invoke it on the * the same type passing {@code json} since that will cause an infinite loop (Gson will call your * call-back method again). * @param json The Json data being deserialized * @param typeOfT The type of the Object to deserialize to * @return a deserialized object of the specified type typeOfT which is a subclass of {@code T} * @throws com.google.gson.JsonParseException if json is not in the expected format of {@code typeOfT} */ @Override public LocalDate deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { // Do not try to deserialize null or empty values if (json.getAsString() == null || json.getAsString().isEmpty()) { return null; } final DateTimeFormatter fmt = DateTimeFormat.forPattern(PATTERN); return fmt.parseLocalDate(json.getAsString()); }
Example 13
Source File: YearMonth.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code YearMonth} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static YearMonth parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new YearMonth(date.getYear(), date.getMonthOfYear()); }
Example 14
Source File: MonthDay.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }
Example 15
Source File: LocalDate.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code LocalDate} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static LocalDate parse(String str, DateTimeFormatter formatter) { return formatter.parseLocalDate(str); }
Example 16
Source File: MonthDay.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }
Example 17
Source File: LocalDate.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code LocalDate} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static LocalDate parse(String str, DateTimeFormatter formatter) { return formatter.parseLocalDate(str); }
Example 18
Source File: YearMonth.java From astor with GNU General Public License v2.0 | 2 votes |
/** * Parses a {@code YearMonth} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static YearMonth parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new YearMonth(date.getYear(), date.getMonthOfYear()); }
Example 19
Source File: Arja_0049_s.java From coming with MIT License | 2 votes |
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }
Example 20
Source File: Arja_0049_t.java From coming with MIT License | 2 votes |
/** * Parses a {@code MonthDay} from the specified string using a formatter. * * @param str the string to parse, not null * @param formatter the formatter to use, not null * @since 2.0 */ public static MonthDay parse(String str, DateTimeFormatter formatter) { LocalDate date = formatter.parseLocalDate(str); return new MonthDay(date.getMonthOfYear(), date.getDayOfMonth()); }