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

Time field option 'display format' does not render if 'Date only' is selected #180

Open
goose2000 opened this issue Nov 16, 2022 · 2 comments

Comments

@goose2000
Copy link

I found that making a custom 'display format' only would affect the displayed date if 'Date only' was NOT selected.

My user expectation was that if the format is set, would override either Date or Date only.

` public function render_display_mode(stdClass $entry, array $params) {
$field = $this->_field;
$fieldid = $field->id();

    $strtime = '';
    if (isset($entry->{"c{$fieldid}_content"})) {
        if ($content = $entry->{"c{$fieldid}_content"}) {
            if (!empty($params['format'])) {
                $strtime = userdate($content, $params['format']);
            } else if (isset($params['date']) || $field->dateonly) {
                $strtime = userdate($content, get_string("strftimedate"));
            } else if (isset($params['timestamp'])) {
                $strtime = $content;
            } else if (!empty($field->displayformat)) {
                $strtime = userdate($content, $field->displayformat);
            } else {
                $date = getdate($content);
                if ($date['seconds'] || $date['minutes'] || $date['hours']) {
                    $strtime = userdate($content, get_string("strftimedatetime"));
                } else {
                    $strtime = userdate($content, get_string("strftimedate"));
                }
            }
        }
    }
    return $strtime;
}`
@goose2000
Copy link
Author

goose2000 commented Nov 18, 2022

I moved the $field->displayformat condition to the top of the else if conditions, this respects the custom date format display and still lets you choose to input date only or with time fields too.

file:
\mod\datalynx\field\time\renderer.php

`
public function render_display_mode(stdClass $entry, array $params) {
$field = $this->_field;
$fieldid = $field->id();

    $strtime = '';
    if (isset($entry->{"c{$fieldid}_content"})) {
        if ($content = $entry->{"c{$fieldid}_content"}) {
            if (!empty($params['format'])) {
                $strtime = userdate($content, $params['format']);
	} else if (!empty($field->displayformat)) {  // this goes to the top
                $strtime = userdate($content, $field->displayformat);
            } else if (isset($params['date']) || $field->dateonly) {
                $strtime = userdate($content, get_string("strftimedate"));
            } else if (isset($params['timestamp'])) {
                $strtime = $content;
            } else {
                $date = getdate($content);
                if ($date['seconds'] || $date['minutes'] || $date['hours']) {
                    $strtime = userdate($content, get_string("strftimedatetime"));
                } else {
                    $strtime = userdate($content, get_string("strftimedate"));
                }
            }
        }
    }
    return $strtime;
}`

@dasistwas
Copy link
Member

Hi @goose2000 , in order to integrate your patch it would be great if you could do the following:

  1. Fork the repo to your account (right top on github)
  2. Make the changes on your repo (you can use the online editor in github directly)
  3. Make a pull request https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request#creating-the-pull-request

then I can merge your changes.

Kind regards,
David

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

No branches or pull requests

2 participants