diff options
author | Sarven Capadisli <csarven@status.net> | 2010-01-05 01:16:48 +0000 |
---|---|---|
committer | Sarven Capadisli <csarven@status.net> | 2010-01-05 01:16:48 +0000 |
commit | 48289e607bf207b40201075be8b599c0f3fa597e (patch) | |
tree | d310e7091467460905287bc29b33098cf986a906 /lib/util.php | |
parent | eb9514120a882aacae38f8b85a1f431852b44b89 (diff) | |
parent | 440b9957f9ae6fdfdb44c39074803fcdbc64112d (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", |