From a424fecdae3b54b47778ed7a52452ff80c2bf631 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 12 Jun 2012 22:52:34 -0700 Subject: [PATCH] this should catch any weirdness caused by being in different timezones and making your first post on the 31st of March --- include/items.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/include/items.php b/include/items.php index 2a0a9a4268..35a4396dc9 100755 --- a/include/items.php +++ b/include/items.php @@ -3402,26 +3402,32 @@ function first_post_date($uid,$wall = false) { ); if(count($r)) { // logger('first_post_date: ' . $r[0]['id'] . ' ' . $r[0]['created'], LOGGER_DATA); - return substr($r[0]['created'],0,10); + return substr(datetime_convert('',date_default_timezone_get(),$r[0]['created']),0,10); } return false; } function posted_dates($uid,$wall) { - $dnow = datetime_convert('','','now','Y-m-d'); + $dnow = datetime_convert('',date_default_timezone_get(),'now','Y-m-d'); $dthen = first_post_date($uid,$wall); if(! $dthen) return array(); + // If it's near the end of a long month, backup to the 28th so that in + // consecutive loops we'll always get a whole month difference. + + if(intval(substr($dnow,8)) > 28) + $dnow = substr($dnow,0,8) . '28'; + if(intval(substr($dthen,8)) > 28) + $dnow = substr($dthen,0,8) . '28'; + $ret = array(); while($dnow >= $dthen) { $start_month = datetime_convert('','','first day of ' . $dnow,'Y-m-d'); $end_month = datetime_convert('','','last day of ' . $dnow,'Y-m-d'); $str = day_translate(datetime_convert('','',$dnow,'F Y')); $ret[] = array($str,$end_month,$start_month); - if($start_month < $dthen) - break; $dnow = datetime_convert('','',$dnow . ' -1 month', 'Y-m-d'); } return $ret;