### Initialize Carbon in PHP Source: https://github.com/briannesbitt/carbon/blob/master/readme.md Basic usage examples for Carbon after installation, showing how to load the library and display the current time. ```php add('month', 1) ); // Exclude start and end dates $period = new CarbonPeriod( '2024-01-01', '1 day', '2024-01-07', CarbonPeriod::EXCLUDE_START_DATE | CarbonPeriod::EXCLUDE_END_DATE ); ``` -------------------------------- ### Set CarbonPeriod start date Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Configures the beginning of the period using a date string. ```php $period = new CarbonPeriod(); $period->setStartDate('2024-01-01'); ``` -------------------------------- ### CarbonPeriod recurrences() Usage Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Example of creating a period with a specific count of recurrences. ```php // 10 daily occurrences starting today $period = CarbonPeriod::recurrences('2024-01-01', 10, '1 day'); ``` -------------------------------- ### setStartDate(DateTimeInterface|string $date) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Sets the start date of the period. ```APIDOC ### Method `public function setStartDate(DateTimeInterface|string $date): static` ### Description Sets the start date of the period. ### Example ```php $period = new CarbonPeriod(); $period->setStartDate('2024-01-01'); ``` ``` -------------------------------- ### CarbonPeriod until() Usage Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Example of creating a period ending on a specific date. ```php $period = CarbonPeriod::until('2024-12-31', '1 week'); ``` -------------------------------- ### setDates(DateTimeInterface|string $start, DateTimeInterface|string $end) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Sets both start and end dates at once. ```APIDOC ### Method `public function setDates(DateTimeInterface|string $start, DateTimeInterface|string $end): static` ### Description Sets both start and end dates at once. ``` -------------------------------- ### CarbonPeriod createFromIso() Usage Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Example of creating a period using an ISO 8601 recurrence rule. ```php // Start/2024-01-31/P1D/End (daily for one month) $period = CarbonPeriod::createFromIso('R10/2024-01-01/P1D'); ``` -------------------------------- ### CarbonPeriod between() Usage Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Examples of using the between() method to define a range. ```php $period = CarbonPeriod::between('2024-01-01', '2024-01-31'); $period = CarbonPeriod::between( Carbon::now(), Carbon::now()->add('month', 3), CarbonInterval::weeks(1) ); ``` -------------------------------- ### Handle ImmutableException Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-immutable.md Example of catching an exception when attempting to modify an immutable object. ```php try { $immutable->modify('+1 day'); } catch (ImmutableException $e) { echo $e->getMessage(); } ``` -------------------------------- ### Get First Day of Month in Year Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Use ofTheYear to retrieve the first day of the month for a specific year or Carbon instance. ```php public function ofTheYear(CarbonImmutable|int|null $now = null): CarbonImmutable ``` ```php $june2024 = Month::June->ofTheYear(2024); $june2024 = Month::June->ofTheYear(Carbon::parse('2024-12-25')); $juneThisYear = Month::June->ofTheYear(); // Current year ``` -------------------------------- ### Get ISO 8601 duration string Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Returns the interval as an ISO 8601 duration specification string. ```php $interval = CarbonInterval::create(years: 1, months: 2, days: 3, hours: 4, minutes: 5); echo $interval->spec(); // "P1Y2M3DT4H5M" ``` -------------------------------- ### Update Dependencies Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Update project dependencies using Composer. Use the local phar or the globally installed composer. ```shell ./composer.phar update ``` ```shell composer update ``` -------------------------------- ### CarbonPeriod since() Method Definition Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Signature for the static factory method to create a period starting from a specific date until now. ```php public static function since( DateTimeInterface|string $date, DateInterval|string|int|null $interval = null ): static ``` -------------------------------- ### Creating Carbon Instances Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Demonstrates various ways to instantiate Carbon objects using current time, date strings, timezones, or existing DateTime objects. ```php use Carbon\Carbon; // Create instance for current time $now = new Carbon(); // Create from string $date = new Carbon('2024-01-15 14:30:00'); // Create with timezone $tokyo = new Carbon('2024-01-15', 'Asia/Tokyo'); // Create from DateTime $dt = new DateTime('2024-01-15'); $carbon = new Carbon($dt); ``` -------------------------------- ### now() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance for the current time, using factory defaults. ```APIDOC ## now(DateTimeZone|string|int|null $tz = null) ### Description Create a Carbon instance for the current time, using factory defaults. ### Parameters - **$tz** (DateTimeZone|string|int|null) - Optional - The timezone to use for the instance. ### Returns - **Carbon** - A new Carbon instance. ``` -------------------------------- ### make($date = null, $tz = null) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates an instance from a given date. ```APIDOC ## make($date = null, $tz = null) ### Description Creates an instance from the provided date input. ### Signature `public function make($date = null, $tz = null): CarbonImmutable` ``` -------------------------------- ### Initialize Factory Instance Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Create a new Factory instance, optionally specifying the Carbon class name. ```php use Carbon\Factory; $factory = new Factory(); $factory = new Factory(Carbon::class); ``` -------------------------------- ### CarbonPeriod::until() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Creates a period starting from now until a specific date. ```APIDOC ## CarbonPeriod::until ### Description Create a period from now to a date. ### Parameters - **date** (DateTimeInterface, string) - Required - End date - **interval** (DateInterval, string, int, null) - Optional - Interval between iterations ``` -------------------------------- ### CarbonPeriod::since() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Creates a period starting from a specific date until now. ```APIDOC ## CarbonPeriod::since ### Description Create a period from a date to now. ### Parameters - **date** (DateTimeInterface, string) - Required - Start date - **interval** (DateInterval, string, int, null) - Optional - Interval between iterations ``` -------------------------------- ### Configure String Format Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Set the default format used when converting instances to strings. ```php $factory->toStringFormat('Y-m-d H:i:s'); // ISO format $date = $factory->now(); echo $date; // Uses the configured format ``` -------------------------------- ### Retrieve timezone name Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Get the string identifier for the timezone. ```php $tz = new CarbonTimeZone('America/New_York'); echo $tz->getName(); // "America/New_York" ``` -------------------------------- ### Initialize Carbon Factory Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Create a new instance of the Factory class to manage global defaults. ```php use Carbon\Factory; use Carbon\CarbonTimeZone; $factory = new Factory(); ``` -------------------------------- ### today() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance for today at midnight. ```APIDOC ## today(DateTimeZone|string|int|null $tz = null) ### Description Create a Carbon instance for today at midnight. ### Parameters - **$tz** (DateTimeZone|string|int|null) - Optional - The timezone to use for the instance. ### Returns - **Carbon** - A new Carbon instance. ``` -------------------------------- ### Format Dates with Locale-Specific Settings Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Demonstrates dynamic locale switching for date formatting using the isoFormat method. ```php function formatDate($date, $locale = 'en') { return Carbon::parse($date)->locale($locale)->isoFormat('LLLL'); } echo formatDate('2024-06-15', 'fr_FR'); // French format echo formatDate('2024-06-15', 'de_DE'); // German format ``` -------------------------------- ### make() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance from any datetime value. ```APIDOC ## make($date = null, $tz = null) ### Description Create a Carbon instance from any datetime value. ### Parameters - **$date** (mixed) - Optional - The date value to convert. - **$tz** (mixed) - Optional - The timezone to use. ### Returns - **Carbon** - A new Carbon instance. ``` -------------------------------- ### Inheritance Path Visualization Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/errors.md Shows the hierarchy of Carbon exceptions. ```text Exception (PHP) ← Carbon\Exceptions\Exception ← All specific Carbon exceptions ``` -------------------------------- ### Get Plural Unit Form Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Retrieve the plural form of a unit, optionally localized. ```php echo Unit::Day->plural(); // 'days' echo Unit::Day->plural('fr_FR'); // 'jours' ``` -------------------------------- ### Carbon::create() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Create a Carbon instance from individual date and time components. ```APIDOC ## Carbon::create() ### Description Create a Carbon instance from individual date/time components. Returns null if the date is invalid. ### Parameters - **year** (int) - Optional - Year; 0 means current year - **month** (int) - Optional - Month (1-12) - **day** (int) - Optional - Day of month (1-31) - **hour** (int) - Optional - Hour (0-23) - **minute** (int) - Optional - Minute (0-59) - **second** (int) - Optional - Second (0-59) - **timezone** (DateTimeZone, string, int, null) - Optional - Timezone ### Example ```php $date = Carbon::create(2024, 6, 15, 14, 30, 45); $date = Carbon::create(2024, 12, 25); ``` ``` -------------------------------- ### Get Singular Unit Form Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Retrieve the singular form of a unit, optionally localized. ```php echo Unit::Day->singular(); // 'day' echo Unit::Day->singular('fr_FR'); // 'jour' ``` -------------------------------- ### now(DateTimeZone|string|int|null $tz = null) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates an instance for the current time. ```APIDOC ## now(DateTimeZone|string|int|null $tz = null) ### Description Creates an instance for the current time using the factory's configured defaults. ### Signature `public function now(DateTimeZone|string|int|null $tz = null): CarbonImmutable` ``` -------------------------------- ### Get Month in Locale Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Use locale to retrieve the month representation in a specific locale. ```php public function locale(string $locale, ?CarbonImmutable $now = null): CarbonImmutable ``` ```php $june = Month::June->locale('fr_FR'); ``` -------------------------------- ### Basic Carbon Usage Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/README.md Demonstrates common operations including instantiation, parsing, modification, formatting, comparison, and human-readable differences. ```php use Carbon\Carbon; // Current time $now = Carbon::now(); // Parse string $date = Carbon::parse('2024-06-15'); // Modify $future = Carbon::now()->addDays(7)->setHour(14); // Format echo $now->format('Y-m-d H:i:s'); echo $now->toDateString(); echo $now->isoFormat('LLLL'); // Long locale-aware format // Compare if ($date->isPast()) { echo 'Date is in the past'; } // Difference $days = $date->diffInDays(now: true); echo $date->diffForHumans(); // "5 days ago" ``` -------------------------------- ### Get Region-Specific Timezone Name Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Retrieves the timezone name associated with a specific region. ```php $tz = new CarbonTimeZone('America/New_York'); echo $tz->toRegionTimeZone('US'); // "America/New_York" ``` -------------------------------- ### Get human-readable difference with diffForHumans() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Returns a localized, human-readable string representing the time difference. ```php public function diffForHumans($other = null, $syntax = null, $short = false, $parts = 1, $options = null): string ``` ```php echo Carbon::now()->subMinutes(5)->diffForHumans(); // Output: "5 minutes ago" echo Carbon::now()->subMinutes(5)->locale('fr_FR')->diffForHumans(); // Output: "il y a 5 minutes" ``` -------------------------------- ### Create time from components with Carbon::createFromTime() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Creates a Carbon instance from time components, defaulting the date to today. ```php $time = Carbon::createFromTime(14, 30, 45); ``` -------------------------------- ### Get Next Weekday in Locale Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Calculate the next occurrence of a weekday while applying a specific locale. ```php $nextMonday = WeekDay::Monday->locale('fr_FR'); ``` -------------------------------- ### Configure custom string format Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Define a default string format for instances created by the factory. ```php $factory = new Factory(); $factory->toStringFormat('l, F j, Y'); // "Monday, June 15, 2024" $date = $factory->now(); echo $date; // Formatted as configured ``` -------------------------------- ### Create instance from value Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance from various datetime inputs. ```php public function make($date = null, $tz = null): Carbon ``` ```php $date = $factory->make('2024-06-15'); $date = $factory->make(1718462400); $date = $factory->make(new DateTime()); ``` -------------------------------- ### Get Abbreviated Name Method Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Signature for retrieving the abbreviated name of a timezone for a specific date. ```php public static function getAbbreviatedName( DateTimeInterface $date, DateTimeZone|string|int|null $tz = null ): string ``` -------------------------------- ### Retrieve UTC offset Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Get the offset from UTC in seconds, optionally calculated for a specific date. ```php $tz = new CarbonTimeZone('America/New_York'); $offset = $tz->getOffset(); echo $offset / 3600; // Hours from UTC ``` -------------------------------- ### Create today instance Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance representing today at midnight. ```php public function today(DateTimeZone|string|int|null $tz = null): Carbon ``` -------------------------------- ### Configure Per-Module Carbon Instances Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Creates isolated Factory instances to maintain specific locale and timezone settings for individual features. ```php // For specific feature $reportFactory = new Factory(); $reportFactory->setLocale('en_US'); $reportFactory->setTimeZone('UTC'); $reportDate = $reportFactory->now(); ``` -------------------------------- ### Create from Unix timestamp with Carbon::createFromTimestamp() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Instantiates a Carbon object from a given Unix timestamp. ```php $date = Carbon::createFromTimestamp(1718462400); ``` -------------------------------- ### Handle InvalidPeriodDateException in PHP Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/errors.md Catch exceptions when period start or end dates do not meet required constraints. ```php try { $period = new CarbonPeriod('invalid-start', '1 day', '2024-12-31'); } catch (InvalidPeriodDateException $e) { echo 'Invalid period date: ' . $e->getMessage(); } ``` -------------------------------- ### Create date from components with Carbon::createFromDate() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Creates a Carbon instance from date components, defaulting the time to midnight. ```php $date = Carbon::createFromDate(2024, 6, 15); ``` -------------------------------- ### Get maximum representable time Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-immutable.md Returns a Carbon instance representing the maximum possible date-time value. ```php $maxTime = CarbonImmutable::endOfTime(); ``` -------------------------------- ### today(DateTimeZone|string|int|null $tz = null) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates an instance for today. ```APIDOC ## today(DateTimeZone|string|int|null $tz = null) ### Description Creates an instance for today using the factory's configured defaults. ### Signature `public function today(DateTimeZone|string|int|null $tz = null): CarbonImmutable` ``` -------------------------------- ### Integrate Carbon with Environment Configuration Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Maps environment variables to Carbon Factory settings for flexible application-wide configuration. ```php // config/carbon.php use Carbon\Factory; return [ 'locale' => env('APP_LOCALE', 'en_US'), 'timezone' => env('APP_TIMEZONE', 'UTC'), 'weekends' => env('APP_WEEKENDS', [0, 6]), 'strict_mode' => env('CARBON_STRICT', false), ]; // Usage $factory = new Factory(); $config = config('carbon'); $factory->setLocale($config['locale']); $factory->setTimeZone($config['timezone']); $factory->setWeekendDays($config['weekends']); if ($config['strict_mode']) { $factory->useStrictMode(); } ``` -------------------------------- ### Creating intervals from components Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Build an interval by specifying individual time units as arguments. ```php $interval = CarbonInterval::create( years: 1, months: 2, days: 3, hours: 4, minutes: 5, seconds: 6 ); ``` -------------------------------- ### Get range as array Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Converts the period into an array of dates, optionally using date strings as keys. ```php $period = new CarbonPeriod('2024-01-01', '1 day', '2024-01-07'); $dates = iterator_to_array($period); // Or with keys $dates = array_combine( array_map(fn($d) => $d->toDateString(), $period), iterator_to_array($period) ); ``` -------------------------------- ### Run Unit Tests Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Execute the project's unit tests using PHPUnit to ensure code quality and stability. ```shell ./vendor/bin/phpunit ``` -------------------------------- ### Working with Timezones Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Basic instantiation of a CarbonTimeZone and applying it to a Carbon instance. ```php $tz = new CarbonTimeZone('America/New_York'); $date = Carbon::now($tz); ``` -------------------------------- ### Configure global factory defaults Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Set locale, timezone, and weekend days to be applied to all instances created by the factory. ```php use Carbon\Factory; $factory = new Factory(); $factory->setLocale('de_DE'); $factory->setTimeZone('Europe/Berlin'); $factory->setWeekendDays([5, 6]); // All instances use these defaults $now = $factory->now(); $date = $factory->make('2024-06-15'); ``` -------------------------------- ### Retrieve abbreviated timezone name Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Get the abbreviated name, such as EST or EDT, based on the provided date or current time. ```php $tz = new CarbonTimeZone('America/New_York'); echo $tz->getAbbreviatedName(); // "EST" or "EDT" depending on DST ``` -------------------------------- ### Iterating CarbonPeriod Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/README.md Shows how to iterate over a range of dates using CarbonPeriod. ```php use Carbon\CarbonPeriod; $period = new CarbonPeriod('2024-01-01', '1 day', '2024-01-31'); foreach ($period as $date) { echo $date->format('Y-m-d'); } ``` -------------------------------- ### Create region-specific factories Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Instantiate multiple factories with different configurations to handle regional requirements. ```php $usFactory = new Factory(); $usFactory->setLocale('en_US'); $usFactory->setTimeZone('America/New_York'); $jpFactory = new Factory(); $jpFactory->setLocale('ja_JP'); $jpFactory->setTimeZone('Asia/Tokyo'); $usDate = $usFactory->now(); $jpDate = $jpFactory->now(); ``` -------------------------------- ### Configure FactoryImmutable Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Initializes an immutable factory instance with specific locale and timezone settings. ```php use Carbon\FactoryImmutable; $factory = new FactoryImmutable(); $factory->setLocale('de_DE'); $factory->setTimeZone('Europe/Berlin'); $date = $factory->now(); // CarbonImmutable instance ``` -------------------------------- ### Create current time with Carbon::now() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Generates a Carbon instance for the current date and time, optionally specifying a timezone. ```php $now = Carbon::now(); $nowInTokyo = Carbon::now('Asia/Tokyo'); ``` -------------------------------- ### Bootstrap Carbon Application Defaults Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Sets global locale, timezone, weekend days, and custom macros during application initialization. ```php // app/config/carbon.php or bootstrap use Carbon\Factory; use Carbon\Month; $factory = new Factory(); // Set application defaults $factory->setLocale('fr_FR'); $factory->setTimeZone('Europe/Paris'); $factory->setWeekendDays([5, 6]); // Friday-Saturday (European) // Add business domain macros $factory->macro('isQuarterEnd', function() { return in_array($this->month, [3, 6, 9, 12]) && $this->day == $this->daysInMonth; }); // Global test configuration if (app()->environment('testing')) { Carbon::setTestNow(Carbon::parse('2024-01-01')); } ``` -------------------------------- ### Create and modify complex intervals Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Demonstrates creating an interval with multiple units and chaining modification methods. ```php $interval = CarbonInterval::create( years: 1, months: 3, days: 15, hours: 6, minutes: 30 ); $interval->add('weeks', 2)->add('hours', 2); ``` -------------------------------- ### Extend factory with mixins Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Use a class to define multiple methods and mix them into the factory instance. ```php class DateMixin { public function isPublicHoliday() { $holidays = [ '01-01', // New Year '12-25', // Christmas ]; return in_array($this->format('m-d'), $holidays); } public function daysTillChristmas() { return $this->diffInDays( $this->setMonth(12)->setDay(25) ); } } $factory = new Factory(); $factory->mixin(new DateMixin()); $date = $factory->now(); $date->isPublicHoliday(); $date->daysTillChristmas(); ``` -------------------------------- ### Create current time instance Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Creates a Carbon instance for the current time using factory defaults. ```php public function now(DateTimeZone|string|int|null $tz = null): Carbon ``` ```php $factory = new Factory(); $factory->setTimeZone('Asia/Tokyo'); $factory->setLocale('ja_JP'); $date = $factory->now(); // Created with Tokyo timezone and Japanese locale ``` -------------------------------- ### Factory Configuration Methods Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Methods available on the Carbon\Factory class to configure global date/time behaviors. ```APIDOC ## Factory::setTimeZone ### Description Sets the default timezone for all instances created by the factory. ### Parameters - **tz** (DateTimeZone, string, int, null) - Optional - Timezone name, UTC offset (seconds), or DateTimeZone object. ## Factory::setLocale ### Description Sets the default locale for all instances created by the factory. ### Parameters - **locale** (string) - Required - BCP 47 locale code (e.g., 'en_US', 'fr_FR'). ## Factory::setWeekendDays ### Description Defines which days of the week are considered weekends. ### Parameters - **days** (array) - Required - Array of day numbers (0=Sunday through 6=Saturday). ## Factory::setYearsOverflow / setMonthsOverflow ### Description Configures how date overflows are handled when adding years or months. ### Parameters - **overflow** (OverflowMode, bool, null) - Optional - Defines overflow behavior (true/false or OverflowMode enum). ## Factory::toStringFormat ### Description Sets the default PHP date format string used by the __toString() method. ### Parameters - **format** (string) - Required - PHP date format string. ## Factory::setStrict / useStrictMode ### Description Enables or disables strict validation of date values. ### Parameters - **strict** (bool) - Optional - Whether to enable strict mode (default: true). ## Factory::setTranslator ### Description Sets a custom translation provider for localization. ### Parameters - **translator** (TranslatorInterface) - Required - The translation provider instance. ``` -------------------------------- ### Create instance via factory method Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Use the static instance method to create or cast a value into a CarbonTimeZone object. ```php $tz = CarbonTimeZone::instance('Asia/Tokyo'); $tz = CarbonTimeZone::instance(new DateTimeZone('Europe/London')); ``` -------------------------------- ### Configure String Format Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Set the default PHP date format string for __toString() conversions. ```php $factory->toStringFormat('Y-m-d H:i:s'); $date = $factory->now(); echo $date; // "2024-06-15 14:30:45" ``` -------------------------------- ### copy() / clone() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Creates a copy or clone of the current Carbon instance. ```APIDOC ## copy() ### Description Create a copy of the instance. ## clone() ### Description Create a clone (synonym for copy). ``` -------------------------------- ### Clone Carbon Repository Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Clone the Carbon project from GitHub and set up the upstream remote for future synchronization. ```shell git clone https://github.com//carbon.git cd Carbon git remote add upstream https://github.com/CarbonPHP/carbon.git ``` -------------------------------- ### CarbonTimeZone Interoperability Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Demonstrates using CarbonTimeZone where a standard DateTimeZone is expected. ```php use Carbon\CarbonTimeZone; use DateTime; $tz = new CarbonTimeZone('Asia/Tokyo'); $dt = new DateTime('now', $tz); // Works with DateTime $carbon = Carbon::now($tz); // Works with Carbon ``` -------------------------------- ### Mock Current Time for Testing Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/README.md Use setTestNow to freeze time during tests and reset it afterwards to restore real-time behavior. ```php use Carbon\Carbon; // Set test time Carbon::setTestNow('2024-06-15 14:30:45'); $now = Carbon::now(); assert($now->toDateTimeString() === '2024-06-15 14:30:45'); // Reset to real time Carbon::setTestNow(); ``` -------------------------------- ### Calculate difference in minutes with diffInMinutes() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Returns the difference in minutes between the instance and another date. ```php public function diffInMinutes($date = null, bool $absolute = false): float ``` -------------------------------- ### Format dates using isoFormat() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Format dates using ISO tokens with optional locale support. ```php echo $date->isoFormat('YYYY-MM-DD'); echo $date->isoFormat('LLLL'); // 'Tuesday, June 15, 2024 2:51 PM' echo $date->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51' ``` -------------------------------- ### Iterate over days Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Creates a period spanning one month with daily intervals. ```php $period = new CarbonPeriod('2024-01-01', '1 day', '2024-01-31'); foreach ($period as $date) { echo $date->format('Y-m-d'); } ``` -------------------------------- ### Configure Carbon Factory with Dependency Injection Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Injects a Carbon Factory instance into a class and configures the factory within a container with specific locale and timezone settings. ```php use Carbon\Factory; class ReportGenerator { public function __construct(private Factory $factory) {} public function generate() { $date = $this->factory->now(); // Use date in report } } // Container configuration $container->bind(Factory::class, function() { $factory = new Factory(); $factory->setLocale('en_GB'); $factory->setTimeZone('Europe/London'); return $factory; }); ``` -------------------------------- ### Initialize FactoryImmutable Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Create a new instance of the FactoryImmutable class to manage immutable Carbon instances. ```php use Carbon\FactoryImmutable; $factory = new FactoryImmutable(); ``` -------------------------------- ### Configure Carbon Strict Mode Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Enables strict mode to throw an UnknownGetterException when accessing undefined properties. ```php // Strict mode - throw on unknown properties $factory->useStrictMode(); try { $date = Carbon::now(); echo $date->unknownProp; } catch (UnknownGetterException $e) { echo 'Unknown property accessed'; } ``` -------------------------------- ### Working with CarbonInterval Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/README.md Demonstrates creating and modifying time intervals for use with date objects. ```php use Carbon\CarbonInterval; $interval = CarbonInterval::days(5); $interval->add('hours', 3); // Use with dates $date = Carbon::now()->add($interval); ``` -------------------------------- ### Add custom methods via macros Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Extend factory instances with custom logic using the macro method. ```php $factory = new Factory(); $factory->macro('nextBusinessDay', function() { $date = $this->copy(); while ($date->isWeekend()) { $date = $date->addDay(); } return $date; }); $date = $factory->now(); $businessDay = $date->nextBusinessDay(); ``` -------------------------------- ### Instantiate CarbonTimeZone Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Create a new CarbonTimeZone instance using a name, UTC offset in seconds, or an existing DateTimeZone object. ```php use Carbon\CarbonTimeZone; // By name $tz = new CarbonTimeZone('UTC'); $tz = new CarbonTimeZone('America/New_York'); // By offset (in seconds) $tz = new CarbonTimeZone(3600); // UTC+1 // From DateTimeZone $dtz = new DateTimeZone('Europe/London'); $tz = new CarbonTimeZone($dtz); // Null defaults to UTC $tz = new CarbonTimeZone(); ``` -------------------------------- ### Create date from components with Carbon::create() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Constructs a Carbon instance using individual year, month, day, hour, minute, and second values. Returns null if the provided date is invalid. ```php $date = Carbon::create(2024, 6, 15, 14, 30, 45); $date = Carbon::create(2024, 12, 25); // Christmas ``` -------------------------------- ### Reset Factory Configurations Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Reset various factory settings back to their default values. ```php $factory->resetTranslations(); $factory->resetToStringFormat(); $factory->resetYearsOverflow(); $factory->resetMonthsOverflow(); $factory->resetMacros(); ``` -------------------------------- ### Repetition Methods (yearly, monthly, weekly, daily, hourly, minutely) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Methods to set the interval to specific time units. ```APIDOC ### Methods - `yearly()`: Set interval to yearly (P1Y). - `monthly()`: Set interval to monthly (P1M). - `weekly()`: Set interval to weekly (P1W). - `daily()`: Set interval to daily (P1D). - `hourly()`: Set interval to hourly (PT1H). - `minutely()`: Set interval to minutely (PT1M). ### Example ```php $period->yearly(); ``` ``` -------------------------------- ### Register Mixins Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Extends Carbon functionality by registering methods from a dedicated class. ```php class DateMixin { public function isPublicHoliday() { $holidays = ['12-25', '01-01']; return in_array($this->format('m-d'), $holidays); } public function daysSinceLastNYE() { return $this->diffInDays($this->setMonth(1)->setDay(1)); } } $factory = new Factory(); $factory->mixin(new DateMixin()); $date = $factory->now(); $date->isPublicHoliday(); $date->daysSinceLastNYE(); ``` -------------------------------- ### __toString() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Converts the instance to its default string representation. ```APIDOC ## __toString() ### Description Convert to default string format (toDateTimeString by default). ### Example ```php echo $date; // calls __toString() ``` ``` -------------------------------- ### Manipulate and Format Dates with Carbon Source: https://github.com/briannesbitt/carbon/blob/master/readme.md Demonstrates common operations such as creating dates, timezones, comparisons, localization, and diffing. ```php toDateTimeString()); printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver')); //implicit __toString() $tomorrow = Carbon::now()->addDay(); $lastWeek = Carbon::now()->subWeek(); $officialDate = Carbon::now()->toRfc2822String(); $howOldAmI = Carbon::createFromDate(1975, 5, 21)->age; $noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London'); $internetWillBlowUpOn = Carbon::create(2038, 01, 19, 3, 14, 7, 'GMT'); // Don't really want this to happen so mock now Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1)); // comparisons are always done in UTC if (Carbon::now()->gte($internetWillBlowUpOn)) { die(); } // Phew! Return to normal behaviour Carbon::setTestNow(); if (Carbon::now()->isWeekend()) { echo 'Party!'; } // Over 200 languages (and over 500 regional variants) supported: echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago' echo Carbon::now()->subMinutes(2)->locale('zh_CN')->diffForHumans(); // '2分钟前' echo Carbon::parse('2019-07-23 14:51')->isoFormat('LLLL'); // 'Tuesday, July 23, 2019 2:51 PM' echo Carbon::parse('2019-07-23 14:51')->locale('fr_FR')->isoFormat('LLLL'); // 'mardi 23 juillet 2019 14:51' // ... but also does 'from now', 'after' and 'before' // rolling up to seconds, minutes, hours, days, months, years $daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays(); // something such as: // 19817.6771 $daysUntilInternetBlowUp = $internetWillBlowUpOn->diffInDays(); // Negative value since it's in the future: // -5037.4560 // Without parameter, difference is calculated from now, but doing $a->diff($b) // it will count time from $a to $b. Carbon::createFromTimestamp(0)->diffInDays($internetWillBlowUpOn); // 24855.1348 ``` -------------------------------- ### Factory Constructor Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Initializes a new Factory instance for creating Carbon objects. ```APIDOC ## public function __construct(string $className = Carbon::class) ### Description Creates a new Factory instance to manage default configurations for Carbon objects. ### Parameters - **className** (string) - Optional - The class name to create instances of. Defaults to Carbon::class. ``` -------------------------------- ### Sync Local Repository with Upstream Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Fetch changes from the upstream remote and rebase your local branch to keep it up-to-date. ```shell git fetch origin git rebase origin/master ``` -------------------------------- ### Apply OverflowMode to Date Arithmetic Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Demonstrates how to use PRESERVE, CLIP, and ROLL modes when adding months to a date. ```php use Carbon\OverflowMode; use Carbon\Carbon; $date = Carbon::create(2024, 1, 31); // January 31 // PRESERVE: Keep day 31, if month has fewer days, use last day $preserved = $date->add('month', 1, OverflowMode::PRESERVE); // Feb 29 (leap year) // CLIP: Clip to last day of month $clipped = $date->add('month', 1, OverflowMode::CLIP); // Feb 29 // ROLL: Roll over to next month $rolled = $date->add('month', 1, OverflowMode::ROLL); // Mar 2 ``` -------------------------------- ### Calculate difference in months with diffInMonths() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Returns the difference in months between the instance and another date. ```php public function diffInMonths($date = null, bool $absolute = false, bool $utc = false): float ``` -------------------------------- ### Creating intervals from custom formats Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Parse a string into an interval using a format pattern containing percentage-prefixed components. ```php $interval = CarbonInterval::createFromFormat('%h hours %i minutes', '5 hours 30 minutes'); ``` -------------------------------- ### Carbon::now() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Returns the current date and time instance. ```APIDOC ## Carbon::now() ### Description Returns the current date and time. ### Parameters - **timezone** (DateTimeZone, string, int, null) - Optional - Timezone for the returned instance ### Example ```php $now = Carbon::now(); $nowInTokyo = Carbon::now('Asia/Tokyo'); ``` ``` -------------------------------- ### Configure Git User Information Source: https://github.com/briannesbitt/carbon/blob/master/contributing.md Set your global Git user name and email. Remove the --global flag to set it only for the current repository. ```shell git config --global user.name "Your Name" git config --global user.email "your.email.address@example.com" ``` -------------------------------- ### Configure Locale Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Set the default BCP 47 locale code for date formatting. ```php $factory->setLocale('fr_FR'); // All instances use French locale $date = $factory->now(); echo $date->isoFormat('LLLL'); // Friday, June 15, 2024 at 2:51 PM ``` -------------------------------- ### Iterate over weeks Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Creates a period spanning three months with weekly intervals. ```php $period = new CarbonPeriod( Carbon::now(), CarbonInterval::weeks(1), Carbon::now()->add('months', 3) ); foreach ($period as $date) { echo $date->format('Y-m-d'); } ``` -------------------------------- ### Parse ISO format with Carbon::createFromIsoFormat() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Parses a date string using ISO formatting, with support for specific locales. ```php $date = Carbon::createFromIsoFormat('YYYY-MM-DD', '2024-06-15'); $date = Carbon::createFromIsoFormat('LLLL', 'Tuesday, June 15, 2024 2:51 PM', locale: 'fr_FR'); ``` -------------------------------- ### Query Methods Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Methods to inspect the state, configuration, and properties of the CarbonPeriod instance. ```APIDOC ## Query Methods ### isStarted() - **Signature**: `public function isStarted(): bool` - **Description**: Check if iteration has started. ### isFinished() - **Signature**: `public function isFinished(): bool` - **Description**: Check if iteration has completed. ### isEndExcluded() - **Signature**: `public function isEndExcluded(): bool` - **Description**: Check if end date is excluded. ### isStartExcluded() - **Signature**: `public function isStartExcluded(): bool` - **Description**: Check if start date is excluded. ### getStartDate() - **Signature**: `public function getStartDate(): Carbon` - **Description**: Get the start date as Carbon instance. ### getEndDate() - **Signature**: `public function getEndDate(): Carbon` - **Description**: Get the end date as Carbon instance. ### getDateInterval() - **Signature**: `public function getDateInterval(): CarbonInterval` - **Description**: Get the interval. ### count() - **Signature**: `public function count(): int` - **Description**: Get the number of dates in the period. ``` -------------------------------- ### Constructing CarbonInterval instances Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Initialize intervals using ISO 8601 duration strings or existing DateInterval objects. ```php use Carbon\CarbonInterval; // Using ISO 8601 spec $interval = new CarbonInterval('P1Y2M3DT4H5M6S'); // 1 year, 2 months, 3 days, 4 hours, 5 minutes, 6 seconds // 7 days $week = new CarbonInterval('P7D'); // 5 minutes $fiveMin = new CarbonInterval('PT5M'); // From DateInterval $di = new DateInterval('P1D'); $ci = new CarbonInterval($di); ``` -------------------------------- ### Calculate difference in days with diffInDays() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Returns the difference in days between the instance and another date. ```php public function diffInDays($date = null, bool $absolute = false, bool $utc = false): float ``` ```php $days = $date1->diffInDays($date2); $daysSinceBirth = Carbon::createFromDate(1990, 5, 15)->diffInDays(); ``` -------------------------------- ### Catching UnknownSetterException Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/errors.md Handles errors when attempting to set an undefined property on a Carbon instance. ```php try { $date = Carbon::now(); $date->unknownProperty = 'value'; } catch (UnknownSetterException $e) { echo 'Unknown property: ' . $e->getMessage(); } ``` -------------------------------- ### Create CarbonPeriod Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Generate a CarbonPeriod instance using the unit. ```php $period = Unit::Day->toPeriod('2024-01-01', '2024-01-31'); ``` -------------------------------- ### Configure Timezone by UTC Offset Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/configuration.md Initializes a CarbonTimeZone using an integer representing the offset in seconds. ```php use Carbon\CarbonTimeZone; // UTC+5:30 (India) $tz = new CarbonTimeZone(19800); // 5.5 hours in seconds // UTC-5 (Eastern) $tz = new CarbonTimeZone(-18000); $date = Carbon::now($tz); ``` -------------------------------- ### Format dates using format() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Use standard PHP date format characters to format the date string. ```php echo $date->format('Y-m-d H:i:s'); echo $date->format('l, F j, Y'); ``` -------------------------------- ### Unit::toPeriod() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/types.md Creates a CarbonPeriod instance using the current unit. ```APIDOC ## Carbon\Unit::toPeriod() ### Description Creates a CarbonPeriod object initialized with this unit. ### Signature `public function toPeriod(...$params): CarbonPeriod` ### Parameters - **params** (mixed) - Optional - Parameters passed to the CarbonPeriod constructor. ### Example ```php $period = Unit::Day->toPeriod('2024-01-01', '2024-01-31'); ``` ``` -------------------------------- ### CarbonTimeZone::__construct Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Creates a new instance of the CarbonTimeZone class. ```APIDOC ## __construct(DateTimeZone|string|int|null $tz = null) ### Description Creates a new CarbonTimeZone instance. The timezone can be specified by name, UTC offset in seconds, or an existing DateTimeZone object. ### Parameters - **tz** (DateTimeZone, string, int, null) - Optional - Timezone name (e.g., 'UTC', 'America/New_York'), UTC offset in seconds, or DateTimeZone object. ``` -------------------------------- ### Handle CarbonPeriod exceptions Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-period.md Demonstrates catching an InvalidPeriodDateException when initializing a CarbonPeriod with invalid date parameters. ```php try { $period = new CarbonPeriod('invalid-date', '1 day', '2024-01-31'); } catch (InvalidPeriodDateException $e) { echo $e->getMessage(); } ``` -------------------------------- ### Creating intervals from days Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-interval.md Generate an interval representing a specific number of days. ```php $interval = CarbonInterval::days(7); ``` -------------------------------- ### Add time to CarbonImmutable instance Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-immutable.md Demonstrates adding time to an instance and verifying that the original instance remains unchanged. ```php public function add($unit, $value = 1, OverflowMode|bool|null $overflow = null, ?int $anchorDay = null): static ``` ```php $original = CarbonImmutable::now(); $future = $original->add('day', 5); // original is unchanged echo $original->format('Y-m-d'); echo $future->format('Y-m-d'); ``` -------------------------------- ### Create CarbonTimeZone from Offset Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-timezone.md Creates a CarbonTimeZone instance using a UTC offset provided in seconds. ```php $tz = CarbonTimeZone::toOffsetTimeZone(19800); // UTC+5:30 echo $tz->toOffsetName(); // "UTC+05:30" ``` -------------------------------- ### setYear(), setMonth(), setDay() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Sets specific date components for the Carbon instance. ```APIDOC ## setYear(int $year), setMonth(int $month), setDay(int $day) ### Description Set specific date components (year, month, or day) on the instance. ``` -------------------------------- ### serialize() Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Serializes the instance for storage or transmission. ```APIDOC ## serialize() ### Description Serialize the instance for storage/transmission. ``` -------------------------------- ### CarbonImmutable Instantiation Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-immutable.md Create new instances using string dates or the current time. ```php use Carbon\CarbonImmutable; $immutable = new CarbonImmutable('2024-06-15'); $immutable = CarbonImmutable::now(); ``` -------------------------------- ### Formatting Methods Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon-immutable.md Methods for converting date objects into various string formats. ```APIDOC ## Formatting Methods ### format() - **format(string $format)**: string ### toDateString(), toTimeString(), toDateTimeString() - **toDateString()**: string - **toTimeString()**: string - **toDateTimeString()**: string ### toIso8601String(), toRfc2822String() - **toIso8601String()**: string - **toRfc2822String()**: string ### isoFormat() - **isoFormat(string $format, ?string $locale = null, ?TranslatorInterface $translator = null)**: string ``` -------------------------------- ### Register a macro on a factory Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/factory.md Define custom methods on instances created by the factory using a callable. ```php $factory->macro('isHoliday', function() { $holidays = ['12-25', '12-31']; return in_array($this->format('m-d'), $holidays); }); $date = $factory->now(); $date->isHoliday(); // Calls the macro ``` -------------------------------- ### isoFormat(string $format, ?string $locale, ?TranslatorInterface $translator) Source: https://github.com/briannesbitt/carbon/blob/master/_autodocs/api-reference/carbon.md Formats the date using ISO format tokens with optional locale support. ```APIDOC ## isoFormat(string $format, ?string $locale, ?TranslatorInterface $translator) ### Description Format using ISO format tokens with locale support. ### Signature `public function isoFormat(string $format, ?string $locale = null, ?TranslatorInterface $translator = null): string` ### Parameters - **format** (string) - Required - The ISO format string. - **locale** (string) - Optional - The locale string. - **translator** (TranslatorInterface) - Optional - The translator instance. ```