def get_initial(self, *args, **kwargs): data = super().get_initial(*args, **kwargs) consultants = self.get_object().members.consultants() data['consultants'] = consultants data['start_at'] = localize_date( self.get_object().start_at, time_zone=self.get_project().timezone).strftime( '%Y-%m-%d %H:%M:%S') data['end_at'] = localize_date( self.get_object().end_at, time_zone=self.get_project().timezone).strftime( '%Y-%m-%d %H:%M:%S') return data
def test_timezone_conversions_timezone(self): """ Test date transformation to differents TimeZones """ today_no_utc = datetime.today() self.assertIsNone(today_no_utc.tzinfo) localized_date = localize_date(today_no_utc) self.assertEqual(localized_date.tzinfo, pytz.utc) # Date with timezone info today_utc = dj_timezone.now() self.assertIsNotNone(today_utc.tzinfo) localized_date = localize_date(today_utc) self.assertEqual( localized_date.tzinfo, today_utc.tzinfo, )
def get_initial(self, *args, **kwargs): settings = self.get_project().settings initial = { 'send_welcome_consultant': settings.launch['send_welcome_consultant'], 'send_welcome_participant': settings.launch['send_welcome_participant'], 'fix_password': settings.launch['fix_password'], } if self.get_project().start: project = self.get_project() initial['start'] = localize_date( project.start, time_zone=project.timezone).strftime('%Y-%m-%d %H:%M:%S') return initial
def validate_date(self, date): return localize_date(date, self.instance.timezone)
def end_tz(self): return localize_date(self.end, time_zone=self.project.timezone) if self.end else None
def start_tz(self): return localize_date(self.start, time_zone=self.project.timezone) if self.start else None
def end_localize(self): return localize_date(self.end, self.timezone) if self.end else ''
def start_localize(self): return localize_date(self.start, self.timezone) if self.start else ''
def test_timezone_conversion_to_city_timezone(self): """ Test timezone conversion to city timezone """ time_format = '%H:%M:%S' date_format = '%d/%m/%Y' FMT = '{} {}'.format(date_format, time_format) # Test with America Timezone washington_DC_timezone = 'America/New_York' # UTC -5 city_timezone = string_to_timezone(washington_DC_timezone) used_time = '10:30:00' washington_time = '06:30:00' used_date = '20/10/2017' date_no_utc = datetime.strptime('{} {}'.format(used_date, used_time), FMT) date_utc = localize_date(date_no_utc) date_relative_city = localize_date(date=date_utc, time_zone=city_timezone) diff = date_utc - date_relative_city self.assertEqual(diff.days, 0) self.assertEqual(diff.total_seconds(), 0.0) self.assertEqual( date_utc.strftime(time_format), used_time, ) self.assertEqual( date_utc.strftime(date_format), used_date, ) self.assertEqual( date_relative_city.strftime(time_format), washington_time, ) self.assertEqual( date_relative_city.strftime(date_format), used_date, ) # Test with Asia Timezone city_timezone = string_to_timezone('Asia/Dubai') # UTC+4 used_time = '23:00:00' used_date = '20/10/2017' abu_dhabi_time = '03:00:00' abu_dhabi_date = '21/10/2017' date_no_utc = datetime.strptime('{} {}'.format(used_date, used_time), FMT) date_utc = localize_date(date_no_utc) date_relative_city = localize_date(date=date_utc, time_zone=city_timezone) self.assertEqual( date_utc.strftime(time_format), used_time, ) self.assertEqual( date_utc.strftime(date_format), used_date, ) self.assertEqual( date_relative_city.strftime(time_format), abu_dhabi_time, ) self.assertEqual( date_relative_city.strftime(date_format), abu_dhabi_date, ) # Test with Asia Timezone and Los Angeles city_abu_dhabi_timezone = string_to_timezone('Asia/Dubai') # UTC+4 city_california_timezone = string_to_timezone( 'America/Los_Angeles') # UTC -8 abu_dhabi_time = '03:00:00' abu_dhabi_date = '23/08/2017' california_time = '16:00:00' california_date = '22/08/2017' date_no_utc = datetime.strptime( '{} {}'.format(abu_dhabi_date, abu_dhabi_time), FMT) date_abu_dhabi = localize_date( date=date_no_utc, time_zone=city_abu_dhabi_timezone, ) date_california = localize_date( date=date_abu_dhabi, time_zone=city_california_timezone, ) self.assertEqual( date_abu_dhabi.strftime(time_format), abu_dhabi_time, ) self.assertEqual( date_abu_dhabi.strftime(date_format), abu_dhabi_date, ) self.assertEqual( date_california.strftime(time_format), california_time, ) self.assertEqual( date_california.strftime(date_format), california_date, )