business\Time::fromString PHP Method

fromString() public static method

Creates a new time from a string.
public static fromString ( string $time ) : Time
$time string
return Time
    public static function fromString($time)
    {
        try {
            $date = new \DateTime($time);
        } catch (\Exception $e) {
            throw new \InvalidArgumentException(sprintf('Invalid time "%s".', $time));
        }
        return self::fromDate($date);
    }

Usage Example

示例#1
0
 public function testFromString()
 {
     $time = Time::fromString('2pm');
     $this->assertEquals(14, $time->getHours());
     $this->assertEquals(0, $time->getMinutes());
 }