Login | Register
My pages Projects Community openCollabNet

Discussions > users > [propel] proposal: date/time formatting accessors

Discussion topic

Hide all messages in topic

All messages in topic

[propel] proposal: date/time formatting accessors


Author hlellelid
Full name Hans Lellelid
Date 2004-03-10 17:33:36 PST
Message Hi,

I'd like to propose a change that would add a convenience factor to the
accessor (get*()) methods for date/time/timestamp columns. In short,
I'd like to be able to specify a format string when calling get*() on a
date/time, column -- OR I'd like to be able to specify a new default
date/time/timestamp formatting string in the build file. Either option
would work, but I think the call-time one (add'l param to get*()
methods) would be a little more attractive.

For example:

<table name="stamp_test">
  <column name="stamp" type="TIMESTAMP" />

Right now, the Creole ResultSet->getTimestamp() method is used to return
values for that field. No formatting string is passed to the
getTimestamp() method, so the default (YYYY-MM-DD HH:MM:SS) is used.
That means that if I call StampTest->getStamp() I will get this ISO
timestamp value that I will than have to convert *back* into a unix
timestamp in order to re-format it:
    $row = StampTestPeer::doSelectOne(new Criteria());
    $datetime = $row->getStamp();
    $ts = strtotime($datetime);
     $printable_datetime = strftime("%c", $ts);

Too much work. What I suggest is this:

    $row = StampTestPeer::doSelectOne(new Criteria());
    $printable_datetime = $row->getStamp("%c");

Supporting either strftime()-style or date()-style formatters. (it's
easy to support both because strftime()-style formatters always have %

Internally (inside the StampTest object) all date, time, and timestamp
values would be stored as unix timestamps. Perhaps calling the
getStamp() method with no paramter would return a unix timestamp? Or we
could continue to have it return readable defaults (the way that Creole
ResultSet does).

Any opinions / thoughts on that? This is a pretty simple change --
seems like it would make life easier. I know it would for me; I'm
always having to reformat dates.

If it's gonna break the exiting functionality (i.e. if the get*()
methods will return unix timestamps instead of readable dates) then I
think we should incorporate the change before initial release.
Otherwise it's not as critical that it be done immediately, since it
won't affect BC.


To unsubscribe, e-mail: users-unsubscribe@pr​opel.tigris.org
For additional commands, e-mail: users-help at propel dot tigris dot org
Messages per page: