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

Closed
wants to merge 5 commits into
base: master
from

Conversation

4 participants
@meteguerlek

meteguerlek commented Mar 12, 2018

$weekdays = Carbon::getCurrentWeekDays()

Array
(
    [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

briannesbitt Mar 12, 2018

Owner

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.

@kylekatarnls

This comment has been minimized.

Collaborator

kylekatarnls commented Mar 13, 2018

Hi,

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.

@meteguerlek

This comment has been minimized.

meteguerlek commented Mar 13, 2018

Hi @kylekatarnls,

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

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

not working.

@kylekatarnls

This comment has been minimized.

Collaborator

kylekatarnls commented Mar 13, 2018

$startOfWeek->addDay()->copy()

- add copy()
- new method getCurrentMonthDays()

kylekatarnls added a commit to kylekatarnls/Carbon that referenced this pull request Apr 13, 2018

@kylekatarnls

This comment has been minimized.

Collaborator

kylekatarnls commented Apr 13, 2018

Will appear in the documentation:
gh-pages...kylekatarnls:gh-pages-1.26

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