jizuscreed/time-approximator

一个用于生成简短、近似、人性化的时间描述的小型库。受 https://github.com/martinandert/damals 启发

0.1 2020-03-19 22:16 UTC

This package is auto-updated.

Last update: 2024-09-20 08:23:08 UTC


README

一个用于生成简短、近似、人性化的时间描述的小型库。受 https://github.com/martinandert/damals 启发

安装

composer require jizuscreed/time-approximator

实例化

$timeApproximator = new jizuscreed\TimeApproximator\TimeApproximator(new \jizuscreed\TimeApproximator\Languages\Russian());

它能够

$this->timeApproximator->getDescriptionFor(20); // полминуты
$this->timeApproximator->getDescriptionFor(40); // меньше чем 1 минута
$this->timeApproximator->getDescriptionFor(16*60); // 16 минут
$this->timeApproximator->getDescriptionFor(11*60); // 11 минут
$this->timeApproximator->getDescriptionFor(46*60); // примерно 1 час
$this->timeApproximator->getDescriptionFor(43*60); // 43 минуты
$this->timeApproximator->getDescriptionFor(68*60); // примерно 1 час
$this->timeApproximator->getDescriptionFor(24*60*60*15+23*60*60+15*600; // 16 дней)

创建语言包

只需在 jizuscreed\TimeApproximator\Languages 中创建类,继承 jizuscreed\TimeApproximator\Languages\AbstractLanguagePack 并实现抽象方法

贡献

请发送您的拉取请求,特别是语言包