hrevert / day-of-week
Day of week library
0.0.1
2014-07-17 17:48 UTC
Requires
- php: >=5.4
- doctrine/collections: 1.*
- marc-mabe/php-enum: 1.2.*
Requires (Dev)
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-11-13 03:22:34 UTC
README
Day of week library
Usage
Please read the docs of php-enum first.
use Hrevert\Day\Day; /** @var Day */ $day = Day::get(Day::MONDAY); // or $day = Day::MONDAY(); // or $day = Day::getByName('MONDAY'); // or $day = Day::getByOrdinal(1); i.e. find by ISO-8601 numeric representation of day /** @var Day */ $today = Day::getToday();
use Hrevert\Day\Day; use Hrevert\Day\DayCollection; $days = new DayCollection([Day::SUNDAY(), Day::MONDAY()]); var_dump($days->contains(Day::SUNDAY())); // bool(true) var_dump($days->contains(Day::MONDAY())); // bool(true) $days->remove(Day::MONDAY()); var_dump($days->contains(Day::MONDAY())); // bool(false) $days->add(Day::MONDAY()); var_dump($days->contains(Day::MONDAY())); // bool(true)
Since Hrevert\Day\DayCollection
is just an extension of Doctrine\Common\Collections\ArrayCollection
, it should not be so difficult.
Using in <select> element
use Hrevert\Day\Day; echo '<select name="day">'; foreach (Day::getOptions() as $iso => $display) { echo '<option value="' . $iso . '">' . $display . '</option>'; } echo '</select>'; // on form submit /** @var Hrevert\Day\Day */ $day = Hrevert\Day\Day::get((int) $_POST['day']);