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

Closed
wants to merge 5 commits into from
Closed

get the all dates of week #1191

wants to merge 5 commits into from

Conversation

meteguerlek
Copy link

@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());
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Glavic Glavic added the macro candidate Rather than new methods, this could be a macro/mixin label Mar 13, 2018
@kylekatarnls
Copy link
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
Copy link
Author

Hi @kylekatarnls,

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

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

not working.

@kylekatarnls
Copy link
Collaborator

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

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

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

@kylekatarnls kylekatarnls added documentation Rely to documentations or gh-pages branch and removed macro candidate Rather than new methods, this could be a macro/mixin labels Apr 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Rely to documentations or gh-pages branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants