Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⭐ Enums for week days, months and units #2701

Closed
kylekatarnls opened this issue Nov 7, 2022 · 0 comments
Closed

⭐ Enums for week days, months and units #2701

kylekatarnls opened this issue Nov 7, 2022 · 0 comments
Assignees
Milestone

Comments

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Nov 7, 2022

If we drop PHP 8.0, using enums for week days, months and units is an option to be able write chaining in a more natural way, such as:

echo \Carbon\WeekDay::Monday->locale('it')->dayName; // lunedì
// equivalent to:
echo \Carbon\CarbonImmutable::parse('Monday')->locale('it')->dayName; // lunedì
echo \Carbon\Month::January->locale('it')->monthName; // gennaio
// equivalent to:
echo \Carbon\CarbonImmutable::parse('January 1st')->locale('it')->monthName; // gennaio
foreach (\Carbon\Unit::Week->stepBy('day') as $day) {
   $days[] = "$day";
}
// equivalent to:
foreach (\Carbon\CarbonInterval::week()->stepBy('day') as $day) {
   $days[] = "$day";
}

Those enums could also be supported in weekday(\Carbon\WeekDay|int $day) or month(\Carbon\Month|int $month)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant