• Recent
    • Unsolved
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    cron-style scheduled task starts on UTC, not local time

    Scheduled Pinned Locked Moved Solved FOG Problems
    9 Posts 2 Posters 8 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      RAThomas
      last edited by

      Problem:

      • I scheduled a task to begin at 15:30 (CDT)
      • The task began at 10:30 (CDT) instead

      Background:

      • I am in US Central time zone (CDT, aka UTC -5)
      • On the FOG server web GUI, in FOG Settings->General Settings “TZ INFO” is set to “America/Chicago [CDT -05:00]”
      • The FOG server is set to use CDT:
      lrwxrwxrwx   1 root root      30 Apr 22 10:16 localtime -> /usr/share/zoneinfo/US/Central
      
      • Time according to my fog server when the above cron scheduled task kicked off:
      root@masterfog-1-5-10:~# date
      Wed Oct 15 10:00:10 AM CDT 2025
      

      My understanding is if a Linux computer’s localtime is set different from UTC, the cron should use the local time automatically.

      Tom ElliottT 1 Reply Last reply Reply Quote 0
      • Tom ElliottT
        Tom Elliott @RAThomas
        last edited by

        @RAThomas Even (slightly) better:

        $GLOBALS['TimeZone'] = $fog_settings[4] ?? (ini_get('date.timezone') ?: 'UTC');
        

        We lose a storage variable (freeing up a tiny bit of memory) and just get the value directly as possible.

        Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

        Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

        Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

        R 1 Reply Last reply Reply Quote 0
        • Tom ElliottT
          Tom Elliott @RAThomas
          last edited by

          @RAThomas So the display time of thigns should follow the TZ Info, but hte /etc/php.ini (or its equivalent) for timezone will need to be set as well as that’s the point the service starts up with.

          Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

          Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

          Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

          R 1 Reply Last reply Reply Quote 0
          • R
            RAThomas @Tom Elliott
            last edited by

            @Tom-Elliott Thank you for pointing me in the right direction. I’ve corrected it for myself, but after looking around in the PHP code, I’d like to ponder a change in defaults/settings priority.

            Right now the FOG timezone selection logic is: If php.ini specifies a timezone (and PHP 8.2 appears to “specify” UTC if there’s nothing explicitly set in php.ini), then use that timezone. Ie, FOG will always use UTC or what is specified in php.ini, and FOG will never use $fogsettings[4].

            I propose (only if my above analysis is correct) that we flip the priority logic to favor $fogsettings[4] timezone setting.

            fogcore.class.php::setEnv() existing logic:

                    $defTz = ini_get('date.timezone');
            
                    if (empty($defTz))
                    {
                        if (empty($fog_settings[4]))
                        {
                            $GLOBALS['TimeZone'] = 'UTC';
                        } else
                        {
                            $GLOBALS['TimeZone'] = $fog_settings[4];
                        }
                    } else
                    {
                        $GLOBALS['TimeZone'] = $defTz;
                    }
            
            

            Proposed logic:

                $defTz = ini_get('date.timezone');
            
                if (empty($fog_settings[4]))
                {
                    if (empty($defTz))
                    {
                        $GLOBALS['TimeZone'] = 'UTC';
                    } else
                    {
                        $GLOBALS['TimeZone'] = $defTz;
                    }
                } else
                {
                    $GLOBALS['TimeZone'] = $fog_settings[4];
                }
            
            R Tom ElliottT 2 Replies Last reply Reply Quote 0
            • R
              RAThomas @RAThomas
              last edited by RAThomas

              @RAThomas screencap showing the above proposed change working correctly (scheduled task above, resulting active task below, shown at ~15:00:10

              Ie. my proposed code change is working for me. My php.ini still does not explicitly set a timezone, but FOG settings does set my CDT timezone.

              FOGschedcorrect.jpg

              1 Reply Last reply Reply Quote 0
              • Tom ElliottT
                Tom Elliott @RAThomas
                last edited by

                @RAThomas What about simplifying the whole stanza?

                I’m not saying I don’t like your suggestions, just that this stanza should effectively do exactly the same thing, just much more simplified.

                $GLOBALS['TimeZone'] = $fog_settings[4] ?? ($defTz ?? 'UTC');
                

                Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                R 1 Reply Last reply Reply Quote 0
                • R
                  RAThomas @Tom Elliott
                  last edited by

                  @Tom-Elliott I do like me some simplification. I will try your suggestion and report back.

                  Tom ElliottT 1 Reply Last reply Reply Quote 0
                  • Tom ElliottT
                    Tom Elliott @RAThomas
                    last edited by

                    @RAThomas Even (slightly) better:

                    $GLOBALS['TimeZone'] = $fog_settings[4] ?? (ini_get('date.timezone') ?: 'UTC');
                    

                    We lose a storage variable (freeing up a tiny bit of memory) and just get the value directly as possible.

                    Please help us build the FOG community with everyone involved. It's not just about coding - way more we need people to test things, update documentation and most importantly work on uniting the community of people enjoying and working on FOG! Get in contact with me (chat bubble in the top right corner) if you want to join in.

                    Web GUI issue? Please check apache error (debian/ubuntu: /var/log/apache2/error.log, centos/fedora/rhel: /var/log/httpd/error_log) and php-fpm log (/var/log/php*-fpm.log)

                    Please support FOG if you like it: https://wiki.fogproject.org/wiki/index.php/Support_FOG

                    R 1 Reply Last reply Reply Quote 0
                    • R
                      RAThomas @Tom Elliott
                      last edited by RAThomas

                      @Tom-Elliott I’ve tested it with a deploy task scheduled for 15:30 and it fired off the active task at 15:30:34, which is a big PASS in my book.

                      Now, are you going to make me do a pull request? 😉

                      PS: I will, pro forma, test your last tweak, but that looks fine too.

                      R 1 Reply Last reply Reply Quote 0
                      • R RAThomas has marked this topic as solved
                      • R
                        RAThomas @RAThomas
                        last edited by RAThomas

                        @RAThomas Confirmed the very last tweak to be working, as expected.

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post

                        157

                        Online

                        12.3k

                        Users

                        17.4k

                        Topics

                        155.8k

                        Posts
                        Copyright © 2012-2025 FOG Project