Last active
          August 27, 2025 18:28 
        
      - 
      
- 
        Save thinkphp/c8165cd495f48d2be4e6736e2f1ac75d to your computer and use it in GitHub Desktop. 
    Est Delivery
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | <?php | |
| function generateDeliveryInterval($minDays = 7, $maxDays = 7, $skipWeekends = true) { | |
| $start = new DateTime(); | |
| // Calculate minimum delivery date (starting tomorrow) | |
| $minDate = clone $start; | |
| $minDate->add(new DateInterval('P1W')); // Start from tomorrow P1Y , P2M PT5H | |
| // Calculate maximum delivery date | |
| $maxDate = clone $start; | |
| if ( $skipWeekends ) { | |
| // Add business days only | |
| $daysAdded = 0; | |
| while ($daysAdded < $maxDays) { | |
| $maxDate->add(new DateInterval('P1D')); | |
| if ($maxDate->format('N') < 4) { // Monday = 1, Sunday = 7 | |
| $daysAdded++; | |
| } | |
| } | |
| } else { | |
| $maxDate->add(new DateInterval('P' . $maxDays . 'D')); | |
| } | |
| // Format dates - show day and date | |
| $minFormatted = $minDate->format('D, j'); // Thu, 27 | |
| $maxFormatted = $maxDate->format('D, M j'); // Thu, Sep 9 | |
| return "Est. delivery " . $minFormatted . " - " . $maxFormatted; | |
| } | |
| ?> | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment