def test_get_localized_time_constraints(self): """Test the constraints for get_localized_time.""" # When no parameters are given an error is raised from plone.api.exc import MissingParameterError with self.assertRaises(MissingParameterError): portal.get_localized_time()
def test_get_localized_time(self): """Test getting the localized time.""" from plone.api.exc import InvalidParameterError # set the expected localized date format name_root = "Products.CMFPlone.i18nl10n.override_dateformat." try: portal.set_registry_record(name=name_root + "Enabled", value=True) portal.set_registry_record(name=name_root + "date_format_long", value="%b %d, %Y %I:%M %p") portal.set_registry_record(name=name_root + "time_format", value="%I:%M %p") portal.set_registry_record(name=name_root + "date_format_short", value="%b %d, %Y") except InvalidParameterError: # before Plone 4.3, date formats were stored in portal_properties properties = portal.get_tool("portal_properties") properties.localLongTimeFormat = "%b %d, %Y %I:%M %p" properties.localTimeOnlyFormat = "%I:%M %p" properties.localTimeFormat = "%b %d, %Y" # tests result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59), long_format=True) self.assertEqual(result, "Dec 31, 1999 11:59 PM") result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59), time_only=True) self.assertEqual(result, "11:59 PM") result = portal.get_localized_time(datetime=DateTime(1999, 12, 31, 23, 59)) self.assertEqual(result, "Dec 31, 1999")
def test_document_report(self, browser): browser.login().open(view='document_report', data={'paths:list': [ '/'.join(self.document.getPhysicalPath()), ]}) with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmpfile: tmpfile.write(browser.contents) tmpfile.flush() workbook = load_workbook(tmpfile.name) self.assertSequenceEqual( [ u'Client1 / 1 / 1', 1L, u'Testdokum\xe4nt', u'Mustermann Max', get_localized_time(self.document_date), get_localized_time(self.receipt_date), get_localized_time(self.delivery_date), Actor.lookup(TEST_USER_ID).get_label(), u'unchecked', u'Dossier A', ], [cell.value for cell in workbook.active.rows[1]])
def test_get_localized_time(self): result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999 11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), time_only=True, ) self.assertEqual(result, '11:59 PM') result = portal.get_localized_time(datetime=DateTime( 1999, 12, 31, 23, 59), ) self.assertEqual(result, 'Dec 31, 1999')
def test_get_localized_time(self): """Test getting the localized time.""" from plone.api.exc import InvalidParameterError # set the expected localized date format name_root = 'Products.CMFPlone.i18nl10n.override_dateformat.' try: portal.set_registry_record( name=name_root + 'Enabled', value=True, ) portal.set_registry_record( name=name_root + 'date_format_long', value='%b %d, %Y %I:%M %p', ) portal.set_registry_record( name=name_root + 'time_format', value='%I:%M %p', ) portal.set_registry_record( name=name_root + 'date_format_short', value='%b %d, %Y', ) except InvalidParameterError: # before Plone 4.3, date formats were stored in portal_properties properties = portal.get_tool('portal_properties') properties.localLongTimeFormat = '%b %d, %Y %I:%M %p' properties.localTimeOnlyFormat = '%I:%M %p' properties.localTimeFormat = '%b %d, %Y' # tests result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999 11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), time_only=True, ) self.assertEqual(result, '11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), ) self.assertEqual(result, 'Dec 31, 1999')
def getAccomadationDates(self): start = self.accomadation_start end = self.accomadation_end options = [] dates = daterange(start, end + timedelta(days=1) ) for single_date in dates: options.append(get_localized_time(single_date)) return options
def test_get_localized_time(self): result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999 11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), time_only=True, ) self.assertEqual(result, '11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), ) self.assertEqual(result, 'Dec 31, 1999')
def get_publication_date(self, brain): date = brain.effective if date.year() == 1969: return '' # date = obj.effective_date return portal.get_localized_time(datetime=date).encode('utf-8')
def test_get_localized_time_python_date(self): """Test getting the localized time using Python datetime.date.""" # set the expected localized date format self._set_localization_date_format() # tests result = portal.get_localized_time( datetime=date(1999, 12, 31), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999') result = portal.get_localized_time( datetime=date(1999, 12, 31), time_only=True, ) self.assertEqual(result, '') result = portal.get_localized_time(datetime=date(1999, 12, 31), ) self.assertEqual(result, 'Dec 31, 1999')
def test_get_localized_time(self): """Test getting the localized time.""" # set the expected localized date format self._set_localization_date_format() # tests result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999 11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), time_only=True, ) self.assertEqual(result, '11:59 PM') result = portal.get_localized_time(datetime=DateTime( 1999, 12, 31, 23, 59), ) self.assertEqual(result, 'Dec 31, 1999')
def test_get_localized_time(self): """Test getting the localized time.""" # set the expected localized date format self._set_localization_date_format() # tests result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999 11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), time_only=True, ) self.assertEqual(result, '11:59 PM') result = portal.get_localized_time( datetime=DateTime(1999, 12, 31, 23, 59), ) self.assertEqual(result, 'Dec 31, 1999')
def test_get_localized_time_python_date(self): """Test getting the localized time using Python datetime.date.""" # set the expected localized date format self._set_localization_date_format() # tests result = portal.get_localized_time( datetime=date(1999, 12, 31), long_format=True, ) self.assertEqual(result, 'Dec 31, 1999') result = portal.get_localized_time( datetime=date(1999, 12, 31), time_only=True, ) self.assertEqual(result, '') result = portal.get_localized_time( datetime=date(1999, 12, 31), ) self.assertEqual(result, 'Dec 31, 1999')
def test_document_report(self, browser): browser.login().open( view='document_report', data={'paths:list': [ '/'.join(self.document.getPhysicalPath()), ]}) with NamedTemporaryFile(delete=False, suffix='.xlsx') as tmpfile: tmpfile.write(browser.contents) tmpfile.flush() workbook = load_workbook(tmpfile.name) self.assertSequenceEqual([ u'Client1 / 1 / 1', 1L, u'Testdokum\xe4nt', u'Mustermann Max', get_localized_time(self.document_date), get_localized_time(self.receipt_date), get_localized_time(self.delivery_date), Actor.lookup(TEST_USER_ID).get_label(), u'unchecked', u'Dossier A', ], [cell.value for cell in list(workbook.active.rows)[1]])
def get_event_date(self, obj): start = obj.startDate end = obj.endDate if start.year() == end.year(): if start.month() == end.month(): if start.day() == end.day(): return get_localized_time(start) else: return u"{0} - {1}".format( get_localized_time(start).split()[0], get_localized_time(end)) else: front_date = re.sub(str(start.year()), '', get_localized_time(start)) return u"{0} - {1}".format(front_date, get_localized_time(end)) return u'{0} - {1}'.format(get_localized_time(start), get_localized_time(end))
def city_modified(self): return portal.get_localized_time(self.context.modified())
def formated_date(self, modifiedTime): modif_date = portal.get_localized_time(datetime=modifiedTime) return modif_date
def _get_text(self, value): return portal.get_localized_time(datetime=value)
def readable_date(date): """Helper method to return a localized date""" return get_localized_time(date) if date else None