Skip to content

Support timeFormat in datetime field#19

Merged
rilwis merged 8 commits into
masterfrom
fea/time-format
Mar 30, 2026
Merged

Support timeFormat in datetime field#19
rilwis merged 8 commits into
masterfrom
fea/time-format

Conversation

@nhatrangnet

@nhatrangnet nhatrangnet commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

@nhatrangnet
nhatrangnet requested a review from rilwis March 18, 2026 13:12
Comment thread src/Parsers/Field.php Outdated
Comment thread src/Parsers/Field.php Outdated
Comment thread src/Parsers/Field.php Outdated

@rilwis rilwis 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.

Còn thiếu phần unparse nữa. E test cả với import export, save to json nhé.

Comment thread src/Parsers/Field.php
Comment thread src/Unparsers/Field.php Outdated
@wpmetabox wpmetabox deleted a comment from opencode-agent Bot Mar 30, 2026
@opencode-agent

Copy link
Copy Markdown

Based on my analysis of the pull request, here's my review:

Code Review Summary

✅ Good Implementation

  • Parser (src/Parsers/Field.php:291-321): Correctly splits datetime_format into dateFormat, timeFormat, and separator in js_options
  • Unparser (src/Unparsers/Field.php:277-303): Properly reverses the parsing, reconstructing datetime_format from js_options
  • Both methods follow existing code patterns and naming conventions
  • Block editor field support added consistently

⚠️ Issues Found

1. Bug: Empty js_options handling in unparser (src/Unparsers/Field.php:278-280)

if ( empty( $this->js_options ) ) {
    return $this;
}

If js_options is an empty array [], this passes through but later code at line 295 will fail because it's expecting an array of objects format. Should check ! is_array($this->js_options) or use null !== $this->js_options.

2. Missing type hint on get_js_option_value (src/Unparsers/Field.php:305)

private function get_js_option_value( array $js_options, string $key ) {

Should add return type: : ?string for PHP 7.4 compatibility.

3. Redundant separator setting (src/Parsers/Field.php:312-314)

if ( empty( $js_options['separator'] ) ) {
    $js_options['separator'] = ' ';
}

The $separator variable is already set to ' ' as default on line 297, so this always sets it. Either remove this check or move it before line 297.

4. Inconsistent variable naming (src/Parsers/Field.php:297):

$separator  = $js_options['separator'] ?? ' ';

vs

$separator   = $this->get_js_option_value( $js_options, 'separator' ) ?? ' ';

The parser uses direct key access while unparser uses helper function. This inconsistency could cause issues if the format changes.

5. PHPDoc missing for new methods
Add @return self for parse_field_datetime(), parse_field_block_editor(), unparse_field_datetime(), and unparse_field_block_editor().


📝 Minor Suggestions

  • Consider extracting the datetime format parsing logic into a reusable trait if similar patterns exist elsewhere
  • The uniqid() in unparse_field_block_editor:262 as fallback is fine but could produce unpredictable names

🔒 Security

No security issues found. The code doesn't handle user input directly and uses proper escaping/context.

New%20session%20-%202026-03-30T12%3A23%3A18.361Z
opencode session  |  github run

@rilwis
rilwis merged commit e8d9628 into master Mar 30, 2026
1 check passed
@rilwis
rilwis deleted the fea/time-format branch March 30, 2026 12:27
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