andre487 / php_rutils

[Project is not supported] php rutils - russian text handler for PHP
MIT License
211 stars 42 forks source link

other phrases for Dt::distanceOfTimeInWords() #9

Open walik91 opened 11 years ago

walik91 commented 11 years ago
$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

githubjeka commented 11 years ago
  1. return "Вчера" if $fromTime===null . And is correct.
  2. Individual option
andre487 commented 11 years ago
  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.
githubjeka commented 11 years ago

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​​.

andre487 commented 11 years ago

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

andre487 commented 11 years ago

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?

githubjeka commented 11 years ago

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 ..

andre487 commented 11 years ago

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

CrazyPHP commented 10 years ago

Why you talk on english if you russians?

githubjeka commented 10 years ago

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