Page 1 of 1

How can I hack strftime functionality?

Posted: Wed Feb 27, 2008 11:24 pm
by mfm
Ok strftime covers the most time formattings. But I missing one tag and that is month as a number without leading zeroes (range 1 to 12)
This is quite strange because there is day of the month (1-31) without leading zeroes (%e) but not month  :(

There is a php-code to strip zeroes, like this:

Code: Select all

function strip_zeros_from_date( $marked_date_string ) {
  $cleaned_string = str_replace('*', '', str_replace('*0', '', $marked_date_string));
  return $cleaned_string;
}
But how can I implement/hack  it in CMS:MS so I can use it in all date format strings, for example the news or comments module .

Re: How can I hack strftime functionality?

Posted: Fri Feb 29, 2008 5:57 am
by altlogin
Hmm... with PHP5 you could use strptime which parses the date into an array, and the month is 0-11 so just and one
http://us2.php.net/manual/en/function.strptime.php


The problem with hacking it everywhere is that there might be some date comparisons that could fail as 01 collates differently than 1.  The comments module pulls the comments from the DB and sorts by date, so you might just look at changing the view, not the data.


If you are just after news and comments, you might change line 57  in News/action.detail.php
            $onerow->formatpostdate = strftime($dateformat, $db->UnixTimeStamp($row['news_date']));
to go through and strip the 0 from the month along the lines of your example.

In Comments/action.detail.php look for the line
$onerow->date = strftime($localedateformat, $db->UnixTimeStamp($row['comment_date']));

and strip out the zero from the month there as well.

That will only change the display, and keep you from messing with any logic.

Of course, back up, then change, then test!


Good luck.

Re: How can I hack strftime functionality?

Posted: Sun Mar 02, 2008 5:19 pm
by mfm
Thx very much! I got it work