php_rutils icon indicating copy to clipboard operation
php_rutils copied to clipboard

other phrases for Dt::distanceOfTimeInWords()

Open walik91 opened this issue 11 years ago • 9 comments

$fromTime = '2013-10-24 11:45';
$toTime = '2013-10-23 11:45';
$accuracy = 3;
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy);
//Returns: 1 день назад

I think it would be better if the phrase would be "Днем ранее" or "Вчера" (if $fromTime is today)

$fromTime = '2013-10-24 11:40';
$toTime = '2013-10-24 11:10';
$accuracy = 3;
echo RUtils::dt()->distanceOfTimeInWords($toTime, $fromTime, $accuracy);
//Returns: 30 минут назад

I think it would be better if the phrase would be "полчаса назад" or "через полчаса" (if the variables $fromTime and $toTime are interchanged)

And other similar examples

walik91 avatar Oct 23 '13 11:10 walik91

  1. return "Вчера" if $fromTime===null . And is correct.
  2. Individual option

githubjeka avatar Oct 23 '13 12:10 githubjeka

  1. I agree with @githubjeka, behavior like this may be correct only when FromTime == null (now).
  2. Need discuss this problem. I'm not sure what's correct.

andre487 avatar Oct 25 '13 12:10 andre487

I wanted to make the rules for setting their records:

 public $rules = array(
        'm'=>array('полчаса'=> 30, 'четверть часа' => 25),
        'h'=>array(),
        'd'=>array('год'=> 365),
    );

but Prevents me to do the following code: $this->_trimArrays($words);

 private function _trimArrays(array &$arr, array &$arr2=null)
    {
        $i = sizeof($arr) - 1;

        while ($i >= 0 && $arr[$i] == 0) {
            var_dump($arr);
            echo 1;
            array_pop($arr);
            if ($arr2)
                array_pop($arr2);
            --$i;
        }
        ...
    }

$arr[$i] == 0

true if "полчаса" and this delete. Problem in the line. Since it must start with a number and do not be zero....

P.S. Need to come up with some sort of a handy set of rules and check them and substitute the values​​.

githubjeka avatar Oct 25 '13 13:10 githubjeka

I think, it possible even with trim. Today I will try to extend this module's functionality.

andre487 avatar Oct 26 '13 07:10 andre487

Algorithm of this function was rewritten. At now it became much better and flexible. But in which cases "полчаса" or "четверть часа" need to be returned? When a minutes strictly equals 30 or 15?

andre487 avatar Oct 26 '13 12:10 andre487

It would be great if you could set the rules for replacement:

public $rules = array(
        'y' => array('1 год' => 'один год'),
        'm' => array(),
        'd' => array(),
        'h' => array(),
        'i' => array('30 минут' => 'полчаса', '15 минут' => 'четверть часа'),
    );

I made ​​a quick sketch: https://github.com/githubjeka/php_rutils/blob/50be6d6dac759f19ff3b7db4f706df789751bde2/Dt.php#L164

uses

use php_rutils\RUtils;
$accuracy = RUtils::ACCURACY_YEAR;
echo  RUtils::dt()->distanceOfTimeInWords(new DateTime('now'), new DateTime('now + 1 year 3 hours 30 minute'),$accuracy);
echo  RUtils::dt()->distanceOfTimeInWords(new DateTime('now - 30 minute'), new DateTime('now'),$accuracy);
echo  RUtils::dt()->distanceOfTimeInWords(new DateTime('now - 15 minute'), new DateTime('now'),$accuracy);

reuslt один год назадполчаса назадчетверть часа назад

think about ..

githubjeka avatar Oct 28 '13 09:10 githubjeka

I think about it a lot. But I think this feature is not necessary. I leave this issue open for community voting.

andre487 avatar Nov 02 '13 13:11 andre487

Why you talk on english if you russians?

CrazyPHP avatar Apr 25 '14 18:04 CrazyPHP

Github this international place. While communicating in English, there is a chance that your code will support not only the Russian players.

githubjeka avatar Apr 25 '14 19:04 githubjeka