def _dt_setter(self, fieldtoset, value, **kwargs): """Always set the date in UTC, saving the timezone in another field. But since the timezone value isn't known at the time of saving the form, we have to save it timezone-naive first and let timezone_handler convert it to the target zone afterwards. """ # Note: The name of the first parameter shouldn't be field, because # it's already in kwargs in some case. if not isinstance(value, DateTime): value = DT(value) # This way, we set DateTime timezoneNaive value = DateTime( "%04d-%02d-%02dT%02d:%02d:%02d" % ( value.year(), value.month(), value.day(), value.hour(), value.minute(), int(value.second()), # No microseconds ) ) self.getField(fieldtoset).set(self, value, **kwargs)
def test_default_start_DT(self): DTS = default_start_DT() DTN = DT(localized_now()) self.assertTrue(DTS.year() == DTN.year() and DTS.month() == DTN.month() and DTS.day() == DTN.day() and DTS.hour() == DTN.hour() and DTS.minute() == DTN.minute())
def test_default_end_DT(self): DTE = default_end_DT() DTN = DT(localized_now() + datetime.timedelta(hours=DEFAULT_END_DELTA)) self.assertTrue(DTE.year() == DTN.year() and DTE.month() == DTN.month() and DTE.day() == DTN.day() and DTE.hour() == DTN.hour() and DTE.minute() == DTN.minute())
def _dt_setter(self, fieldtoset, value, **kwargs): """Always set the date in UTC, saving the timezone in another field. But since the timezone value isn't known at the time of saving the form, we have to save it timezone-naive first and let timezone_handler convert it to the target zone afterwards. """ # Note: The name of the first parameter shouldn't be field, because # it's already in kwargs in some case. if not isinstance(value, DateTime): value = DT(value) # This way, we set DateTime timezoneNaive value = DateTime('%04d-%02d-%02dT%02d:%02d:%02d' % ( value.year(), value.month(), value.day(), value.hour(), value.minute(), int(value.second()) # No microseconds )) self.getField(fieldtoset).set(self, value, **kwargs)