def test_system_time_hybrid(self, time_mock): """Test we do timezone math properly when setting system time to a mix of "now" and explicit values, in and out of daylight savings. We use 12pm as 12pm UTC is on the same date in each tested timezone. """ isys.set_system_date_time(None, None, None, 19, 15, 30) time_mock.assert_called_with(1609528530) isys.set_system_date_time( None, None, None, 19, 15, 30, tz=zoneinfo.ZoneInfo(key="US/Eastern") ) time_mock.assert_called_with(1609546530) with freeze_time("2021-06-01 12:00:00"): isys.set_system_date_time( None, None, None, 19, 15, 30, tz=zoneinfo.ZoneInfo(key="US/Eastern") ) time_mock.assert_called_with(1622589330) isys.set_system_date_time( None, None, None, 19, 15, 30, tz=zoneinfo.ZoneInfo(key="Asia/Kolkata") ) time_mock.assert_called_with(1609508730) isys.set_system_date_time( None, None, None, 19, 15, 30, tz=zoneinfo.ZoneInfo(key="Asia/Aden") ) time_mock.assert_called_with(1609517730)
def test_system_time_explicit(self, time_mock): """Test we do timezone math properly when setting system time to explicit values, in and out of daylight savings. """ isys.set_system_date_time(2020, 1, 1, 0, 0, 0) time_mock.assert_called_with(1577836800) isys.set_system_date_time(2020, 1, 1, 0, 0, 0, tz=zoneinfo.ZoneInfo(key="US/Eastern")) time_mock.assert_called_with(1577854800) isys.set_system_date_time(2020, 6, 1, 0, 0, 0, tz=zoneinfo.ZoneInfo(key="US/Eastern")) time_mock.assert_called_with(1590984000) isys.set_system_date_time(2020, 1, 1, 0, 0, 0, tz=zoneinfo.ZoneInfo(key="Asia/Kolkata")) time_mock.assert_called_with(1577817000) isys.set_system_date_time(2020, 1, 1, 0, 0, 0, tz=zoneinfo.ZoneInfo(key="Asia/Aden")) time_mock.assert_called_with(1577826000)
def _save_system_time(self): """ Returning False from this method removes the timer that would otherwise call it again and again. """ self._start_updating_timer_id = None if not flags.can_touch_runtime_system("save system time"): return False month = self._get_combo_selection(self._monthCombo)[0] if not month: return False year = self._get_combo_selection(self._yearCombo)[0] if not year: return False hours = int(self._hoursLabel.get_text()) if not self._radioButton24h.get_active(): hours = self._to_24h(hours, self._amPmLabel.get_text()) minutes = int(self._minutesLabel.get_text()) day = self._get_combo_selection(self._dayCombo)[0] #day may be None if there is no such in the selected year and month if day: isys.set_system_date_time(year, month, day, hours, minutes, tz=self._tz) #start the timer only when the spoke is shown if self._shown and not self._update_datetime_timer_id: self._update_datetime_timer_id = GLib.timeout_add_seconds( 1, self._update_datetime) #run only once (after first 2 seconds of inactivity) return False
def test_system_time_now(self, time_mock): """Test we do timezone math properly when setting system time to "now". 1609459200 is 00:00:00 on 2021-01-01; with time frozen to that point, whatever timezone we call the function with, it should end up with that number. We also test 2021-06-01 (with the appropriate expected result) for zones which do DST, as that date is during daylight savings. """ # default tz (UTC) isys.set_system_date_time() time_mock.assert_called_with(1609459200) isys.set_system_date_time(tz=zoneinfo.ZoneInfo(key="US/Eastern")) time_mock.assert_called_with(1609459200) with freeze_time("2021-06-01"): isys.set_system_date_time(tz=zoneinfo.ZoneInfo(key="US/Eastern")) time_mock.assert_called_with(1622505600) isys.set_system_date_time(tz=zoneinfo.ZoneInfo(key="Asia/Kolkata")) time_mock.assert_called_with(1609459200) isys.set_system_date_time(tz=zoneinfo.ZoneInfo(key="Asia/Aden")) time_mock.assert_called_with(1609459200)
def _save_system_time(self): """ Returning False from this method removes the timer that would otherwise call it again and again. """ if not flags.can_touch_runtime_system("save system time"): return False month = self._get_combo_selection(self._monthCombo) if not month: return False month = self._months_nums[month] year_str = self._get_combo_selection(self._yearCombo) if not year_str: return False year = int(year_str) hours = int(self._hoursLabel.get_text()) if not self._radioButton24h.get_active(): hours = self._to_24h(hours, self._amPmLabel.get_text()) minutes = int(self._minutesLabel.get_text()) day = self._get_combo_selection(self._dayCombo) #day may be None if there is no such in the selected year and month if day: day = int(day) isys.set_system_date_time(year, month, day, hours, minutes) #start the timer only when the spoke is shown if self._update_datetime_timer_id is not None: self._update_datetime_timer_id = GLib.timeout_add_seconds(1, self._update_datetime) #run only once (after first 2 seconds of inactivity) return False
def _save_system_time(self): """ Returning False from this method removes the timer that would otherwise call it again and again. """ self._start_updating_timer = None if not conf.system.can_set_system_clock: return False month = self._get_combo_selection(self._monthCombo)[0] if not month: return False year = self._get_combo_selection(self._yearCombo)[0] if not year: return False hours = int(self._hoursLabel.get_text()) if not self._radioButton24h.get_active(): hours = self._to_24h(hours, self._amPmLabel.get_text()) minutes = int(self._minutesLabel.get_text()) day = self._get_combo_selection(self._dayCombo)[0] #day may be None if there is no such in the selected year and month if day: isys.set_system_date_time(year, month, day, hours, minutes, tz=self._tz) #start the timer only when the spoke is shown if self._shown and not self._update_datetime_timer: self._update_datetime_timer = Timer() self._update_datetime_timer.timeout_sec(1, self._update_datetime) #run only once (after first 2 seconds of inactivity) return False