Scrooge-McDucks commented on code in PR #10956: URL: https://github.com/apache/nifi/pull/10956#discussion_r2885964022
########## nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/evaluation/util/DateAmountParser.java: ########## @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.nifi.attribute.expression.language.evaluation.util; + +import org.apache.nifi.attribute.expression.language.exception.AttributeExpressionLanguageException; + +import java.time.Duration; +import java.time.Period; +import java.time.ZonedDateTime; +import java.util.Locale; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Parses a human-readable duration expression (e.g. {@code "2 weeks"}, {@code "1 month"}) + * and applies calendar-aware arithmetic to a {@link ZonedDateTime}. + * + * <p>Format: {@code <positive-integer> <unit>} — a space between number and unit is required. + * Units are case-insensitive and accept singular/plural: second(s), minute(s), hour(s), + * day(s), week(s), month(s), year(s).</p> + */ +public final class DateAmountParser { Review Comment: Good call about the nanos — that’s a great point. I can include nanoseconds as a supported unit so it aligns more closely with the Duration logic for fixed-length units. I did now have a look at delegating to DurationFormat, but it converts everything to a fixed nanosecond count. Months and years require java.time.Period for calendar-aware arithmetic (e.g., adding 1 month to Jan 31 → Feb 28), which means we’d still need a separate path for those cases. Happy to adjust if there’s a preferred direction here, but my thinking was that this keeps the behavior simpler. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
