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

get the all dates of week #1191

wants to merge 5 commits into from


Copy link

@meteguerlek meteguerlek commented Mar 12, 2018

$weekdays = Carbon::getCurrentWeekDays()

    [0] => 2018-03-12 00:00:00
    [1] => 2018-03-13 00:00:00
    [2] => 2018-03-14 00:00:00
    [3] => 2018-03-15 00:00:00
    [4] => 2018-03-16 00:00:00
    [5] => 2018-03-17 00:00:00
    [6] => 2018-03-18 00:00:00
public static function getCurrentWeekDays()
$startOfWeek = Carbon::instance((new static)->startOfWeek());

This comment has been minimized.


briannesbitt Mar 12, 2018

If change this to static::now()->startOfWeek()->subDay() you can then just loop from 0 to < DAYS_PER_WEEK and loop code will stay the same. This will get rid of the PHP 5.4+ array syntax as well, since we support 5.3 and higher.

Copy link

@kylekatarnls kylekatarnls commented Mar 13, 2018


For me this method is too user-specific (mostly when returning datetime strings rather than a date copy users can format as they want after that).

Every feature in Carbon needs unit tests (that's why codecov does not pass).

You also need to follow the code style of the project (check StyleCI details).

It's also required to use constats (Carbon::DAYS_PER_WEEK) rather than hard-coded values, it allows to configure Carbon by extending it and make every method respect the user settings.

I agree with @Glavic for the macro label, this could go in our future list of macros.

Copy link

@meteguerlek meteguerlek commented Mar 13, 2018

Hi @kylekatarnls,

its ok, this could go in the future list. But

$weekDays[] = $startOfWeek->addDay();

not working.

Copy link

@kylekatarnls kylekatarnls commented Mar 13, 2018


- new method getCurrentMonthDays()
kylekatarnls added a commit to kylekatarnls/Carbon that referenced this pull request Apr 13, 2018
Copy link

@kylekatarnls kylekatarnls commented Apr 13, 2018

Will appear in the documentation:

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

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.