New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal] To add validation rule for php timezones #4127

Closed
prady00 opened this Issue Apr 15, 2014 · 5 comments

Comments

Projects
None yet
4 participants
@prady00
Contributor

prady00 commented Apr 15, 2014

This feature will be used by developers as below :

$validator = Validator::make(
array('timezone' => array('timezone'))
);

It can be implemented by adding a function in Illuminate/Validation/Validator.php

validateTimezone($attribute, $value){
//
}

@franzliedke

This comment has been minimized.

Show comment
Hide comment
@franzliedke

franzliedke Apr 15, 2014

Contributor

What would this do? Validate that the string is a valid timezone (such as "UTC", "Europe/Amsterdam" etc.)?

Contributor

franzliedke commented Apr 15, 2014

What would this do? Validate that the string is a valid timezone (such as "UTC", "Europe/Amsterdam" etc.)?

@alexwhitman

This comment has been minimized.

Show comment
Hide comment
@alexwhitman

alexwhitman Apr 15, 2014

Contributor

Untested but this would probably work:

protected function validateTimezone($attribute, $value)
{
    try
    {
        new DateTimeZone($value);
    }
    catch (Exception $e)
    {
        return false;
    }

    return true;
}
Contributor

alexwhitman commented Apr 15, 2014

Untested but this would probably work:

protected function validateTimezone($attribute, $value)
{
    try
    {
        new DateTimeZone($value);
    }
    catch (Exception $e)
    {
        return false;
    }

    return true;
}
@prady00

This comment has been minimized.

Show comment
Hide comment
@prady00

prady00 Apr 15, 2014

Contributor

@franzliedke yes, you are right

@alexwhitman Yes, it's same I have done in my project. Thanks for confirmation ;). complete code looks like :

/**
* Validate that an attribute is a valid timestamp.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function validateTimezone($attribute, $value)
{
try {
new DateTimeZone($value);
}catch (Exception $e){
return false;
}
return true;
}

Contributor

prady00 commented Apr 15, 2014

@franzliedke yes, you are right

@alexwhitman Yes, it's same I have done in my project. Thanks for confirmation ;). complete code looks like :

/**
* Validate that an attribute is a valid timestamp.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
protected function validateTimezone($attribute, $value)
{
try {
new DateTimeZone($value);
}catch (Exception $e){
return false;
}
return true;
}

@taylorotwell

This comment has been minimized.

Show comment
Hide comment
@taylorotwell

taylorotwell May 2, 2014

Member

Fine with me if you wanna do it.

Member

taylorotwell commented May 2, 2014

Fine with me if you wanna do it.

@prady00

This comment has been minimized.

Show comment
Hide comment
@prady00

prady00 May 9, 2014

Contributor

Thanks @taylorotwell . Should I submit a pull request against master branch or 4.1 branch. I am done with enhancements.

Edit: I got the answer for it and submitted a pull request to master branch

Contributor

prady00 commented May 9, 2014

Thanks @taylorotwell . Should I submit a pull request against master branch or 4.1 branch. I am done with enhancements.

Edit: I got the answer for it and submitted a pull request to master branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment