From eab8319418b7457cce41b0eb4b16829c3d81e551 Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Wed, 18 Mar 2026 20:12:24 +0700 Subject: [PATCH 1/7] Support timeFormat in datetime field --- src/Parsers/Field.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/Parsers/Field.php b/src/Parsers/Field.php index 41bd567..f61aaa5 100644 --- a/src/Parsers/Field.php +++ b/src/Parsers/Field.php @@ -77,6 +77,7 @@ public function parse() { ->parse_clone() ->parse_array_attributes( 'options' ) ->parse_array_attributes( 'js_options' ) + ->parse_datetime_format() ->parse_array_attributes( 'query_args' ) ->parse_array_attributes( 'attributes' ) ->parse_text_limiter() @@ -287,4 +288,41 @@ private function parse_text_limiter() { unset( $this->text_limiter ); return $this; } + + private function parse_datetime_format() { + if ( empty( $this->datetime_format ) ) { + return $this; + } + // Apply for datetime field only + if ( $this->type !== 'datetime' ) { + return $this; + } + + $js_options = is_array( $this->js_options ) ? $this->js_options : []; + $separator = $js_options['separator'] ?? ' '; + $pos = strpos( $this->datetime_format, $separator ); + + // Split format (simple format rule: "date time") + $date_format = ( false !== $pos ) ? substr( $this->datetime_format, 0, $pos ) : $this->datetime_format; // If no separator, client setup for date format + $time_format = ( false !== $pos ) ? substr( $this->datetime_format, $pos + strlen( $separator ) ) : ''; + + if ( $date_format ) { + $this->format = $date_format; + + if ( empty( $js_options['dateFormat'] ) ) { + $js_options['dateFormat'] = $date_format; + } + } + + if ( $time_format && empty( $this->js_options['timeFormat'] ) ) { + $js_options['timeFormat'] = $time_format; + } + + $this->js_options = $js_options; + + // Clean data + unset( $this->datetime_format ); + + return $this; + } } From ae761e8da66214e6d039685e7577a2b09e2700c2 Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Thu, 19 Mar 2026 06:26:49 +0700 Subject: [PATCH 2/7] Remove clean --- src/Parsers/Field.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/Parsers/Field.php b/src/Parsers/Field.php index f61aaa5..13ee1a4 100644 --- a/src/Parsers/Field.php +++ b/src/Parsers/Field.php @@ -320,9 +320,6 @@ private function parse_datetime_format() { $this->js_options = $js_options; - // Clean data - unset( $this->datetime_format ); - return $this; } } From 880930934a496329b337e513885300047d398aa5 Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Tue, 24 Mar 2026 17:48:12 +0700 Subject: [PATCH 3/7] Change function name and optimize codde --- src/Parsers/Field.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Parsers/Field.php b/src/Parsers/Field.php index 13ee1a4..cd94c1a 100644 --- a/src/Parsers/Field.php +++ b/src/Parsers/Field.php @@ -77,7 +77,6 @@ public function parse() { ->parse_clone() ->parse_array_attributes( 'options' ) ->parse_array_attributes( 'js_options' ) - ->parse_datetime_format() ->parse_array_attributes( 'query_args' ) ->parse_array_attributes( 'attributes' ) ->parse_text_limiter() @@ -289,7 +288,7 @@ private function parse_text_limiter() { return $this; } - private function parse_datetime_format() { + private function parse_field_datetime() { if ( empty( $this->datetime_format ) ) { return $this; } @@ -303,18 +302,14 @@ private function parse_datetime_format() { $pos = strpos( $this->datetime_format, $separator ); // Split format (simple format rule: "date time") - $date_format = ( false !== $pos ) ? substr( $this->datetime_format, 0, $pos ) : $this->datetime_format; // If no separator, client setup for date format - $time_format = ( false !== $pos ) ? substr( $this->datetime_format, $pos + strlen( $separator ) ) : ''; + $date_format = false !== $pos ? substr( $this->datetime_format, 0, $pos ) : $this->datetime_format; // If no separator, client setup for date format + $time_format = false !== $pos ? substr( $this->datetime_format, $pos + strlen( $separator ) ) : ''; - if ( $date_format ) { - $this->format = $date_format; - - if ( empty( $js_options['dateFormat'] ) ) { - $js_options['dateFormat'] = $date_format; - } + if ( $date_format && empty( $js_options['dateFormat'] ) ) { + $js_options['dateFormat'] = $date_format; } - if ( $time_format && empty( $this->js_options['timeFormat'] ) ) { + if ( $time_format && empty( $js_options['timeFormat'] ) ) { $js_options['timeFormat'] = $time_format; } From b89e435c87a31b8987f9ed1c763d940ab4ea2631 Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Sun, 29 Mar 2026 10:14:02 +0700 Subject: [PATCH 4/7] Unparse datetime --- src/Unparsers/Field.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/Unparsers/Field.php b/src/Unparsers/Field.php index 124b68f..3286516 100644 --- a/src/Unparsers/Field.php +++ b/src/Unparsers/Field.php @@ -243,4 +243,35 @@ protected function ensure_boolean( $key ) { } return $this; } + + private function unparse_field_datetime() { + // Apply for datetime field only + if ( $this->type !== 'datetime' ) { + return $this; + } + + if ( empty( $this->js_options ) || ! is_array( $this->js_options ) ) { + return $this; + } + + $date_format = $this->js_options['dateFormat'] ?? ''; + $time_format = $this->js_options['timeFormat'] ?? ''; + + if ( ! $date_format && ! $time_format ) { + return $this; + } + + $separator = $this->js_options['separator'] ?? ' '; + + if ( $date_format && $time_format ) { + $this->datetime_format = $date_format . $separator . $time_format; + } elseif ( $date_format ) { + $this->datetime_format = $date_format; + } else { + // handle timeFormat only + $this->datetime_format = $time_format; + } + + return $this; + } } From cab33a6eadde31eb97dc859396f6cf48be27f8ba Mon Sep 17 00:00:00 2001 From: Anh Tran Date: Mon, 30 Mar 2026 09:30:43 +0700 Subject: [PATCH 5/7] Remove `datetime_format` after parsing, and add `separator` option --- src/Parsers/Field.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Parsers/Field.php b/src/Parsers/Field.php index cd94c1a..fa6352b 100644 --- a/src/Parsers/Field.php +++ b/src/Parsers/Field.php @@ -288,14 +288,10 @@ private function parse_text_limiter() { return $this; } - private function parse_field_datetime() { + private function parse_field_datetime(): self { if ( empty( $this->datetime_format ) ) { return $this; } - // Apply for datetime field only - if ( $this->type !== 'datetime' ) { - return $this; - } $js_options = is_array( $this->js_options ) ? $this->js_options : []; $separator = $js_options['separator'] ?? ' '; @@ -313,8 +309,14 @@ private function parse_field_datetime() { $js_options['timeFormat'] = $time_format; } + if ( empty( $js_options['separator'] ) ) { + $js_options['separator'] = ' '; + } + $this->js_options = $js_options; + unset( $this->datetime_format ); + return $this; } } From 8f71c5a270b240a48aefb0b2ca39a4502c09d00f Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Mon, 30 Mar 2026 15:54:30 +0700 Subject: [PATCH 6/7] Fix code --- src/Unparsers/Field.php | 43 ++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Unparsers/Field.php b/src/Unparsers/Field.php index 3286516..e76fd7f 100644 --- a/src/Unparsers/Field.php +++ b/src/Unparsers/Field.php @@ -244,34 +244,41 @@ protected function ensure_boolean( $key ) { return $this; } - private function unparse_field_datetime() { - // Apply for datetime field only - if ( $this->type !== 'datetime' ) { + private function unparse_field_datetime(): self { + if ( empty( $this->js_options ) ) { return $this; } - if ( empty( $this->js_options ) || ! is_array( $this->js_options ) ) { - return $this; - } - - $date_format = $this->js_options['dateFormat'] ?? ''; - $time_format = $this->js_options['timeFormat'] ?? ''; - - if ( ! $date_format && ! $time_format ) { - return $this; - } - - $separator = $this->js_options['separator'] ?? ' '; + $js_options = is_array( $this->js_options ) ? $this->js_options : []; + $date_format = $this->get_js_option_value( $js_options, 'dateFormat' ); + $time_format = $this->get_js_option_value( $js_options, 'timeFormat' ); + $separator = $this->get_js_option_value( $js_options, 'separator' ) ?? ' '; if ( $date_format && $time_format ) { - $this->datetime_format = $date_format . $separator . $time_format; + $this->datetime_format = "{$date_format}{$separator}{$time_format}"; } elseif ( $date_format ) { $this->datetime_format = $date_format; - } else { - // handle timeFormat only + } elseif ( $time_format ) { $this->datetime_format = $time_format; } + foreach ( $js_options as $key => $option ) { + if ( isset( $option['key'] ) && in_array( $option['key'], [ 'dateFormat', 'timeFormat', 'separator' ] ) ) { + unset( $js_options[ $key ] ); + } + } + $this->js_options = $js_options; + return $this; } + + private function get_js_option_value( array $js_options, string $key ): mixed { + foreach ( $js_options as $option ) { + if ( isset( $option['key'] ) && $option['key'] === $key ) { + return $option['value'] ?? null; + } + } + + return null; + } } From cb99a5ee0866a3d37c064b640f550afdd139ba27 Mon Sep 17 00:00:00 2001 From: Anh Tran Date: Mon, 30 Mar 2026 19:17:18 +0700 Subject: [PATCH 7/7] Remove return mixed type --- AGENTS.md | 4 +-- composer.json | 4 +-- phpcs.xml | 78 ----------------------------------------- src/Unparsers/Field.php | 4 +-- 4 files changed, 6 insertions(+), 84 deletions(-) delete mode 100644 phpcs.xml diff --git a/AGENTS.md b/AGENTS.md index 1b20131..d10c793 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -7,12 +7,12 @@ PHP library for parsing and unparsing Meta Box settings from the builder (provid ### Lint ```bash -composer phpcs +composer phpcs src ``` ### Fix Auto-fixable Issues ```bash -composer phpcbf +composer phpcbf src ``` ### No Tests diff --git a/composer.json b/composer.json index 6d4421a..0f45379 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "riimu/kit-phpencoder": "^2.4" }, "scripts": { - "phpcs": "phpcs --standard=phpcs.xml src", - "phpcbf": "phpcbf --standard=phpcs.xml src" + "phpcs": "phpcs --standard=../meta-box-aio/phpcs.xml", + "phpcbf": "phpcbf --standard=../meta-box-aio/phpcs.xml" } } diff --git a/phpcs.xml b/phpcs.xml deleted file mode 100644 index 712d8b7..0000000 --- a/phpcs.xml +++ /dev/null @@ -1,78 +0,0 @@ - - - - - - - - - - - - - - - - - - - - . - - - /vendor/* - /tests/* - /.github/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Unparsers/Field.php b/src/Unparsers/Field.php index e76fd7f..b46a3c3 100644 --- a/src/Unparsers/Field.php +++ b/src/Unparsers/Field.php @@ -263,7 +263,7 @@ private function unparse_field_datetime(): self { } foreach ( $js_options as $key => $option ) { - if ( isset( $option['key'] ) && in_array( $option['key'], [ 'dateFormat', 'timeFormat', 'separator' ] ) ) { + if ( isset( $option['key'] ) && in_array( $option['key'], [ 'dateFormat', 'timeFormat', 'separator' ], true ) ) { unset( $js_options[ $key ] ); } } @@ -272,7 +272,7 @@ private function unparse_field_datetime(): self { return $this; } - private function get_js_option_value( array $js_options, string $key ): mixed { + private function get_js_option_value( array $js_options, string $key ) { foreach ( $js_options as $option ) { if ( isset( $option['key'] ) && $option['key'] === $key ) { return $option['value'] ?? null;