Skip to content
Day of week library
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
tests
.gitignore
.travis.yml
LICENSE
README.md
composer.json
phpunit.xml

README.md

day-of-week

Master Branch Build Status Latest Stable Version Total Downloads

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']);
You can’t perform that action at this time.