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

Feature request: Next elapse (systemd-analyze calendar) #3095

Open
shaedrich opened this issue Oct 28, 2024 · 1 comment
Open

Feature request: Next elapse (systemd-analyze calendar) #3095

shaedrich opened this issue Oct 28, 2024 · 1 comment

Comments

@shaedrich
Copy link

shaedrich commented Oct 28, 2024

It would be nice to have something like systemd-analyze calendar in Carbon

grafik
grafik

Idea: https://chaos.social/@rixx/113381352980372544

Docs: https://www.man7.org/linux/man-pages/man1/systemd-analyze.1.html#:~:text=Example%2012.%20Show%20leap%20days%20in%20the%20near%20future

@kylekatarnls
Copy link
Collaborator

kylekatarnls commented Oct 30, 2024

Hello,

As a first sight, this sound like a big enough project to deserve its own package.

Then any kind of package can be integrated in Carbon using macros.

With this use-case it would look like:

// This class could come from a dedicate package
class CalendarAnalyzer
{
    public function analyze(
        DateTimeImmutable $now,
        string $pattern,
        int $iterations = 1,
    ): DateTimeImmutable {
        // Here comes the actual algorithm which can be completely agnostic from Carbon
        return new DateTimeImmutable('...');
    }
}

// Then when bootstrapping the app, we can turn it into a Carbon macro:
Carbon::macro('analyzeCalendar', static function (string $pattern, int $iterations = 1) {
    $analyzer = new CalendarAnalyzer();

    return Carbon::instance($analyzer->analyze(self::this(), $pattern, $iterations));
});

// Then later in your app, you can use it right from Carbon:
Carbon::analyzeCalendar('Tue *-12-25');
Carbon::parse('2026-01-01')->analyzeCalendar('*-02-29', 3);

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

2 participants