DateFactory
class DateFactory
Single point of creation for all date objects in the framework.
Every date Chappy creates should come from this class so that the application timezone, locale, and choice of mutable or immutable Carbon are applied consistently. Because "now" always comes from Carbon, Carbon::setTestNow() freezes time for everything built on this factory.
Properties
| static protected CarbonInterface> | $class | The Carbon class used to build new instances. |
Methods
Sets the Carbon class used for all new instances.
Sets the Carbon class from the DATE_CLASS environment value.
Returns the Carbon class currently in use.
Returns the current time.
Returns midnight of the current day.
Normalizes any supported input into a Carbon instance in the application timezone.
Applies framework-wide settings to an instance.
Returns the application timezone.
Details
at line 36
static void
use(string $class)
Sets the Carbon class used for all new instances.
Call once during bootstrap, for example: DateFactory::use(CarbonImmutable::class);
at line 49
static void
boot()
Sets the Carbon class from the DATE_CLASS environment value.
Accepts "immutable" or "mutable". Defaults to mutable.
at line 59
static string
getClass()
Returns the Carbon class currently in use.
at line 69
static CarbonInterface
now(string|null $timezone = null)
Returns the current time.
at line 79
static CarbonInterface
today(string|null $timezone = null)
Returns midnight of the current day.
at line 96
static CarbonInterface
parse(mixed $value, string $fromTimezone = 'UTC')
Normalizes any supported input into a Carbon instance in the application timezone.
Accepts:
- DateTimeInterface instances
- Integer Unix timestamps (always treated as UTC)
- Date strings, interpreted in $fromTimezone
at line 112
static protected CarbonInterface
configure(CarbonInterface $date)
Applies framework-wide settings to an instance.
at line 121
static string
timezone()
Returns the application timezone.