Skip to content

Commit

Permalink
Add static cache for documentation of the older versions
Browse files Browse the repository at this point in the history
kylekatarnls committed Oct 9, 2024
1 parent 8acd5d4 commit 4e740ac
Showing 24 changed files with 75 additions and 47 deletions.
86 changes: 43 additions & 43 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -133,13 +133,13 @@ <h1 id="api-introduction">Introduction</h1>
$modifiedImmutable = CarbonImmutable::now()->add(1, 'day');

var_dump($modifiedMutable === $mutable); // bool(true)
var_dump($mutable->isoFormat('dddd D')); // string(9) "Monday 16"
var_dump($modifiedMutable->isoFormat('dddd D')); // string(9) "Monday 16"
var_dump($mutable->isoFormat('dddd D')); // string(12) "Wednesday 25"
var_dump($modifiedMutable->isoFormat('dddd D')); // string(12) "Wednesday 25"
// So it means $mutable and $modifiedMutable are the same object
// both set to now + 1 day.
var_dump($modifiedImmutable === $immutable); // bool(false)
var_dump($immutable->isoFormat('dddd D')); // string(9) "Sunday 15"
var_dump($modifiedImmutable->isoFormat('dddd D')); // string(9) "Monday 16"
var_dump($immutable->isoFormat('dddd D')); // string(10) "Tuesday 24"
var_dump($modifiedImmutable->isoFormat('dddd D')); // string(12) "Wednesday 25"
// While $immutable is still set to now and cannot be changed and
// $modifiedImmutable is a new instance created from $immutable
// set to now + 1 day.
@@ -281,16 +281,16 @@ <h1 id="api-instantiation">Instantiation</h1>

<p>
<pre class="live-editor"><code class="php">$now = Carbon::now();
echo $now; // 2024-09-15 20:26:50
echo $now; // 2024-09-24 09:21:00
echo "\n";
$today = Carbon::today();
echo $today; // 2024-09-15 00:00:00
echo $today; // 2024-09-24 00:00:00
echo "\n";
$tomorrow = Carbon::tomorrow('Europe/London');
echo $tomorrow; // 2024-09-16 00:00:00
echo $tomorrow; // 2024-09-25 00:00:00
echo "\n";
$yesterday = Carbon::yesterday();
echo $yesterday; // 2024-09-14 00:00:00
echo $yesterday; // 2024-09-23 00:00:00
</code></pre>
</p>

@@ -451,7 +451,7 @@ <h1 id="api-instantiation">Instantiation</h1>
// 19:15 in Johannesburg
echo 'Meeting starts at '.$meeting->format('H:i').' in Johannesburg.'; // Meeting starts at 19:15 in Johannesburg.
// now in Johannesburg
echo "It's ".$meeting->nowWithSameTz()->format('H:i').' right now in Johannesburg.'; // It's 22:26 right now in Johannesburg.
echo "It's ".$meeting->nowWithSameTz()->format('H:i').' right now in Johannesburg.'; // It's 11:21 right now in Johannesburg.
</code></pre>
</p>

@@ -705,7 +705,7 @@ <h1 id="api-localization">Localization</h1>
echo "\n";
echo $date->monthName; // septembre
echo "\n";
echo $date->isoFormat('LLLL'); // dimanche 15 septembre 2024 20:26
echo $date->isoFormat('LLLL'); // mardi 24 septembre 2024 09:21
</code></pre>
</p>

@@ -736,13 +736,13 @@ <h1 id="api-localization">Localization</h1>
echo $toDisplay;
/*
15 juin 2018 14:34
Aujourd’hui à 22:26
Aujourd’hui à 11:21
*/

echo $notificationForJohn;
/*
Jun 15, 2018 7:34 AM
Today at 3:26 PM
Today at 4:21 AM
*/
</code></pre>
</p>
@@ -769,9 +769,9 @@ <h1 id="api-localization">Localization</h1>
]);
// Important note: timezone setting calls ->shiftTimezone() and not ->setTimezone(),
// It means it does not just set the timezone, but shift the time too:
echo Carbon::today()->setTimezone('Asia/Tokyo')->format('d/m G\h e'); // 15/09 9h Asia/Tokyo
echo Carbon::today()->setTimezone('Asia/Tokyo')->format('d/m G\h e'); // 24/09 9h Asia/Tokyo
echo "\n";
echo Carbon::today()->shiftTimezone('Asia/Tokyo')->format('d/m G\h e'); // 15/09 0h Asia/Tokyo
echo Carbon::today()->shiftTimezone('Asia/Tokyo')->format('d/m G\h e'); // 24/09 0h Asia/Tokyo

// You can find back which factory created a given object:
$a = $factory->now();
@@ -1654,21 +1654,21 @@ <h1 id="api-localization">Localization</h1>

<p>
<pre class="live-editor"><code class="php">$date = CarbonImmutable::now();
echo $date->calendar(); // Today at 8:26 PM
echo $date->calendar(); // Today at 9:21 AM
echo "\n";
echo $date->sub('1 day 3 hours')->calendar(); // Yesterday at 5:26 PM
echo $date->sub('1 day 3 hours')->calendar(); // Yesterday at 6:21 AM
echo "\n";
echo $date->sub('3 days 10 hours 23 minutes')->calendar(); // Last Thursday at 10:03 AM
echo $date->sub('3 days 10 hours 23 minutes')->calendar(); // Last Friday at 10:58 PM
echo "\n";
echo $date->sub('8 days')->calendar(); // 09/07/2024
echo $date->sub('8 days')->calendar(); // 09/16/2024
echo "\n";
echo $date->add('1 day 3 hours')->calendar(); // Tomorrow at 11:26 PM
echo $date->add('1 day 3 hours')->calendar(); // Tomorrow at 12:21 PM
echo "\n";
echo $date->add('3 days 10 hours 23 minutes')->calendar(); // Thursday at 6:49 AM
echo $date->add('3 days 10 hours 23 minutes')->calendar(); // Friday at 7:44 PM
echo "\n";
echo $date->add('8 days')->calendar(); // 09/23/2024
echo $date->add('8 days')->calendar(); // 10/02/2024
echo "\n";
echo $date->locale('fr')->calendar(); // Aujourd’hui à 20:26
echo $date->locale('fr')->calendar(); // Aujourd’hui à 09:21
</code></pre>
</p>

@@ -5588,7 +5588,7 @@ <h1 id="api-testing">Testing Aids</h1>
var_dump(Carbon::hasTestNow()); // bool(true)
Carbon::setTestNow(); // clear the mock
var_dump(Carbon::hasTestNow()); // bool(false)
echo Carbon::now(); // 2024-09-15 20:26:52
echo Carbon::now(); // 2024-09-24 09:21:01
// Instead of mock and clear mock, you also can use withTestNow():

Carbon::withTestNow('2010-09-15', static function () {
@@ -5831,12 +5831,12 @@ <h1 id="api-getters">Getters</h1>

// You can get any property dynamically too:
$unit = 'second';
var_dump(Carbon::now()->get($unit)); // int(52)
var_dump(Carbon::now()->get($unit)); // int(1)
// equivalent to:
var_dump(Carbon::now()->$unit); // int(52)
var_dump(Carbon::now()->$unit); // int(1)
// If you have plural unit name, use singularUnit()
$unit = Carbon::singularUnit('seconds');
var_dump(Carbon::now()->get($unit)); // int(52)
var_dump(Carbon::now()->get($unit)); // int(1)
// Prefer using singularUnit() because some plurals are not the word with S:
var_dump(Carbon::pluralUnit('century')); // string(9) "centuries"
var_dump(Carbon::pluralUnit('millennium')); // string(9) "millennia"
@@ -5912,23 +5912,23 @@ <h1 id="api-week">Weeks</h1>

var_dump($en->firstWeekDay); // int(0)
var_dump($en->lastWeekDay); // int(6)
var_dump($en->startOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-15 00:00"
var_dump($en->endOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-21 23:59"
var_dump($en->startOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-22 00:00"
var_dump($en->endOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-28 23:59"

echo "-----------\n";

// We still can force to use an other day as start/end of week
$start = $en->startOfWeek(Carbon::TUESDAY);
$end = $en->endOfWeek(Carbon::MONDAY);
var_dump($start->format('Y-m-d H:i')); // string(16) "2024-09-10 00:00"
var_dump($end->format('Y-m-d H:i')); // string(16) "2024-09-16 23:59"
var_dump($start->format('Y-m-d H:i')); // string(16) "2024-09-24 00:00"
var_dump($end->format('Y-m-d H:i')); // string(16) "2024-09-30 23:59"

echo "-----------\n";

var_dump($ar->firstWeekDay); // int(6)
var_dump($ar->lastWeekDay); // int(5)
var_dump($ar->startOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-14 00:00"
var_dump($ar->endOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-20 23:59"
var_dump($ar->startOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-21 00:00"
var_dump($ar->endOfWeek()->format('Y-m-d H:i')); // string(16) "2024-09-27 23:59"

$en = CarbonImmutable::parse('2015-02-05'); // use en_US as default locale

@@ -6413,8 +6413,8 @@ <h1 id="api-comparison">Comparison</h1>

// now is the default param
$dt1 = Carbon::createMidnightDate(2000, 1, 1);
echo $dt1->max(); // 2024-09-15 20:26:52
echo $dt1->maximum(); // 2024-09-15 20:26:52
echo $dt1->max(); // 2024-09-24 09:21:01
echo $dt1->maximum(); // 2024-09-24 09:21:01

// Remember min and max PHP native function work fine with dates too:
echo max(Carbon::create('2002-03-15'), Carbon::create('2003-01-07'), Carbon::create('2002-08-25')); // 2003-01-07 00:00:00
@@ -6909,7 +6909,7 @@ <h1 id="api-difference">Difference</h1>
greater than the other.</p>

<p>
<pre><code class="php">echo Carbon::now('America/Vancouver')->diffInSeconds(Carbon::now('Europe/London')); // 9.0E-6
<pre><code class="php">echo Carbon::now('America/Vancouver')->diffInSeconds(Carbon::now('Europe/London')); // 1.0E-5

$dtOttawa = Carbon::createMidnightDate(2000, 1, 1, 'America/Toronto');
$dtVancouver = Carbon::createMidnightDate(2000, 1, 1, 'America/Vancouver');
@@ -7048,10 +7048,10 @@ <h1 id="api-difference">Difference</h1>

$date = Carbon::now()->addSeconds(3666);

echo $date->diffInSeconds(); // -3665.999883
echo $date->diffInMinutes(); // -61.099996533333
echo $date->diffInHours(); // -1.0183332527778
echo $date->diffInDays(); // -0.042430551273148
echo $date->diffInSeconds(); // -3665.999871
echo $date->diffInMinutes(); // -61.0999962
echo $date->diffInHours(); // -1.0183332469444
echo $date->diffInDays(); // -0.042430551006944

$date = Carbon::create(2016, 1, 5, 22, 40, 32);

@@ -7706,7 +7706,7 @@ <h1 id="api-macro">Macro</h1>
echo "\n";
echo Carbon::tomorrow()->formatForUser(); // Demain à 02:00
echo "\n";
echo Carbon::now()->subDays(3)->formatForUser(); // jeudi dernier à 22:26
echo Carbon::now()->subDays(3)->formatForUser(); // samedi dernier à 11:21
</code></pre>
</p>

@@ -7969,9 +7969,9 @@ <h1 id="api-macro">Macro</h1>
echo substr(implode(', ', $dates), 0, 100).'...';
}

dumpDateList(Carbon::getCurrentWeekDays()); // 2024-09-09 00:00:00, 2024-09-10 00:00:00, 2024-09-11 00:00:00, 2024-09-12 00:00:00, 2024-09-13 00:00...
dumpDateList(Carbon::getCurrentWeekDays()); // 2024-09-23 00:00:00, 2024-09-24 00:00:00, 2024-09-25 00:00:00, 2024-09-26 00:00:00, 2024-09-27 00:00...
dumpDateList(Carbon::getCurrentMonthDays()); // 2024-09-01 00:00:00, 2024-09-02 00:00:00, 2024-09-03 00:00:00, 2024-09-04 00:00:00, 2024-09-05 00:00...
dumpDateList(Carbon::now()->subMonth()->getCurrentWeekDays()); // 2024-08-12 00:00:00, 2024-08-13 00:00:00, 2024-08-14 00:00:00, 2024-08-15 00:00:00, 2024-08-16 00:00...
dumpDateList(Carbon::now()->subMonth()->getCurrentWeekDays()); // 2024-08-19 00:00:00, 2024-08-20 00:00:00, 2024-08-21 00:00:00, 2024-08-22 00:00:00, 2024-08-23 00:00...
dumpDateList(Carbon::now()->subMonth()->getCurrentMonthDays()); // 2024-08-01 00:00:00, 2024-08-02 00:00:00, 2024-08-03 00:00:00, 2024-08-04 00:00:00, 2024-08-05 00:00...
</code></pre>
</p>
@@ -8951,7 +8951,7 @@ <h1 id="api-period">CarbonPeriod</h1>
$days[] = $date->format('Y-m-d');
}

echo implode(', ', $days); // 2024-09-15, 2024-09-16, 2024-09-17
echo implode(', ', $days); // 2024-09-24, 2024-09-25, 2024-09-26
</code></pre>
</p>

14 changes: 10 additions & 4 deletions tools/api-history.php
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ function nameAlias($name)
$versions = array_filter(array_map(function ($version) {
return $version === MASTER_BRANCH ? MASTER_VERSION : $version;
}, array_keys(json_decode(file_get_contents('https://packagist.org/p/nesbot/carbon.json'), true)['packages']['nesbot/carbon'])), function ($version) {
return !preg_match('/(dev-|-beta|-alpha|-dev)/', $version) && !in_array($version, BLACKLIST);
return !preg_match('/(dev-|-beta|-alpha|-dev)/', $version) && !\in_array($version, BLACKLIST, true);
});

usort($versions, 'version_compare');
@@ -240,10 +240,16 @@ function requireCarbon($branch): string

ksort($methods);

$count = count($versions);
$count = \count($versions);

function getMethodsOfVersion($version, bool $forceRebuild = false)
{
$cache = __DIR__.'/static-cache/methods_of_version_'.$version.'.json';

if (file_exists($cache)) {
return file_get_contents($cache);
}

$cache = __DIR__.'/cache/methods_of_version_'.$version.'.json';

if (!$forceRebuild && file_exists($cache)) {
@@ -284,8 +290,8 @@ function getMethodsOfVersion($version, bool $forceRebuild = false)

foreach ([false, true] as $forceRebuild) {
$output = getMethodsOfVersion($version, $forceRebuild);
$data = is_string($output) ? @json_decode($output, true) : null;
$decodable = is_array($data);
$data = \is_string($output) ? @json_decode($output, true) : null;
$decodable = \is_array($data);
$error = $decodable ? ($data['error'] ?? null) : ($output ?? 'Missing output');

if ($error === null) {
1 change: 1 addition & 0 deletions tools/static-cache/methods_of_version_1.0.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Carbon\\Carbon::__construct":["$time = null","$tz = null"],"Carbon\\Carbon::instance":["DateTime $date"],"Carbon\\Carbon::now":["$tz = null"],"Carbon\\Carbon::create":["$year = null","$month = null","$day = null","$hour = null","$minute = null","$second = null","$tz = null"],"Carbon\\Carbon::createFromDate":["$year = null","$month = null","$day = null","$tz = null"],"Carbon\\Carbon::createFromTime":["$hour = null","$minute = null","$second = null","$tz = null"],"Carbon\\Carbon::createFromFormat":["$format","$time","$object = null"],"Carbon\\Carbon::createFromTimestamp":["$timestamp","$tz = null"],"Carbon\\Carbon::createFromTimestampUTC":["$timestamp"],"Carbon\\Carbon::copy":[],"Carbon\\Carbon::__get":["$name"],"Carbon\\Carbon::__set":["$name","$value"],"Carbon\\Carbon::year":["$value"],"Carbon\\Carbon::month":["$value"],"Carbon\\Carbon::day":["$value"],"Carbon\\Carbon::setDate":["$year","$month","$day"],"Carbon\\Carbon::hour":["$value"],"Carbon\\Carbon::minute":["$value"],"Carbon\\Carbon::second":["$value"],"Carbon\\Carbon::setTime":["$hour","$minute","$second = 0"],"Carbon\\Carbon::setDateTime":["$year","$month","$day","$hour","$minute","$second"],"Carbon\\Carbon::timestamp":["$value"],"Carbon\\Carbon::timezone":["$value"],"Carbon\\Carbon::tz":["$value"],"Carbon\\Carbon::setTimezone":["$value"],"Carbon\\Carbon::__toString":[],"Carbon\\Carbon::toDateString":[],"Carbon\\Carbon::toFormattedDateString":[],"Carbon\\Carbon::toTimeString":[],"Carbon\\Carbon::toDateTimeString":[],"Carbon\\Carbon::toDayDateTimeString":[],"Carbon\\Carbon::toATOMString":[],"Carbon\\Carbon::toCOOKIEString":[],"Carbon\\Carbon::toISO8601String":[],"Carbon\\Carbon::toRFC822String":[],"Carbon\\Carbon::toRFC850String":[],"Carbon\\Carbon::toRFC1036String":[],"Carbon\\Carbon::toRFC1123String":[],"Carbon\\Carbon::toRFC2822String":[],"Carbon\\Carbon::toRFC3339String":[],"Carbon\\Carbon::toRSSString":[],"Carbon\\Carbon::toW3CString":[],"Carbon\\Carbon::eq":["Carbon\\Carbon $date"],"Carbon\\Carbon::ne":["Carbon\\Carbon $date"],"Carbon\\Carbon::gt":["Carbon\\Carbon $date"],"Carbon\\Carbon::gte":["Carbon\\Carbon $date"],"Carbon\\Carbon::lt":["Carbon\\Carbon $date"],"Carbon\\Carbon::lte":["Carbon\\Carbon $date"],"Carbon\\Carbon::isWeekday":[],"Carbon\\Carbon::isWeekend":[],"Carbon\\Carbon::isYesterday":[],"Carbon\\Carbon::isToday":[],"Carbon\\Carbon::isTomorrow":[],"Carbon\\Carbon::isFuture":[],"Carbon\\Carbon::isPast":[],"Carbon\\Carbon::isLeapYear":[],"Carbon\\Carbon::addYears":["$value"],"Carbon\\Carbon::addYear":[],"Carbon\\Carbon::subYear":[],"Carbon\\Carbon::subYears":["$value"],"Carbon\\Carbon::addMonths":["$value"],"Carbon\\Carbon::addMonth":[],"Carbon\\Carbon::subMonth":[],"Carbon\\Carbon::subMonths":["$value"],"Carbon\\Carbon::addDays":["$value"],"Carbon\\Carbon::addDay":[],"Carbon\\Carbon::subDay":[],"Carbon\\Carbon::subDays":["$value"],"Carbon\\Carbon::addWeekdays":["$value"],"Carbon\\Carbon::addWeekday":[],"Carbon\\Carbon::subWeekday":[],"Carbon\\Carbon::subWeekdays":["$value"],"Carbon\\Carbon::addWeeks":["$value"],"Carbon\\Carbon::addWeek":[],"Carbon\\Carbon::subWeek":[],"Carbon\\Carbon::subWeeks":["$value"],"Carbon\\Carbon::addHours":["$value"],"Carbon\\Carbon::addHour":[],"Carbon\\Carbon::subHour":[],"Carbon\\Carbon::subHours":["$value"],"Carbon\\Carbon::addMinutes":["$value"],"Carbon\\Carbon::addMinute":[],"Carbon\\Carbon::subMinute":[],"Carbon\\Carbon::subMinutes":["$value"],"Carbon\\Carbon::addSeconds":["$value"],"Carbon\\Carbon::addSecond":[],"Carbon\\Carbon::subSecond":[],"Carbon\\Carbon::subSeconds":["$value"],"Carbon\\Carbon::startOfDay":[],"Carbon\\Carbon::endOfDay":[],"Carbon\\Carbon::startOfMonth":[],"Carbon\\Carbon::endOfMonth":[],"Carbon\\Carbon::diffInYears":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffInMonths":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffInDays":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffInHours":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffInMinutes":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffInSeconds":["Carbon\\Carbon $date = null","$absolute = true"],"Carbon\\Carbon::diffForHumans":["Carbon\\Carbon $other = null"],"Carbon\\Carbon::__wakeup":[],"Carbon\\Carbon::__set_state":["array $array"],"Carbon\\Carbon::createFromImmutable":["$DateTimeImmutable"],"Carbon\\Carbon::getLastErrors":[],"Carbon\\Carbon::format":["$format"],"Carbon\\Carbon::modify":["$modify"],"Carbon\\Carbon::add":["$interval"],"Carbon\\Carbon::sub":["$interval"],"Carbon\\Carbon::getTimezone":[],"Carbon\\Carbon::getOffset":[],"Carbon\\Carbon::setISODate":["$year","$week","$day"],"Carbon\\Carbon::setTimestamp":["$unixtimestamp"],"Carbon\\Carbon::getTimestamp":[],"Carbon\\Carbon::diff":["$object","$absolute"]}
Loading

0 comments on commit 4e740ac

Please sign in to comment.