public static function factory($periodType, $periodDay = false)
    {
        switch ($periodType) {
            case 'hourly':
                return new Hourly();
            case 'daily':
                return new Daily();
            case 'weekly':
                $result = new Weekly();
                if ($periodDay !== false) {
                    $result->setDay($periodDay);
                }
                return $result;
            case 'monthly':
                $result = new Monthly($periodDay);
                if ($periodDay !== false) {
                    if (is_int($periodDay)) {
                        $result->setDay($periodDay);
                    } else {
                        $result->setDayOfWeekFromString($periodDay);
                    }
                }
                return $result;
            default:
                throw new Exception("Unsupported scheduled period type: '$periodType'. Supported values are"
                                  . " 'hourly', 'daily', 'weekly' or 'monthly'.");
        }
    }