Skip to content

fix(message-parser): parse timestamps inside formatted text#39455

Open
Harshith1702 wants to merge 4 commits intoRocketChat:developfrom
Harshith1702:fix-timestamp-parser
Open

fix(message-parser): parse timestamps inside formatted text#39455
Harshith1702 wants to merge 4 commits intoRocketChat:developfrom
Harshith1702:fix-timestamp-parser

Conversation

@Harshith1702
Copy link
Copy Markdown

@Harshith1702 Harshith1702 commented Mar 8, 2026

Fixes an issue where <t:...> timestamps were not parsed when used
inside formatted text such as bold or strike.

This updates the parser grammar so TimestampRules are included in
the bold and italic preferential parsing patterns.

Additionally, a test case was added to verify timestamps inside
formatted text.

Summary by CodeRabbit

  • Bug Fixes

    • Timestamps inside bold and italic text are now recognized as inline content rather than being skipped or rejected.
  • Tests

    • Updated tests to reflect structured timestamp nodes and to validate timestamp parsing within formatted content.
  • Chores

    • Prepared a patch release entry for the message parser to document the timestamp parsing fix.

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 8, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 8, 2026

CLA assistant check
All committers have signed the CLA.

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 8, 2026

🦋 Changeset detected

Latest commit: 9bf92ef

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/message-parser Patch
@rocket.chat/meteor Patch
@rocket.chat/core-services Patch
@rocket.chat/core-typings Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/rest-typings Patch
@rocket.chat/pdf-worker Patch
rocketchat-services Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/abac Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/models Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch
@rocket.chat/server-fetch Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 8, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fcc2ee0a-2a84-4b32-bb9f-01bb71899b6c

📥 Commits

Reviewing files that changed from the base of the PR and between 5c52609 and 9bf92ef.

📒 Files selected for processing (1)
  • .changeset/fix-timestamp-parser.md
✅ Files skipped from review due to trivial changes (1)
  • .changeset/fix-timestamp-parser.md

Walkthrough

Grammar updates allow <t:...> timestamp tokens to be parsed inside italic and bold content by adding TimestampRules to the preferential item patterns; tests and a changeset were updated to reflect TIMESTAMP nodes in formatted text.

Changes

Cohort / File(s) Summary
Grammar Parser
packages/message-parser/src/grammar.pegjs
Added TimestampRules at the start of alternatives in ItalicContentPreferentialItemPattern and BoldContentPreferentialItemPattern so <t:...> tokens are recognized inside italic and bold content.
Tests
packages/message-parser/tests/timestamp.test.ts
Updated tests to expect structured TIMESTAMP nodes (with value/format and fallback) within italic/bold formatted examples and for combined formatted content.
Release Notes / Changeset
.changeset/fix-timestamp-parser.md
Added a patch-level changeset documenting the fix for timestamp parsing inside bold and italic text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: adding support for parsing timestamps inside formatted text (bold and italic).
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files


Since this is your first cubic review, here's how it works:

  • cubic automatically reviews your code and comments on bugs and improvements
  • Teach cubic by replying to its comments. cubic learns from your replies and gets better over time
  • Add one-off context when rerunning by tagging @cubic-dev-ai with guidance or docs links (including llms.txt)
  • Ask questions if you need clarification on any suggestion

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/message-parser/src/grammar.pegjs (1)

531-570: ⚠️ Potential issue | 🟠 Major

Update bold/italic renderers before emitting TIMESTAMP nodes here.

These rules now produce TIMESTAMP children inside BOLD and ITALIC, but packages/gazzodown/src/elements/BoldSpan.tsx:25-75 and packages/gazzodown/src/elements/ItalicSpan.tsx:25-75 still fall through to default and return null for that block type. As written, **<t:...>** and _ <t:...> _ will parse, but the timestamp will disappear at render time until those spans accept MessageParser.Timestamp like StrikeSpan already does.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/message-parser/src/grammar.pegjs` around lines 531 - 570, Update the
BoldSpan and ItalicSpan renderers to handle MessageParser.Timestamp children the
same way StrikeSpan does: in packages/gazzodown/src/elements/BoldSpan.tsx and
ItalicSpan.tsx detect nodes of type MessageParser.Timestamp (or TIMESTAMP) in
the children iteration/switch and return the appropriate timestamp element
instead of falling through to default/null; mirror the handling logic used in
StrikeSpan for rendering/propagating timestamp nodes and ensure any
props/formatting applied to other inline children are correctly preserved for
Timestamp nodes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/message-parser/tests/timestamp.test.ts`:
- Around line 38-47: Add a test case in
packages/message-parser/tests/timestamp.test.ts that mirrors the existing bold
assertions but uses italic markup (_..._ and/or __...__) to cover the changed
italic parsing in grammar.pegjs; specifically add an input like '_hello
<t:1708551317> world_' (and/or '__hello <t:1708551317> world__') and assert the
parsed output uses paragraph/italic/plain/timestampNode('1708551317') structure
similar to the bold test, ensuring timestampNode is nested inside the italic
node path.
- Line 1: Remove the invalid import "import { timeStamp } from 'node:console';"
from the test file (it's not a named export and is unused), and add a new unit
test in timestamp.test.ts that wraps an existing timestamp fixture with the
italic helper (e.g., use italic(`<t:${timestamp}>`) from the helpers module) to
assert the parser produces the same timestamp tokenization/AST as the non-italic
form; reference the existing timestamp test harness and the italic helper to
mirror the other timestamp assertions so italic-formatted timestamps are
covered.

---

Outside diff comments:
In `@packages/message-parser/src/grammar.pegjs`:
- Around line 531-570: Update the BoldSpan and ItalicSpan renderers to handle
MessageParser.Timestamp children the same way StrikeSpan does: in
packages/gazzodown/src/elements/BoldSpan.tsx and ItalicSpan.tsx detect nodes of
type MessageParser.Timestamp (or TIMESTAMP) in the children iteration/switch and
return the appropriate timestamp element instead of falling through to
default/null; mirror the handling logic used in StrikeSpan for
rendering/propagating timestamp nodes and ensure any props/formatting applied to
other inline children are correctly preserved for Timestamp nodes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 14f8a175-d471-4065-8eaa-c24608e1f1a4

📥 Commits

Reviewing files that changed from the base of the PR and between 4f43a85 and f5289e1.

📒 Files selected for processing (2)
  • packages/message-parser/src/grammar.pegjs
  • packages/message-parser/tests/timestamp.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • packages/message-parser/tests/timestamp.test.ts
🧠 Learnings (13)
📓 Common learnings
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 37419
File: packages/i18n/src/locales/en.i18n.json:918-921
Timestamp: 2025-11-19T18:20:07.720Z
Learning: Repo: RocketChat/Rocket.Chat — i18n/formatting
Learning: This repository uses a custom message formatting parser in UI blocks/messages; do not assume standard Markdown rules. For keys like Call_ended_bold, Call_not_answered_bold, Call_failed_bold, and Call_transferred_bold in packages/i18n/src/locales/en.i18n.json, retain the existing single-asterisk emphasis unless maintainers request otherwise.
📚 Learning: 2026-03-06T18:09:14.766Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/elements/Timestamp/DateTimeFormats.spec.tsx:20-23
Timestamp: 2026-03-06T18:09:14.766Z
Learning: In the RocketChat/Rocket.Chat gazzodown package (`packages/gazzodown`), tests are intended to run under the UTC timezone, but as of PR `#39397` this is NOT yet explicitly enforced in `jest.config.ts` or the `package.json` test scripts (which just run `jest` without `TZ=UTC`). To make timezone-sensitive snapshot tests reliable across all environments, `TZ=UTC` should be added to the test scripts in `package.json` or to `jest.config.ts` via `testEnvironmentOptions.timezone`. Without explicit UTC enforcement, snapshot tests involving date-fns formatted output or `toLocaleString()` will fail for contributors in non-UTC timezones.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `expect` matchers for assertions (`toEqual`, `toContain`, `toBeTruthy`, `toHaveLength`, etc.) instead of `assert` statements in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Utilize Playwright fixtures (`test`, `page`, `expect`) for consistency in test files

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2026-03-06T18:02:11.732Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 39397
File: packages/gazzodown/src/elements/Timestamp/RelativeTime.spec.tsx:63-70
Timestamp: 2026-03-06T18:02:11.732Z
Learning: In RocketChat/Rocket.Chat, tests in the `packages/gazzodown` package (and likely the broader test suite) are always expected to run in the UTC timezone. This makes `toLocaleString()` output deterministic, so snapshot tests that include locale/timezone-sensitive content (such as `title` attributes from `toLocaleString()`) are stable and do not need to be replaced with targeted assertions.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Ensure tests run reliably in parallel without shared state conflicts

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to **/*.spec.ts : Use descriptive test names that clearly communicate expected behavior in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use `test.step()` for complex test scenarios to improve organization in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Prefer web-first assertions (`toBeVisible`, `toHaveText`, etc.) in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.{ts,spec.ts} : Follow Page Object Model pattern consistently in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2025-11-24T17:08:17.065Z
Learnt from: CR
Repo: RocketChat/Rocket.Chat PR: 0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-11-24T17:08:17.065Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Maintain test isolation between test cases in Playwright tests

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • packages/message-parser/tests/timestamp.test.ts

Comment thread packages/message-parser/tests/timestamp.test.ts Outdated
Comment thread packages/message-parser/tests/timestamp.test.ts
@Harshith1702
Copy link
Copy Markdown
Author

Made the changes suggested by the review:

  • removed the unused node:console import
  • added a test for timestamps inside italic formatting

All tests pass locally.

@Harshith1702
Copy link
Copy Markdown
Author

Hi maintainers,

This PR fixes timestamp parsing inside formatted text (bold/italic) and includes tests. All tests pass locally.

Could someone please review it and approve the workflows so CI can complete?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants