jonathangeiger / kohana-jelly

See the link below for the most up-to-date code
https://github.com/creatoro/jelly
MIT License
146 stars 34 forks source link

Timestamp pretty_format #59

Closed chrisgo closed 14 years ago

chrisgo commented 14 years ago

Is this implemented? Probably have to add a method inside Jelly_Field_Timestamp

public function get($model, $value)
{
    if( $this->pretty_format ) 
        {
        return (date($this->pretty_format, $value));
    }
    return $value;
}
jonathangeiger commented 14 years ago

It's only used for the input() method.

SpadXIII commented 14 years ago

How would you access this and other field-properties ? I've only used this so far:

$model->meta()->fields('fieldname')->pretty_format
banks commented 14 years ago

How would you access this and other field-properties ?

Like you just did...

SpadXIII commented 14 years ago

Ah, that's cool .. it just seemed like an inverted-shortcut to me at first, but it works

chrisgo commented 14 years ago

Maybe I am using this wrong ... this is how I came across this "issue" (or non-issue) - maybe there is a better way than to stuff this into the Model

I have a datetime field in the database (it's stored as Y-m-d G:i:s format in the database as opposed to a integer) so I put the formatting string in "format" (which works better than in Sprig). On my View, when I do something like

$object->create_date

it displays as a integer ... so I placed that get() method in Jelly_Field_Timestamp to display it in the "pretty-format".

Thinking about this more ... this is probably NOT a good idea as this could affect all the date calculations that operate on the integer format of the date.

Maybe the best way to implement this is to create a static method in a Model_Base like

Model_Base::formatDate($obj->create_date);

and just use it to "standardize" date outputs in the application

jonathangeiger commented 14 years ago

Thinking about this more ... this is probably NOT a good idea as this could affect all the date calculations that operate on the integer format of the date.

Probably not. I can't be entirely sure of the ramifications but Jelly converts all dates to a common format that can be easily used within PHP.

Your solution is fine, but you could also override the __get() method in Jelly_Model or create a field of your own that converts it to the pretty format so you have two fields, one that is dealing with the the time as a UNIX timestamp and the other that keeps it in the pretty format.

banks commented 14 years ago

Jon, is this a bug or request and will it be resolved? Can you tag it appropriately?

jonathangeiger commented 14 years ago

It's a feature request and outside of the scope of Field_Timestamp. I'm closing it.