Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 30, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 30, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 30, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 30, 2025

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025

      The Witcher 3: Wild Hunt reaches 60 million copies sold as work continues on The Witcher 4

      May 30, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      How Remix is shaking things up

      May 30, 2025
      Recent

      How Remix is shaking things up

      May 30, 2025

      Perficient at Kscope25: Let’s Meet in Texas!

      May 30, 2025

      Salesforce + Informatica: What It Means for Data Cloud and Our Customers

      May 30, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025
      Recent

      Does Elden Ring Nightreign have crossplay or cross-platform play?

      May 30, 2025

      Cyberpunk 2077 sequel enters pre-production as Phantom Liberty crosses 10 million copies sold

      May 30, 2025

      EA has canceled yet another game, shuttered its developer, and started more layoffs

      May 30, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Recurr is a PHP library for working with recurrence rules for calendar dates

    Recurr is a PHP library for working with recurrence rules for calendar dates

    January 8, 2025

    Recurr is a PHP library for working with recurrence rules for calendar dates

    As the new year begins, many of us set recurring goals—daily workouts, weekly meetings, or monthly reflections. Tracking these commitments in life can be tricky, but managing them programmatically doesn’t have to be. Enter Recurr, a powerful PHP library created by Shaun Simmons which is designed to handle recurrence rules (RRULE) with ease. Whether you’re scheduling weekly reminders, monthly events, or anything in between, Recurr simplifies the complexities of recurring dates so you can focus on building your application.

    To install Recurr use composer.

    composer require simshaun/recurr
    

    Then, in your PHP code, you can instantiate the RecurrRule class:

    $timezone = 'America/Jamaica';
    $startDate = new DateTime('2025-01-1 10:00:00', new DateTimeZone($timezone));
    $endDate = new DateTime('2025-02-12 10:00:00', new DateTimeZone($timezone)); // Optional
    $rule = new RecurrRule('FREQ=WEEKLY;COUNT=6', $startDate, $endDate, $timezone);
    
    echo $rule->getString(); 
    //output: FREQ=WEEKLY;COUNT=6;DTEND=20250212T100000
    

    You can also rewrite the above by chaining methods together for better readability:

    $rule = (new RecurrRule)
        ->setStartDate($startDate)
        ->setTimezone($timezone)
        ->setFreq('WEEKLY')
        ->setCount(6)
        ->setUntil($endDate);
    

    Once you have a recurrence rule, you can take it a step further by transforming it into human-readable text:

    $transformer = new RecurrTransformerTextTransformer();
    echo $transformer->transform($rule);
    //output: weekly on Wednesday for 6 times
    

    If you need the actual PHP DateTime objects representing the recurrence dates, use the ArrayTransformer class along with the getStart() or getEnd() methods:

    $transformer = new RecurrTransformerArrayTransformer();
    $dates = $transformer->transform($rule);
    
    foreach ($dates as $date) {
        echo $date->getStart()->format('Y-m-d H:i:s') . PHP_EOL;
    }
    
    /*
    output:
    
    2025-01-01 10:00:00
    2025-01-08 10:00:00
    2025-01-15 10:00:00
    2025-01-22 10:00:00
    2025-01-29 10:00:00
    2025-02-05 10:00:00
    2025-02-12 10:00:00
    */
    

    You can also specify the days of the week for the recurrence using the setByDay() method:

    $rule = (new RecurrRule)
        ->setStartDate($startDate)
        ->setTimezone($timezone)
        ->setFreq('WEEKLY')
    ->setByDay(['WE','FR'])
        ->setCount(6)
        ->setUntil($endDate);
    
    $transformer = new RecurrTransformerTextTransformer();
    echo $transformer->transform($rule) . PHP_EOL;
    
    //output: weekly on Wednesday and Friday until February 12, 2025
    

    Recurr also provides advanced features like setting constraints to include or exclude specific dates, applying post-transformation filters, and defining custom intervals.

    To explore more about this library and its capabilities, visit the source code on Github.


    The post Recurr is a PHP library for working with recurrence rules for calendar dates appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleGoogle Home APIs now available as public developer beta on Android
    Next Article String Manipulation Made Easy with Laravel’s AsStringable Cast

    Related Posts

    Security

    China-Linked Hackers Exploit SAP and SQL Server Flaws in Attacks Across Asia and Brazil

    May 30, 2025
    Security

    New Apache InLong Vulnerability (CVE-2025-27522) Exposes Systems to Remote Code Execution Risks

    May 30, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    This forgotten Windows 11 feature is about to get some love from Microsoft

    News & Updates

    A new AI-powered weather app is coming to Google Pixel 9 phones

    Development

    Beyond Vulnerability Management – Can You CVE What I CVE?

    Development

    Inside Iran’s Cyber Playbook: AI, Fake Hosting, and Psychological Warfare

    Development

    Highlights

    How to Add a Header to a curl Request

    August 3, 2024

    curl is one of those great utilities that’s been around seemingly forever and has endless…

    CVE-2025-4509 – PHPGurukul e-Diary Management System SQL Injection

    May 10, 2025

    MonetDB is a high performance relational database system for analytics

    April 13, 2025

    Enhance call center efficiency using batch inference for transcript summarization with Amazon Bedrock

    August 21, 2024
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.