diff options
author | Evan Prodromou <evan@status.net> | 2010-01-04 10:55:21 -1000 |
---|---|---|
committer | Evan Prodromou <evan@status.net> | 2010-01-04 10:55:21 -1000 |
commit | 6add2693b009a2122883f4f6c96c775be878e42c (patch) | |
tree | ea6f11e37e44f61216cf9d3f678d2d99a72fc30c /lib/util.php | |
parent | 96480aa6c1abda95db272f7c0a2b0e96f17acc70 (diff) | |
parent | f5b8177bc752c29228ee76bc95285cdbb8549748 (diff) |
Merge branch '0.9.x' of git@gitorious.org:statusnet/mainline into 0.9.x
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/util.php b/lib/util.php index 63656b604..50bd0e2ac 100644 --- a/lib/util.php +++ b/lib/util.php @@ -908,6 +908,26 @@ function common_sql_date($datetime) return strftime('%Y-%m-%d %H:%M:%S', $datetime); } +/** + * Return an SQL fragment to calculate an age-based weight from a given + * timestamp or datetime column. + * + * @param string $column name of field we're comparing against current time + * @param integer $dropoff divisor for age in seconds before exponentiation + * @return string SQL fragment + */ +function common_sql_weight($column, $dropoff) +{ + if (common_config('db', 'type') == 'pgsql') { + // PostgreSQL doesn't support timestampdiff function. + // @fixme will this use the right time zone? + // @fixme does this handle cross-year subtraction correctly? + return "sum(exp(-extract(epoch from (now() - $column)) / $dropoff))"; + } else { + return "sum(exp(timestampdiff(second, utc_timestamp(), $column) / $dropoff))"; + } +} + function common_redirect($url, $code=307) { static $status = array(301 => "Moved Permanently", |