How do I fix All-Day Calendar events from shifting 1 hour during day light savings?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nocstaff@urbancom.net
    Member
    • Jul 2025
    • 80

    #1

    How do I fix All-Day Calendar events from shifting 1 hour during day light savings?

    I am custom making a repeating calendar events option, but discovered any repeating meetings or jobs I make that exists after November 1st gets shifted from 12am-12pm to 11am-11pm, making the item appear to last 2 days on the calendar. I tried everything to fix it but I just can't figure it out. How can I adjust this?


    Here is the code I made in the new hook I made /var/www/espocrm/data/espocrm/custom/Espo/Custom/Hooks/Common/RecurringBase.php:

    PHP Code:
    <?php
    namespace Espo\Custom\Hooks\Common;
    use 
    Espo\ORM\Entity;
    use 
    Espo\Core\Hook\Hook\AfterSave;
    use 
    Espo\ORM\EntityManager;
    use 
    Espo\ORM\Repository\Option\SaveOptions;
    class 
    RecurringBase implements AfterSave
    {
        protected 
    EntityManager $em;
        public function 
    __construct(EntityManager $em)
        {
            
    $this->em $em;
        }
        public function 
    afterSave(Entity $entitySaveOptions $options): void
        
    {
            if (!
    $entity->get('repeat') || $options->get('isRecurringChild') === true) {
                return;
            }
            
    $startDate = new \DateTime($entity->get('dateStart'));
            
    $endDate   = new \DateTime($entity->get('dateEnd'));
            
    $until     $entity->get('repeatUntil') ? new \DateTime($entity->get('repeatUntil')) : null;
            
    $interval  = (int) $entity->get('repeatInterval') ?: 1;
            
    $repeat    $entity->get('repeat');
            
    $count 0;
            
    $max   200;
            while (
    true) {
                
    $count++;
                
    $newStart = (clone $startDate);
                
    $newEnd   = (clone $endDate);
                switch (
    $repeat) {
                    case 
    'Daily':
                        
    $newStart->modify("+{$interval} days");
                        
    $newEnd->modify("+{$interval} days");
                        break;
                    case 
    'Weekly':
                        
    $newStart->modify("+{$interval} weeks");
                        
    $newEnd->modify("+{$interval} weeks");
                        break;
                    case 
    'Monthly':
                        
    $newStart->modify("+{$interval} months");
                        
    $newEnd->modify("+{$interval} months");
                        break;
                    default:
                        return;
                }
                if (
    $until && $newStart $until) {
                    break;
                }
                
    $duplicate $this->em->getEntityFactory()->create($entity->getEntityType());
                foreach ([
                    
    'name','description','status',
                    
    'assignedUserId','teamsIds',
                    
    'parentId','parentType',
                    
    'allDay','reminders'
                
    ] as $f) {
                    if (
    $entity->has($f)) {
                        
    $duplicate->set($f$entity->get($f));
                    }
                }
                
    $duplicate->set('dateStart'$newStart->format('Y-m-d H:i:s'));
                
    $duplicate->set('dateEnd',   $newEnd->format('Y-m-d H:i:s'));
                
    $duplicate->set('repeat'null);
                
    $duplicate->set('repeatInterval'null);
                
    $duplicate->set('repeatUntil'null);
                
    $this->em->saveEntity($duplicate, ['isRecurringChild' => true]);
                if (
    $count >= $max) {
                    break;
                }
                
    $startDate $newStart;
                
    $endDate   $newEnd;
            }
        }
    }

    Click image for larger version  Name:	image.png Views:	0 Size:	25.2 KB ID:	121795
    Last edited by nocstaff@urbancom.net; 10-01-2025, 04:32 PM.
Working...