Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1

Birthday announcements appearing in wrong time zone

This discussion is related to the Birthday Module addon.

I realize this plugin hasn't been updated in many years, but I'm not sure if this is a problem with the plugin, or my configuration.

For some reason the birthday announcements are appearing at 4PM my time, or midnight in Dubai (!)

My site's Guest Time Zone is set to NYC:
$Configuration['Garden']['GuestTimeZone'] = 'America/New_York';

This works as advertised; if I log out I see posts in my time zone.

And I think I see this plugin looks for that setting (I'm not a php programmer by any means)
https://github.com/bleistivt/BirthdayModule/blob/master/class.birthdaymodule.php

does anyone have any ideas why?

PS: I just noticed that Dubai is +04:00UTC, while New York is -04:00UTC. May be relevant?

Comments

  • thanks @vrijvlinder I have the Guest Time Zone set correctly for NYC. I am wondering why this plugin is not respecting that. Sorry I wasn't more clear.

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    Is it set correctly according to UTC ?

    New York is -04:00UTC this is correct, because you subtract 4 hours from your current time but that can change during daylight savings ... so it would be -5:00UTC .

    http://24timezones.com/world_directory/time_in_new_york.php

    Whenever you modify a plugin whether it is via settings page or hardcode, it is a good idea to carefully delete the .ini files in the cache.

    Another thing that can affect what time you see when logged in or not, are session cookies.

    This plugin as far as I can see within the code, checks for time and guest time based on your settings.

  • I have the guest time zone set in conf.php to this:
    $Configuration['Garden']['GuestTimeZone'] = 'America/New_York';

    I don't want to use a straight UTC code, because like you say that changes during the year.

    I haven't modified the plugin. Are you suggesting I do?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    If you look at the plugin's module file, you can see how this is implemented. Your time is correct as a guest. But you claim that it is not correct as a logged in .. so that configuration only affects how guests see it and not your solution to the issue that when you log in it's wrong time.

    I suggest you try using the UTC

    UTC/GMT -4 hour or USA/New York for the forum setting, because your issue looks like a forum setting and not related to this plugin alone.

    <?php if (!defined('APPLICATION')) exit();
    
    class BirthdayModule extends Gdn_Module {
    
        public function AssetTarget() {
            return 'Panel';
        }
    
        protected function GetBirthdays() {
            $Birthdays = json_decode(Gdn::Get('BirthdayModule.Birthdays'));
            if ($Birthdays && $Birthdays[0] == date('y-m-d/H')) {
                return $Birthdays[1];
            }
            $GuestTimeZone = C('Garden.GuestTimeZone');
            $Date = new DateTime();
            if ($GuestTimeZone) {
                try {
                    $TimeZone = new DateTimeZone($GuestTimeZone);
                    $HourOffset = $TimeZone->getOffset(new DateTime('now', new DateTimeZone('UTC')));
                    $HourOffset = - floor($HourOffset / 3600);
                    $Date->modify("$HourOffset hours");
                } catch (Exception $e) {}
            }
            $Px = Gdn::Database()->DatabasePrefix;
            $Birthdays = Gdn::SQL()
                ->Select('UserID')
                ->From('User')
                ->Where("DATE_FORMAT(DateOfBirth, '%m-%d')", $Date->format("'m-d'"), false, false)
                ->Get()
                ->Result(DATASET_TYPE_ARRAY);
            $Birthdays = ConsolidateArrayValuesByKey($Birthdays, 'UserID');
            Gdn::Set('BirthdayModule.Birthdays', json_encode(array(date('y-m-d/H'), $Birthdays)));
            return $Birthdays;
        }
    
        public function ToString() {
            $Birthdays = $this->GetBirthdays();
            if (empty($Birthdays)) {
                return;
            }
            Gdn::UserModel()->GetIDs($Birthdays);
            $Return = '<div class="Box BirthdayModule"><h4>'
                .Plural(count($Birthdays), T("Today's Birthday"), T("Today's Birthdays"))
                .'</h4><p>';
            foreach ($Birthdays as $Birthday) {
                $Return .= UserPhoto(Gdn::UserModel()->GetID($Birthday), 'Medium').' ';
            }
            $Return .= '</p></div>';
            return $Return;
        }
    
    }
    
Sign In or Register to comment.