Time extends native DateTime class to fix shortcomings and defects, and provide more, simpler and safer getters and setters

1.2.0 2021-06-14 11:01 UTC

README

composer namespace: simplecomplex/time

Time

extends native \DateTime to fix shortcomings and defects, and provide more properties, getters and setters.

Features

  • enhanced timezone awareness
  • diff which works correctly with non-UTC timezones
  • safer formatting and modifying
  • is stringable (sic!), to ISO-8601
  • JSON serializes to string ISO-8601 with timezone marker
  • freezable
  • directly accessible time part properties
  • more, simpler and safer getters and setters

Related classes

TimeInterval

has the same properties as native \DateInterval plus signed relatives and totals, and works with non-UTC timezones.

Time::diffTime()

returns interval with actual differences.

Time::diffDstIgnorant()

returns an interval which ignores daylight saving time shift.
In everyday business you often don't want the difference between a date outside daylight saving time (DST)
and a date inside DST to be off by the DST offset.
That offset can be particularly nasty if either of the dates is at or close to midnight,
because then the days difference may get 1 off.

TimeSpan

It's main feature is to check overlap vs. another TimeSpan.

TimeImmutable

Is an immutable extending Time, not \DateTimeImmutable.

TimeLocal

Forces instances to be in local (default) timezone.

Requirements

  • PHP >=7.2 (64-bit)

Development requirements

Suggestions

MIT licensed

License and copyright. Explained.