使用相同数据的相同功能会给我不同的结果

时间:2017-07-09 20:14:16

标签: php

我有一些代码只是为了知道发送消息的时间:

function time_ago ($respuestas) {

$date = $respuestas;

$today_date = getdate();
$months = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio','julio','agosto','septiembre','octubre','noviembre','diciembre'];

$minute = $today_date['minutes'];
$hour = $today_date['hours'];
$day = $today_date['mday'];
$month = $today_date['mon'];

if ($today_date['hours'] <= 9) {
    $hour = "0" . $today_date['hours'];
}

if ($today_date['minutes'] <= 9) {
    $minute = "0" . $today_date['minutes'];
}

if ($today_date['mon'] <= 9) {
    $month = "0" . $today_date['mon'];
}

if ($today_date['mday'] <= 9) {
    $day = "0" . $today_date['mday'];
}

$actual_total_date = $today_date['year'] . "-" . $month . "-" . $day . " " . $hour . ":" . $minute;
$actual_total_date = new DateTime($actual_total_date);
//data of the date of the post
$post_date = substr($date,0,16);
$post_date = new DateTime($post_date);
$post_year = substr($date,0,4);
$post_month = substr($date,5,2);
$post_day = substr($date,8,2);
$post_hour = substr($date,11,2);
$post_minute = substr($date,14,2);
$interval = date_diff($post_date, $actual_total_date);
$invertal_days = substr($interval->format('%R%a'),1,strlen($interval->format('%R%a')));
$invertal_hours = $interval->format('%H');
$invertal_minutes = $interval->format('%I');

$result = "";

if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 1) {
    $result = "Now";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes == 1) {
    $result = substr($invertal_minutes,1,2) . " minute ago";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 10 AND $invertal_minutes > 1) {
    $result = substr($invertal_minutes,1,2) . " minutes ago";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 60 AND $invertal_minutes >= 10) {
    $result = $invertal_minutes . " minutes ago";
} else if ($invertal_days == 0 AND $post_day == $day) {
    $result = "Today at " . $post_hour . ":" . $post_minute ;
} else if ($invertal_days == 0 AND $post_day == $day-1) {
    $result = "Yesterday at " . $post_hour . ":" . $post_minute;
} else if ($invertal_days == 1 AND $post_day == $day-1) {
    $result = "Yesterday at " . $post_hour . ":" . $post_minute;
} else {
    $result = $post_day . " " . $months[$post_month-1] . " " . $post_year . " " . $post_hour . ":" . $post_minute;
}

return $result;

问题我只在生产中发生,而不是在本地发生,经过一些研究后我不知道发生了什么。会发生什么是这个函数给了我两个不同的输出和相同的输入。例如,日期:2017-07-09 20:52:39,在我发送此帖子时,它应该输入第四个条件,因为分钟间隔在10到60分钟之间。

如果需要,我可以分享到我遇到问题的网站。我已经测试了我用于该功能的数据并且它是正确的。

0 个答案:

没有答案