yohang/CalendR — pull request #33 by mynameiszanders (2014-04-13 23:16:09+00:00)
Title: Add Support for Time Periods

### Time Periods
- Created the classes required for the time periods Hour, Minute and Second. I can't think of any situation where seconds would actually be needed, but might as well have the complete set.
- Update the `Day` period class to extend the `\Iterator` interface and provides each hour of the day upon iteration. Iterating over hours gives minutes and minutes gives seconds, as would be expected.
- Update the `Calendar` and `Factory` classes to add new `createPeriod()` helper methods. They are also now defined in the `FactoryInterface`.

### Strict Dates
- Create new option called `strict_dates` (default: false).
- Update `isValid()` static methods, return false if the supplied `\DateTime` object is not at the very beginning of the date/time period.
- If `strict_dates` is true, then a `NotAPeriod` exception is thrown from the constructor of the chosen period class when `isValid()` returns false.
- If `strict_dates` is false, then do not validate the `\DateTime` object; automatically set the begin date to the beginning of the date/time period.
- Create helper methods `getStrictDates()` and `setStrictDates()` in the `Calendar` and `Factory` classes (has **not** been added to the `FactoryInterface`).

### Strict Dates: Example

```php
setStrictDates(true);
$month = new \CalendR\Period\Month($date, $factory);
// A NotAMonth exception will be thrown.

$factory->setStrictDates(false);
$month = new \CalendR\Period\Month($date, $factory);
// The date returned from $month->getBegin() has been set to '2014-05-01 00:00:00'.
```

### Unit Tests

All changes have 100% code coverage with unit tests which pass on Travis CI.