/** * Name of this extension * * @return string */ public function getTimeAgo($date) { return Str::timeAgo($date); }
public function testTimeAgo() { $elapsedTime = new \DateTime(); $date = $elapsedTime; $this->expected = '0秒前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT59S')); $this->expected = '59秒前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT60S')); $this->expected = '1分前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT59M59S')); $this->expected = '59分前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT59M60S')); $this->expected = '1時間前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT23H59M59S')); $this->expected = '23時間前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('PT23H59M60S')); $this->expected = '1日前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('P31DT23H59M59S')); $this->expected = '31日前'; $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('P31DT23H59M60S')); $this->expected = date('Y/m/d', strtotime('- 32 days')); $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); $elapsedTime = new \DateTime(); $date = $elapsedTime->sub(new \DateInterval('P1Y')); $this->expected = date('Y/m/d', strtotime('- 1 years')); $this->actual = Str::timeAgo($date); $this->assertEquals($this->expected, $this->actual); // 日付書式を引数に $this->expected = date('Y/m/d', strtotime('- 1 years')); $this->actual = Str::timeAgo(date('Y/m/d', strtotime('- 1 years'))); $this->assertEquals($this->expected, $this->actual); // 引数が空 $this->actual = Str::timeAgo(''); $this->assertEmpty($this->actual); }