function to_db_time($string, $mer = '')
{
    global $timeMeridiem;
    $hours = getHours($string);
    $minutes = getMinutes($string);
    if (!empty($mer)) {
        $meridiem = $mer;
    } else {
        $meridiem = getMeridiem($string);
    }
    if (!empty($meridiem)) {
        $hours = $hours % 12;
    }
    if ($meridiem == $timeMeridiem[1]) {
        $hours += 12;
    }
    if ($hours > 24) {
        $hours = $hours % 24;
    }
    if ($hours < 10 && strlen($hours) == 1) {
        $hours = '0' . $hours;
    }
    return $hours . ':' . $minutes;
}
Exemple #2
0
function getDiff($timestamp)
{
    $now = time();
    if ($timestamp > $now) {
        echo 'Podana data nie może być większa od obecnej.';
        // tutaj była 'zła data'
        return;
    }
    $diff = $now - $timestamp;
    $minut = floor($diff / 60);
    $godzin = floor($minut / 60);
    $dni = floor($godzin / 24);
    if ($minut <= 60) {
        $res = getMinutes($minut);
        switch ($res) {
            case 0:
                return "przed chwilą";
            case 1:
                return "minutę temu";
            default:
                return $res;
        }
    }
    if ($godzin > 6 && $godzin < 24) {
        return "Dzisiaj " . date("H:i:s", $timestamp);
    } elseif ($godzin > 0 && $godzin < 24) {
        $restMinutes = $minut - 60 * $godzin;
        $res = getMinutes($restMinutes);
        if ($godzin == 1) {
            return "Godzinę temu " . $res;
        } else {
            return "{$godzin} godzin temu " . $res;
        }
    }
    if ($godzin >= 24 && $godzin <= 48) {
        return "Wczoraj " . date("H:i:s", $timestamp);
    }
    switch ($dni) {
        case $dni < 7:
            return "{$dni} dni temu, " . date("Y-m-d", $timestamp);
            break;
        case 7:
            return "Tydzień temu, " . date("Y-m-d", $timestamp);
            break;
        case $dni > 7 && $dni < 14:
            return "Ponad tydzień temu, " . date("Y-m-d", $timestamp);
            break;
        case 14:
            return "Dwa tygodnie temu, " . date("Y-m-d", $timestamp);
            break;
        case $dni > 14 && $dni < 30:
            return "Ponad 2 tygodnie temu, " . date("Y-m-d", $timestamp);
            break;
        case 30:
        case 31:
            return "Miesiąc temu";
            break;
        case $dni > 31:
            return date("Y-m-d", $timestamp);
            break;
    }
    return date("Y-m-d", $timestamp);
}