• Hi everybody, i’ve got a functions which display time, when the post was published like: 2 hours ago:

    function get_date( $date, $first, $second, $third ) {
    	if ( ( ( $date % 10 ) > 4 && ( $date % 10 ) < 10 ) || ( $date > 10 && $date < 20 ) ) {
    		return $second;
    	}
    	if ( ( $date % 10 ) > 1 && ( $date % 10 ) < 5 ) {
    		return $third;
    	}
    	if ( ( $date % 10 ) == 1 ) {
    		return $first;
    	} else {
    		return $second;
    	}
    }
    
    function timespan( $seconds = 1, $time = '' ) {
    	if ( ! is_numeric( $seconds ) ) {
    		$seconds = 1;
    	}
    	if ( ! is_numeric( $time ) ) {
    		$time = time();
    	}
    	if ( $time <= $seconds ) {
    		$seconds = 1;
    	} else {
    		$seconds = $time - $seconds;
    	}
    
    	$str   = array();
    	$years = floor( $seconds / 31536000 );
    
    	if ( $years > 0 ) {
    		$str[] = $years . ' ' . get_date( $years,
    				__( '<!--:ru-->год<!--:--><!--:ua-->рік<!--:--><!--:en-->year<!--:-->' ),
    				__( '<!--:ru-->лет<!--:--><!--:ua-->років<!--:--><!--:en-->years<!--:-->' ),
    				__( '<!--:ru-->года<!--:--><!--:ua-->року<!--:--><!--:en-->year<!--:-->' ) );
    	}
    
    	$seconds -= $years * 31536000;
    	$months = floor( $seconds / 2628000 );
    
    	if ( $years > 0 OR $months > 0 ) {
    		if ( $months > 0 ) {
    			$str[] = $months . ' ' . get_date( $months,
    					__( '<!--:ru-->месяц<!--:--><!--:ua-->місяць<!--:--><!--:en-->month<!--:-->' ),
    					__( '<!--:ru-->месяцев<!--:--><!--:ua-->місяців<!--:--><!--:en-->months<!--:-->' ),
    					__( '<!--:ru-->месяца<!--:--><!--:ua-->місяця<!--:--><!--:en-->months<!--:-->' ) );
    		}
    
    		$seconds -= $months * 2628000;
    	}
    
    	$weeks = floor( $seconds / 604800 );
    
    	if ( $years > 0 OR $months > 0 OR $weeks > 0 ) {
    		if ( $weeks > 0 ) {
    			$str[] = $weeks . ' ' . get_date( $weeks,
    					__( '<!--:ru-->неделю<!--:--><!--:ua-->тиждень<!--:--><!--:en-->week<!--:-->' ),
    					__( '<!--:ru-->недель<!--:--><!--:ua-->тижнів<!--:--><!--:en-->weeks<!--:-->' ),
    					__( '<!--:ru-->недели<!--:--><!--:ua-->тижні<!--:--><!--:en-->weeks<!--:-->' ) );
    		}
    
    		$seconds -= $weeks * 604800;
    	}
    
    	$days = floor( $seconds / 86400 );
    
    	if ( $months > 0 OR $weeks > 0 OR $days > 0 ) {
    		if ( $days > 0 ) {
    			$str[] = $days . ' ' . get_date( $days,
    					__( '<!--:ru-->день<!--:--><!--:ua-->день<!--:--><!--:en-->day<!--:-->' ),
    					__( '<!--:ru-->дней<!--:--><!--:ua-->днів<!--:--><!--:en-->days<!--:-->' ),
    					__( '<!--:ru-->дня<!--:--><!--:ua-->дня<!--:--><!--:en-->day<!--:-->' ) );
    		}
    
    		$seconds -= $days * 86400;
    	}
    
    	$hours = floor( $seconds / 3600 );
    	if ( $days == 0 ) {
    		if ( $days > 0 OR $hours > 0 ) {
    			if ( $hours > 0 ) {
    				$str[] = $hours . ' ' . get_date( $hours,
    						__( '<!--:ru-->час<!--:--><!--:ua-->година<!--:--><!--:en-->hour<!--:-->' ),
    						__( '<!--:ru-->часов<!--:--><!--:ua-->годин<!--:--><!--:en-->hours<!--:-->' ),
    						__( '<!--:ru-->часа<!--:--><!--:ua-->години<!--:--><!--:en-->hours<!--:-->' ) );
    			}
    
    			$seconds -= $hours * 3600;
    		}
    	}
    
    	if ( $days == 0 ) {
    		$minutes = floor( $seconds / 60 );
    
    		if ( $days > 0 OR $hours > 0 OR $minutes > 0 ) {
    			if ( $minutes > 0 ) {
    				$str[] = $minutes . ' ' . get_date( $minutes,
    						__( '<!--:ru-->минута<!--:--><!--:ua-->хвилина<!--:--><!--:en-->minute<!--:-->' ),
    						__( '<!--:ru-->минут<!--:--><!--:ua-->хвилин<!--:--><!--:en-->minutes<!--:-->' ),
    						__( '<!--:ru-->минуты<!--:--><!--:ua-->хвилини<!--:--><!--:en-->minutes<!--:-->' ) );
    			}
    
    			$seconds -= $minutes * 60;
    		}
    	}
    	if ( $days == 0 ) {
    		if ( $str == '' ) {
    			$str[] = $seconds . ' ' . get_date( $seconds,
    					__( '<!--:ru-->секунда<!--:--><!--:ua-->секунда<!--:--><!--:en-->second<!--:-->' ),
    					__( '<!--:ru-->секунд<!--:--><!--:ua-->секунд<!--:--><!--:en-->seconds<!--:-->' ),
    					__( '<!--:ru-->секунды<!--:--><!--:ua-->секунди<!--:--><!--:en-->seconds<!--:-->' ) );
    		}
    	}
    print_r($str);
    	return $str;
    }
    
    function get_time_details( $post_id, $details_num = 5 ) {
    	$postDate = strtotime( get_the_time( 'Y-m-d H(idea)(worry)' ), $post_id );
    	$now      = current_time( 'timestamp' );
    	$result   = timespan( $postDate, $now );
    
    	$str = '';
    	for ( $i = 0; $i <= $details_num; $i ++ ) {
    		if ( ! empty( $result[ $i ] ) ) {
    			$str .= $result[ $i ] . ' ';
    		}
    	}
    	if ( empty( $str ) ) {
    		$str .= ' ' . __( '<!--:ru-->меньше минуты<!--:--><!--:ua-->менше хвилини<!--:--><!--:en-->less than a minute<!--:-->' );
    	} else {
    		$str .= ' ' . __( '<!--:ru-->назад<!--:--><!--:ua-->тому<!--:--><!--:en-->ago<!--:-->' );
    	}
    
    	return $str;
    
    }

    but they display thise: 45 yeras 1 week 20 hours and 6 minutes.

    Can somebody explain why?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘My WordPress functions not working correctly, please help’ is closed to new replies.