{"record":{"id":"680a9aedbcea2ca2","repo":"apache/shardingsphere","slug":"invalid-s-datetime-pattern-should-be-s-value-680a9a","errorCode":null,"errorMessage":"Invalid %s, datetime pattern should be '%s', value is '%s'.","messagePattern":"Invalid (.+?), datetime pattern should be '(.+?)', value is '(.+?)'\\.","errorType":"exception","errorClass":"InvalidDatetimeFormatException","httpStatus":null,"severity":"error","filePath":"features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java","lineNumber":108,"sourceCode":"    private String getDateTimePattern(final Properties props) {\n        ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_PATTERN_KEY, () -> new AlgorithmInitializationException(this, String.format(\"%s can not be null\", DATE_TIME_PATTERN_KEY)));\n        return props.getProperty(DATE_TIME_PATTERN_KEY);\n    }\n    \n    private TemporalAccessor getDateTimeLower(final Properties props, final String dateTimePattern) {\n        ShardingSpherePreconditions.checkContainsKey(props, DATE_TIME_LOWER_KEY, () -> new AlgorithmInitializationException(this, String.format(\"%s can not be null.\", DATE_TIME_LOWER_KEY)));\n        return getDateTime(DATE_TIME_LOWER_KEY, props.getProperty(DATE_TIME_LOWER_KEY), dateTimePattern);\n    }\n    \n    private TemporalAccessor getDateTimeUpper(final Properties props, final String dateTimePattern) {\n        return props.containsKey(DATE_TIME_UPPER_KEY) ? getDateTime(DATE_TIME_UPPER_KEY, props.getProperty(DATE_TIME_UPPER_KEY), dateTimePattern) : LocalDateTime.now();\n    }\n    \n    private TemporalAccessor getDateTime(final String dateTimeKey, final String dateTimeValue, final String dateTimePattern) {\n        try {\n            return dateTimeFormatter.parse(dateTimeValue);\n        } catch (final DateTimeParseException ignored) {\n            throw new InvalidDatetimeFormatException(dateTimeKey, dateTimeValue, dateTimePattern);\n        }\n    }\n    \n    private DateTimeFormatter getTableSuffixPattern(final Properties props) {\n        String suffix = props.getProperty(SHARDING_SUFFIX_FORMAT_KEY);\n        ShardingSpherePreconditions.checkNotEmpty(suffix, () -> new AlgorithmInitializationException(this, String.format(\"%s can not be null or empty.\", SHARDING_SUFFIX_FORMAT_KEY)));\n        return DateTimeFormatter.ofPattern(suffix);\n    }\n    \n    private ChronoUnit getStepUnit(final String stepUnit) {\n        for (ChronoUnit each : ChronoUnit.values()) {\n            if (each.toString().equalsIgnoreCase(stepUnit)) {\n                return each;\n            }\n        }\n        throw new UnsupportedSQLOperationException(String.format(\"Cannot find step unit for specified %s property: `%s`\", INTERVAL_UNIT_KEY, stepUnit));\n    }\n    ","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/shardingsphere/blob/e952770a215630a3659c75d64369168cd3e26b82/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/IntervalShardingAlgorithm.java#L90-L126","documentation":"Thrown by IntervalShardingAlgorithm.getDateTime when the datetime-lower (or datetime-upper) value fails to parse with the configured datetime-pattern (default yyyy-MM-dd HH:mm:ss). Interval-based table sharding derives table suffixes from these dates, so a malformed anchor aborts algorithm init.","triggerScenarios":"Configuring an INTERVAL algorithm where datetime-lower/datetime-upper do not match the datetime-pattern prop; e.g. pattern 'yyyy-MM-dd' but value '2020/01/01', or pattern omitted (default) while value is date-only.","commonSituations":"Custom datetime-pattern that does not exactly match the anchor values; date-only values with the default pattern; switching between AUTO_INTERVAL examples and INTERVAL props; locale-dependent separators.","solutions":["Make datetime-lower and datetime-upper strings conform exactly to datetime-pattern (including separators and time part)","If you want date-only values, set datetime-pattern: 'yyyy-MM-dd' explicitly","Quote the values in YAML to preserve leading zeros or special separators","Validate the pattern letters against java.time DateTimeFormatter syntax"],"exampleFix":"# before\n- !SHARDING_ALGORITHM\n  type: INTERVAL\n  props:\n    datetime-lower: 2020/01/01\n    datetime-pattern: yyyy/MM/dd HH:mm:ss\n# after\n- !SHARDING_ALGORITHM\n  type: INTERVAL\n  props:\n    datetime-lower: '2020/01/01 00:00:00'\n    datetime-pattern: yyyy/MM/dd HH:mm:ss","handlingStrategy":"validation","validationCode":"DateTimeFormatter f = DateTimeFormatter.ofPattern(props.getProperty(\"datetime-pattern\", \"yyyy-MM-dd HH:mm:ss\"));\ntry { f.parse(props.getProperty(\"datetime-lower\")); } catch (DateTimeParseException ex) { throw new IllegalArgumentException(\"datetime-lower does not match datetime-pattern\"); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep datetime-pattern adjacent to every datetime value in reviewed config files","Unit-test rule YAML by constructing the algorithm in a config test"],"tags":["sharding","interval","datetime","config"],"backgroundTag":null,"analyzedSha":"e952770a215630a3659c75d64369168cd3e26b82","analyzedAt":"2026-08-14T13:54:53.392Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}