Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Friendlier Time (Trac #1531) #1531

Closed
elgg-gitbot opened this issue Feb 16, 2013 · 9 comments
Closed

Friendlier Time (Trac #1531) #1531

elgg-gitbot opened this issue Feb 16, 2013 · 9 comments

Comments

@elgg-gitbot
Copy link

Original ticket http://trac.elgg.org/ticket/1531 on 40136141-10-07 by trac user jricher, assigned to unknown.

Elgg version: 1.7

Formats friendly times older than 2 weeks as a simple date, using the language file and elgg_echo to determine the date format (allows for custom localization of dates, too).

@elgg-gitbot
Copy link
Author

Attachment added by trac user jricher on 40136142-06-30: friendlier_time.patch

@elgg-gitbot
Copy link
Author

cash wrote on 40136433-03-05

When dealing with this, also see #1265 which I'm closing as a duplicate (even though it's not exactly). Also see #451

@elgg-gitbot
Copy link
Author

trac user jricher wrote on 40136475-04-28

I did it this way as a compromise between the two alternatives posited in #1265 that uses both where reasonable (at least, as I thought).

Ultimately, I'd rather have there be a programmatic way to set the time and date formatting for different time periods, and to set the time periods themselves, from an admin console. One of our sites here had actually overridden the friendly_time function call to always post the date string (in a hardcoded format), and it'd be nice to have that as a configuration option. But until we figure out how to do that, I think this is a good stopgap that'd keep us from having another local patch against 1.7 final.

As to #451, I'd be happy to see this use strftime instead of date -- but where do we get the info to send into setlocale in the first place? Without that, strftime is as limited as date, it seems.

@elgg-gitbot
Copy link
Author

cash wrote on 40136499-07-02

Decided not to close #1265 for the time being.

Eventually Elgg is going to have to deal with locale and timezones (especially if we allow absolute timestamps). I'm assuming we'd do it by allowing the admin to select the defaults and users can set their own location just like they can set their own language.

What we did was use the acronym tag on timestamps so it shows the friendly time and if you mouse over, it shows absolute.

@elgg-gitbot
Copy link
Author

brettp wrote on 40139787-09-07

(In [svn:3957]) Refs #1531: Added full time and dates to friendly time stamptes via acronym tags.

@elgg-gitbot
Copy link
Author

brettp wrote on 40139794-03-06

I've used Cash's approach for 1.7 because it provides added functionality without UI changes. Some people might prefer the "friendly times" so until we can provide an admin option, let's keep it as it has been.

Closing this ticket in favor of #1265 and #451.

@elgg-gitbot
Copy link
Author

trac user thomas wrote on 40146224-02-10

Sibce [svn:3957] the logic is broken, because the old "return" skiped the rest of the function. Now

$friendly_time = sprintf(elgg_echo("friendlytime:hours:singular"), $diff);

will be always the winner, because it stands outside an else {} and will always overide

if ($diff > 1) {
            $friendly_time = sprintf(elgg_echo("friendlytime:hours"), $diff);
}

Here the complete fix

function friendly_time($time) {
    $diff = time() - ((int) $time);

    if ($diff < 60) {
        return elgg_echo("friendlytime:justnow");
    } else if ($diff < 3600) {
        $diff = round($diff / 60);
        if ($diff == 0) {
            $diff = 1;
        } 
        if ($diff > 1) {
            $friendly_time = sprintf(elgg_echo("friendlytime:minutes"), $diff);
        } else {
            $friendly_time = sprintf(elgg_echo("friendlytime:minutes:singular"), $diff);
        }
    } else if ($diff < 86400) {
        $diff = round($diff / 3600);
        if ($diff == 0) {
            $diff = 1;
        }
        if ($diff > 1) {
            $friendly_time = sprintf(elgg_echo("friendlytime:hours"), $diff);
        } else {
            $friendly_time = sprintf(elgg_echo("friendlytime:hours:singular"), $diff);
        }
    } else {
        $diff = round($diff / 86400);
        if ($diff == 0) {
            $diff = 1;
        }
        if ($diff > 1) {
            $friendly_time = sprintf(elgg_echo("friendlytime:days"), $diff);
        } else {
            $friendly_time = sprintf(elgg_echo("friendlytime:days:singular"), $diff);
        }
    }

    $timestamp = htmlentities(date(elgg_echo('friendlytime:date_format', $time)));
    return "<acronym title=\"$timestamp\">$friendly_time</acronym>";
}

@elgg-gitbot
Copy link
Author

trac user thomas wrote on 40146233-06-16

And another one:

$timestamp = htmlentities(date(elgg_echo('friendlytime:date_format'), $time));

There was missing a ) after elgg_echo('friendlytime:date_format', so always the actual time was returned

@elgg-gitbot
Copy link
Author

brettp wrote on 40146902-04-01

(In [svn:3965]) Fixes #1531: Correctly implemented dates for friendly times. No more coding while watching the Olympics!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant