Skip to content

Kdyby/DateTimeProvider, formerly Kdyby/Clock

Pre-release
Pre-release
Compare
Choose a tag to compare
@Majkl578 Majkl578 released this 06 Jun 21:23
· 15 commits to master since this release
e8e7999

First pre-release version of the Kdyby/DateTimeProvider, formerly Kdyby/Clock.

Original interface has been split into four simpler interfaces:

  • Kdyby\DateTimeProvider\DateTimeProviderInterface
    • provides current date & time
    • returns a DateTimeImmutable instance
  • Kdyby\DateTimeProvider\DateProviderInterface
    • provides current date
    • returns a DateTimeImmutable instance without date (as in, time will always be 00:00:00.000000)
  • Kdyby\DateTimeProvider\TimeProviderInterface
    • provides current time
    • returns a DateInterval instance containing hour, minute, second and microsecond
  • Kdyby\DateTimeProvider\DateTimeZoneProviderInterface
    • provides current time zone
    • returns a DateTimeZone instance, matching the time zone of current time

Providers have been reworked and implement all the above interfaces (don't rely on it, it's an implementation detail).
There are three of them:

  • Kdyby\DateTimeProvider\Provider\ConstantProvider
    • given a DateTimeImmutable instance, it will aways return the same time for every future call
    • useful for HTTP requests or when time should be kept same
  • Kdyby\DateTimeProvider\Provider\CurrentProvider
    • whenever asked for, it will return a current time obtained from the system
    • useful i.e. for long-running proceses or when time precision is required
  • Kdyby\DateTimeProvider\Provider\MutableProvider
    • same as constant provider, but the time prototype could be explicitly changed
    • useful for testing

And there is also a helper factory:

  • Kdyby\DateTimeProvider\Provider\ConstantProviderFactory
    • given a date & time as an object or integer, returns a ConstantProvider