Yii Framework Forum: Different dateformat specifications - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Different dateformat specifications Rate Topic: ***** 2 Votes

#1 User is offline   nicocin 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 29-November 10

Posted 13 January 2011 - 06:01 AM

I'm getting confused by the different ways to specifiy a date format in Yii;

In my application I have some models witch contain (user supplied) dates.
The dates are saved as unix timestamps (integers) in the models (and DB). Off course I want to transform this timestamp into a human-readable format in the user interface.
In the user interface I want dates to be displayed and inputted as '31-12-2011';

To transform a timestamp to a readable date I use
CFormatter : Yii::app()->format->formatDate( $date ); //date format is specified in config file as 'd-m-Y'
And
CDateFormatter : Yii::app()->dateFormatter->formatDate( $format, $date ); // $format == 'dd-MM-yyyy'

To transform a human readable date back into a timestamp I use:
CDateTimeParser : CDateTimeParser::parse( $date, $format ); // $format == 'dd-MM-yyyy'

I've got this working now, but I struggled with it, because the way you specifie the format for a date (or datetime) is different for all three:
CFormatter uses PHP's date() and therefore expects a format as accepted by date (specs: http://php.net/manua...nction.date.php)
CDateFormatter uses CLDR (specs: http://www.unicode.o...Format_Patterns)
CDateTimeParser uses its own pattern specification (specs: http://www.yiiframew...CDateTimeParser)
(might seem like a subset of PHP's date function specification, but its not, for example minute (00-59) is 'mm' in CDateTimeParser but 'i' in PHP's date)

I think it would be much easier if there would be one pattern specification used by all formatting/parsing functions.
(I now have three date formats in my config file all describing the same pattern!!)

What do you think?
Has anybody got any tips to prevent confusion when using date formatting/parsing functions?
2

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 13 January 2011 - 09:13 AM

I have the same problem.

I'd add to the list CJuiDatePicker, wich uses one more different format.
1

#3 User is offline   Piemol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 03-February 16

Posted 13 September 2017 - 10:07 AM

+1 for identifying this inconveniance !
I'm glad I finally could find this topic, so I'm not the only one. Too bad no other response in 6.5 years :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users