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

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 29, 2025

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

      May 29, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 29, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 29, 2025

      Gemini can now watch Google Drive videos for you – including work meetings

      May 29, 2025

      LG is still giving away a free 27-inch gaming monitor, but you’ll have to hurry

      May 29, 2025

      Slow Roku TV? This 30-second fix made my system run like new again

      May 29, 2025

      Hume’s new EVI 3 model lets you customize AI voices – how to try it

      May 29, 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

      Your Agentforce Readiness Assessment

      May 29, 2025
      Recent

      Your Agentforce Readiness Assessment

      May 29, 2025

      Introducing N|Sentinel: Your AI-Powered Agent for Node.js Performance Optimization

      May 29, 2025

      FoalTS framework – version 5 is released

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

      KB5058499 finally makes Windows 11 24H2 stable for gaming, and it wasn’t Nvidia’s fault

      May 29, 2025
      Recent

      KB5058499 finally makes Windows 11 24H2 stable for gaming, and it wasn’t Nvidia’s fault

      May 29, 2025

      Transform Your Workflow With These 10 Essential Yet Overlooked Linux Tools You Need to Try

      May 29, 2025

      KNOPPIX is a bootable Live system

      May 29, 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

    Development

    How to Build an AI-Powered Cooking Assistant with Flutter and Gemini

    May 29, 2025
    Development

    Learn Python for Data Science – Full Course for Beginners

    May 29, 2025
    Leave A Reply Cancel Reply

    Hostinger

    Continue Reading

    Top Tableau Books to Read in 2024

    Development

    Valiantys Shares Expanded AI Capabilities for Empowering Next-Generation Software Development at Team 25

    Tech & Work

    PHP 8.4 Alpha 1 is now out!

    Development

    Are tariffs about to make your next iPhone way more expensive? It’s complicated

    News & Updates
    Hostinger

    Highlights

    Machine Learning in Linux: Stability Matrix – Package Manager for Stable Diffusion

    March 19, 2025

    Stability Matrix is a multi-platform package manager and inference UI for AI image generation. The…

    Top JavaScript Frameworks and Libraries to Watch in 2025

    January 1, 2025

    This AI Paper Explores Long Chain-of-Thought Reasoning: Enhancing Large Language Models with Reinforcement Learning and Supervised Fine-Tuning

    February 11, 2025

    Where Is the Line Between Identifying Client’s Needs and Interrogating?

    March 16, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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