Yii 1.1: timestring

A Yii widget for displaying a human friendly view of two dates
9 followers

This extension is a Widget that takes two dates and displays them in a human friendly string.

Here are some example outcomes

"2012-12-25" and "2012-12-31" will show as "25 to 31 Dec 2012"
"2012-12-25" and "2013-01-15" will show as "25 Dec 2012 to 15 Jan 2013"
"2013-01-05" and "2013-02-10" will show as "05 Jan to 10 Feb 2013"

Requirements

Yii 1.1 or above

Usage

  1. Copy the extension to your protected/extensions folder.
  2. In a View file, insert as a Widget using "YYYY-mm-dd" formatted parameters for 'startDate' and 'endDate'. Set 'duration' to true to show the number of days in brackets as a suffix.
$this->widget('TimeString', array(
    'startDate'=>$data->start_date, // assuming $data->start_date is "2012-12-25"
    'endDate'=>$data->end_date,     // assuming $data->end_date is "2012-12-31"
    'duration'=>true,
));

Total 4 comments

#11693 report it
Peter JK at 2013/01/27 09:57pm
CGridView

I see,

thx for your response. how about convert this extension into helper function? so, i could make a special AR function on model, and then call that function from CGridView? just idea..

#11684 report it
CobraF at 2013/01/27 08:09am
CGridView

Hi Peter, I tried using the example I have written below but without luck. The page renders up to the point where the widget code is and then stops rendering any further. Did you have any further luck? In the following example, I used

parent::widget

instead of

$this->widget

as "widget" is not a method of CGridView.

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'trip-grid',
    'dataProvider'=>$model->search(),
    'filter'=>$model,
    'columns'=>array(
        'id',
        array(
            'name'=>'start_date',
            'type'=>'raw',
            'value'=>'parent::widget(\'TimeString\', array(
                        \'startDate\'=>$data->start_date,
                        \'endDate\'=>$data->end_date,
                    ),
                    true);',
        ),
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>
#11605 report it
CobraF at 2013/01/22 05:46pm
RE: CGridView

Hi Peter, Thank you for your question. I haven't tried this in CGridView, but I will try it and come back to you.

#11561 report it
Peter JK at 2013/01/20 10:04pm
CGridView

is it working on CGridView?..

Leave a comment

Please to leave your comment.

Create extension