2017 © Pedro Peláez
 

library input-to-date

A small PHP library that assists with converting your user input into a Carbon object

image

jono20201/input-to-date

A small PHP library that assists with converting your user input into a Carbon object

  • Thursday, May 4, 2017
  • by Jono20201
  • Repository
  • 3 Watchers
  • 2 Stars
  • 6,125 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 22 % Grown

The README.md

InputToDate

This is a really simple library to convert user input to a Carbon object without having to worry about the possible exceptions that maybe thrown with bad or empty input., (*1)

If you're using a framework (such as Laravel) you should still validate user input if you want to send them nice errors about invalid input., (*2)

Features

  • Parse user input to a Carbon object.
  • Throw an Exception or return a default upon error/empty input.
  • Fluent API

Usage

The following example would return a Carbon object with the correct date., (*3)

    $user_input = '01/01/2016 09:30:30'
    $date = InputToDate::create('d/m/Y H:i:s')
                        ->convert($user_input);

The following example has incorrect input, and will return null as we have asked it to by running the setReturnNullOnFailure() method., (*4)

    $user_input = '01/01/2016 09:30:30'
    $date = InputToDate::create('d/m/Y')
                        ->setReturnNullOnFailure()
                        ->convert($user_input);

The following example will return this current time as its incorrect, but as have asked for a default of Carbon::now()., (*5)

    $user_input = '01/01/2016 09:30:30'
    $date = InputToDate::create('d/m/Y')
                        ->setDefault(Carbon::now())
                        ->convert($user_input);

The following will throw an InvalidArgumentException exception as the input is incorrect and we have not set any other default. You can also explicitly add the throwException() method., (*6)

    $user_input = '01/01/2016 09:30:30'
    $date = InputToDate::create('d/m/Y')
                        ->convert($user_input);

Contribute

Pull requests are more than welcome., (*7)

The Versions

04/05 2017

dev-master

9999999-dev

A small PHP library that assists with converting your user input into a Carbon object

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jonathan Martin

date validate input parse

26/10 2016

v1.3

1.3.0.0

A small PHP library that assists with converting your user input into a Carbon object

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jonathan Martin

date validate input parse

26/10 2016

1.2

1.2.0.0

A small PHP library that assists with converting your user input into a Carbon object

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jonathan Martin

date validate input parse

26/10 2016

1.0.1

1.0.1.0

A small PHP library that assists with converting your user input into a Carbon object

  Sources   Download

MIT

The Requires

 

The Development Requires

by Jonathan Martin

date validate input parse

26/10 2016

1.0

1.0.0.0

A small PHP library that assists with converting your user input into a Carbon object

  Sources   Download

MIT

The Requires

 

by Jonathan Martin

date validate input parse