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

How to get a list of all the names of the days of the week? #275

Closed
max-sym opened this issue Feb 9, 2018 · 1 comment
Closed

How to get a list of all the names of the days of the week? #275

max-sym opened this issue Feb 9, 2018 · 1 comment

Comments

@max-sym
Copy link

max-sym commented Feb 9, 2018

I'm wondering if there's a way of getting a full list of all the names of the days of the week or month names. It would be very helpful for creating the tables with the columns named as such depending on which language is used. Thanks!

Update: I found the solution, but it's not very clean:

$date = Date::getTranslator()->getCatalogue()->all()['messages']; // gets a full translation array
$days = array_slice($date,23); // 23 is index of 'monday'

@kylekatarnls
Copy link
Contributor

kylekatarnls commented Mar 12, 2019

With jessengers/date >= 3.5.0 (and Carbon >= 2.0), an elegant way could be:

var_dump(array_map(function ($number) {
  return Date::parse("next Monday + $number days")->locale('fr')->dayName;
}, range(0, 6)));

Replace fr by any language you want.

Same principle for months:

var_dump(array_map(function ($number) {
  return Date::parse("2000-$number-01")->locale('fr')->monthName;
}, range(1, 12)));

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

No branches or pull requests

3 participants