Download the PHP package maba/clock without Composer
On this page you can find all versions of the php package maba/clock. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package clock
Clock PHP library
What's that?
-
ClockInterface
with single methodgetCurrentDateTime
(@returns \DateTime
)Why not just
new \DateTime()
? Because sometimes you need to adjust the time. Depending on global context (readnew \DateTime()
) is just wrong, as you cannot change the behaviour by dependency injection, and thus configuration.Few examples: 1) unit tests - you need to mock the clock 2) you need to alter the timezone and you don't want to change php.ini settings (see
TimeZonedClock
) - Classes in
Condition
namespace for checking and prioritizing time conditions.
Clock
RealTimeClock
- gives the real, unaltered \DateTime
TimeZonedClock
- gets time from another ClockInterface
(usually RealTimeClock
) and sets pre-configured timezone.
Condition
TimeCondition
- POJO/Value object, which contains available time restrictions:
- From time, in seconds, inclusive
- Until time, in seconds, exclusive. Can overlap 00:00 with from time
- Weekday.
0
(Sunday) to6
(Saturday) - Day of month (
1
to31
) - Month (
1
to12
). Can be specified only with day of month - Year (for example
2015
). Can be specified only with month and day of month
You can implement TimeConditionInterface
and use this library with your own objects, for example any Doctrine Entity.
ConditionPriorityResolver
- gives priority for any TimeConditionInterface
.
Larger priority means that condition is more concrete, thus should "win" if choosing between several.
TimeConditionChecker
- returns whether given TimeConditionInterface
matches given \DateTime
CurrentTimeConditionChecker
- returns whether given TimeConditionInterface
matches current time
ConditionalValueResolver
- resolves most concrete time condition matching current time and gives related value.
Example: