Skip to content

[LANG-1827] Support escaped single quotes ('') in DurationFormatUtils format patterns#1700

Open
sarankumarbaskar wants to merge 2 commits into
apache:masterfrom
sarankumarbaskar:LANG-1827-duration-format-quote-escaping
Open

[LANG-1827] Support escaped single quotes ('') in DurationFormatUtils format patterns#1700
sarankumarbaskar wants to merge 2 commits into
apache:masterfrom
sarankumarbaskar:LANG-1827-duration-format-quote-escaping

Conversation

@sarankumarbaskar

@sarankumarbaskar sarankumarbaskar commented Jun 11, 2026

Copy link
Copy Markdown

DurationFormatUtils.lexx() does not handle escaped single quotes, making it
impossible to include a literal apostrophe in formatted duration output.

The root cause is in the lexx() parser: when it encounters a single quote
while inside a literal block, it unconditionally ends the literal. It never
checks whether the next character is also a single quote, which should mean
"emit a literal apostrophe and continue the literal."

This behavior contradicts the quoting convention established by
java.text.SimpleDateFormat, where '' consistently produces a literal
single quote. The class Javadoc acknowledged the limitation explicitly:

"Note: It's not currently possible to include a single-quote in a format."

and a TODO in lexx() read:

// TODO: Need to handle escaping of '

This PR modifies lexx() to recognise '' as an escaped single quote — both
inside and outside quoted literal sections — matching SimpleDateFormat
behavior. The Javadoc has been updated to document the '' convention and
the TODO has been removed.

Note: This is a minor behavioral change. Existing format strings that relied
on '' as "close one literal then open another" will now produce a literal
apostrophe instead. This aligns with what most users would expect.

This issue is tracked asLANG-1827.

  • Read the contribution guidelines for this project.
  • Read the ASF Generative Tooling Guidance.
  • Ran a successful build with mvn.
  • Unit tests cover all new behavior and verify no regressions.
  • Commit message follows the [LANG-XXXX] convention.

@garydgregory

Copy link
Copy Markdown
Member

@ppkarwasz @chtompki
Do you foresee any issues with this solution aside from the obvious change in behavior?

@garydgregory garydgregory left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Sarankumar18
Please see my comment.
Thank you!

}

@Test
void testLANG1827() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @Sarankumar18
Please write this new test as a @ParameterizedTest so that we can run all input/output individually and see them all fail if the main side of the patch is not applied.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@garydgregory I've made as parametrize test for testLANG1827

Run each DurationFormatUtils escaped quote case independently.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants