Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH add support for expanded values on Time/DateField #11193

Draft
wants to merge 3 commits into
base: 5
Choose a base branch
from

Conversation

lekoala
Copy link
Contributor

@lekoala lekoala commented Apr 8, 2024

Description

Currently, partial values in date/time field will results in null values. This is a bit annoying for time value (input 18:--:-- will be null) but is even more obvious on datetime field (inputing the date without the time results in null)

Manual testing steps

Only input partial values, it still submit properly

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@lekoala lekoala marked this pull request as draft April 8, 2024 15:17
@lekoala
Copy link
Contributor Author

lekoala commented Apr 8, 2024

Still work in progress

the basic idea would be to add some kind of common helper

    private function expandValue(?string $value, IntlDateFormatter $formatter): int|false
    {
        $zeroFormat = $formatter->format(strtotime(date('Y-01-01 00:00:00')));
        $expectedLength = strlen($zeroFormat);
        if (strlen($value) >= $expectedLength) {
            return false;
        }
        $expandedValue = $value . substr($zeroFormat, strlen($value));
        return $formatter->parse($expandedValue);
    }

i realize that there are many cases where you can setValue, setSubmittedValue, convert from frontend to internal, tidy internals, ... it's not always super consistent and basically i'd like partial values to work everywhere without too much issues

@GuySartorelli
Copy link
Member

@lekoala Are you still keen to work on this? It seems like it'd be a really useful feature.

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.

None yet

2 participants