Skip to content

Conversation

FabianoLothor
Copy link
Contributor

  • Create TextParser class with natural language processing
  • Add Rule::createFromText() static method
  • Support common patterns: frequencies, intervals, counts, weekdays, months
  • Compatible with existing Rule infrastructure and TextTransformer

@FabianoLothor FabianoLothor changed the title feat: Add text-to-rule parsing functionality Add text-to-rule parsing functionality Oct 1, 2025
@FabianoLothor
Copy link
Contributor Author

FabianoLothor commented Oct 1, 2025

#222

@FabianoLothor
Copy link
Contributor Author

@simshaun I don't know how to trigger phpstan check in the PR.

@FabianoLothor FabianoLothor force-pushed the codespace-improved-broccoli-gxwg779x54c9q6j branch from 1a99dd0 to db0b79f Compare October 7, 2025 05:14
- Cast numeric values (INTERVAL, COUNT, BYMONTH) to strings
- Update type annotations to match Rule constructor expectations
- Maintain null safety checks for symbol array access
@FabianoLothor FabianoLothor force-pushed the codespace-improved-broccoli-gxwg779x54c9q6j branch from 9f6e6ea to 7b99dc8 Compare October 7, 2025 05:45
\DateTime|\DateTimeImmutable|string|null $endDate = null,
?string $timezone = null,
): self {
require_once __DIR__ . '/TextParser.php';
Copy link
Owner

Choose a reason for hiding this comment

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

Shouldn't be necessary with Composer's autoloader

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed

@simshaun
Copy link
Owner

simshaun commented Oct 7, 2025

Thank you! At initial glance, looks good. I'll fully review when I get some downtime.

Couple things:

  1. A comprehensive test suite will be necessary. I can work on it while reviewing if you don't beat me to it.
  2. Multi-lingual support would be nice. This isn't a blocker and can be added later.

@FabianoLothor
Copy link
Contributor Author

FabianoLothor commented Oct 7, 2025

1. A comprehensive test suite will be necessary. I can work on it while reviewing if you don't beat me to it.

I won't be able to write unit-tests until the weekend, but this snippet might be helpful if you decide to write them properly:

<?php

require_once 'src/Recurr/Exception.php';
require_once 'src/Recurr/Exception/InvalidRRule.php';
require_once 'src/Recurr/Exception/InvalidArgument.php';
require_once 'src/Recurr/Exception/InvalidWeekday.php';
require_once 'src/Recurr/TextParser.php';
require_once 'src/Recurr/Rule.php';

use Recurr\Rule;
use Recurr\TextParser;

echo "Testing Text-to-Rule functionality\n";
echo "==================================\n\n";

// Test cases similar to rrule.js examples
$testCases = [
    'every day',
    'every 2 days', 
    'every week',
    'every 3 weeks',
    'every month',
    'every year',
    'every day for 3 times',
    'every 2 weeks for 5 times',
    'every Monday',
    'every Friday', 
    'every weekdays',
    'every January',
    'every December'
];

foreach ($testCases as $text) {
    echo "Testing: '$text'\n";
    
    try {
        $rule = Rule::createFromText($text);
        $rruleString = $rule->getString();
        echo "  Result: $rruleString\n";
        echo "  Frequency: " . $rule->getFreqAsText() . "\n";
        if ($rule->getInterval() > 1) {
            echo "  Interval: " . $rule->getInterval() . "\n";
        }
        if ($rule->getCount()) {
            echo "  Count: " . $rule->getCount() . "\n";
        }
        if ($rule->getByDay()) {
            echo "  ByDay: " . implode(',', $rule->getByDay()) . "\n";
        }
        if ($rule->getByMonth()) {
            echo "  ByMonth: " . implode(',', $rule->getByMonth()) . "\n";
        }
    } catch (Exception $e) {
        echo "  Error: " . $e->getMessage() . "\n";
    }
    
    echo "\n";
}

echo "Testing completed!\n";
2. Multi-lingual support would be nice. This isn't a blocker and can be added later.

I really like the multi-lingual support suggestion, certainly doable and likely not too complicated to implement.

That said, I'm not aware of a similar feature in other libraries that supports internationalization. It would be a really nice and welcome novelty.

todoist for example is an app that supports multi-lingual support for recurring tasks.

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

Successfully merging this pull request may close these issues.

2 participants