Ticket #202 (closed defect: wontfix)

Opened 8 years ago

Last modified 7 years ago

return date in another format

Reported by: morten.dk Owned by: argh
Priority: normal Milestone: v0.9.0 stable
Component: patForms Version: SVN-HEAD
Severity: normal Keywords:
Cc:

Description

is it possible to return the date format in another way than timestamp or isodate ?

something like 'returnformat' => date('d m Y H:i:s',timestamp)

Change History

comment:1 Changed 8 years ago by argh

  • Status changed from new to assigned

comment:2 Changed 8 years ago by gerd

IMHO the 'returnformat' attribute should rather accept a format string like 'strftime()'

Please also consider that allowing different return-formats may cause additional confusion. Hence I would always use the isodate-style.

comment:3 Changed 8 years ago by schst

Couldn't this problem be solved easily, by creating a new filter, which is able to format the datestamp corrently?

class patForms_Filter_Dateformat extends patForms_Filter {
    var $_type = PATFORMS_FILTER_TYPE_PHP;
    var $_format;
    function setFormat($format) {
        $this->_format = $format;
    }
    function in($value) {
        return $value;
    }
    function out($value) {
        return date($this->_format, $value);
    }
}

Note that I haven't tested this, but it basically should work this way.

comment:4 Changed 8 years ago by sfuchs

When this gets touched please also reconsider a topic that has been raised on the mailinglist. Please correct me if I'm wrong.

Element_Date::getValue() will return the date as isodate regardless what has been set as $attributesdateformat?. Thus, $form->getValues() also will always contain the isodate.

So, when we enable people to set a specific output format - why shouldn't we use it in getValue()/getValues() also?

comment:5 Changed 8 years ago by schst

Because it's the output format and any designer might change it in the form template. Your application might break, if it receives "12.Mai 2005" instead of "2005-05-12".

comment:6 Changed 8 years ago by schst

  • Milestone changed from none to v1.0.0

comment:7 Changed 7 years ago by schst

  • Milestone changed from v1.0.0 to v0.9.0 stable

We just decided, that the Date element will provide this feature out of the box without applying filters.

comment:8 Changed 7 years ago by argh

  • Status changed from assigned to closed
  • Resolution set to wontfix

Actually, the matter is really quite simple: the 'dateformat' attribute determines how the date will be shown to the user, and what the user will be able to enter. So using "H:i" as dateformat will only allow the user to enter a time.

The returnformat is how the element will provide you with the information, and IMO the only formats for that are an ISO date string or a timestamp (the two available options).

Now you may need to access the value of the element in the format specified by 'dateformat', to display it somewhere in else in your application or whatever. For this, simply use the available getFormattedDate() method of the target Date element.

Should you need the date in any other format, either use filters as Stephan suggested, or get the value normally via getValue() and use the date and time functions to transform it. It doesn't really make sense to have the date element return fancy strings via getValue() as it would break the logic.

Note: See TracTickets for help on using tickets.