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

Datetime field: impossible to select time format 17:10:02 #758

Closed
Toutouwai opened this issue Nov 30, 2018 · 4 comments
Closed

Datetime field: impossible to select time format 17:10:02 #758

Toutouwai opened this issue Nov 30, 2018 · 4 comments

Comments

@Toutouwai
Copy link

Short description of the issue

One of the time output formats for Datetime fields is "17:10:02". But it's impossible to select this format in the dropdown as it is changed to the "17:10" format after the field is saved.

time

Setup/Environment

  • ProcessWire version: 3.0.119
  • (Optional) PHP version: 7.1
@Toutouwai
Copy link
Author

This issue doesn't have a lot of effect on the actual time output format because the "Time Output Format" field value is not actually saved as part of the field config and it's the "Date/Time Output Format Code" field that has an effect, and this field is updated correctly from the selection in Time Output Format.

But the Date/Time Output Format Code field is shown collapsed so there can be confusion because the visible Time Output Format can show a value that is not actually in effect.

The problem part is here, where strpos() !== false does not sufficiently discriminate between the "17:10" (H:i) and "17:10:02" (H:i:s) options.

@Toutouwai
Copy link
Author

Possible fix - not sure if there's something more optimal:

$matches = array();
foreach($wdt->getTimeFormats() as $format) {
    $timeFormatted = $wdt->formatDate($date, $format);  
    $f->addOption($format, $timeFormatted);
    if(strpos($field->get('dateOutputFormat'), $format) !== false) $matches[] = $format;
}
if(!empty($matches)) {
    usort($matches, function($a, $b) {
        return strlen($b) - strlen($a);
    });
    $f->value = reset($matches);
}

ryancramerdesign added a commit to processwire/processwire that referenced this issue Nov 30, 2018
@ryancramerdesign
Copy link
Member

Thanks, that's a good find. I've pushed an update to correct it.

@Toutouwai
Copy link
Author

I like what you did there - I haven't seen that before.
Thanks for the fix.

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

No branches or pull requests

2 participants