#2896: Remove sugar.date module.
This commit is contained in:
		
							parent
							
								
									382910b0ba
								
							
						
					
					
						commit
						07107fb81b
					
				
							
								
								
									
										2
									
								
								NEWS
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								NEWS
									
									
									
									
									
								
							| @ -1,3 +1,5 @@ | |||||||
|  | * #2896: Remove sugar.date module. (tomeu) | ||||||
|  | 
 | ||||||
| Snapshot 0b3f687749 | Snapshot 0b3f687749 | ||||||
| 
 | 
 | ||||||
| * #3088: Fix style of zoom buttons palettes. (marco) | * #3088: Fix style of zoom buttons palettes. (marco) | ||||||
|  | |||||||
| @ -3,7 +3,6 @@ SUBDIRS = activity clipboard graphics objects presence datastore | |||||||
| sugardir = $(pythondir)/sugar | sugardir = $(pythondir)/sugar | ||||||
| sugar_PYTHON =		\
 | sugar_PYTHON =		\
 | ||||||
| 	__init__.py	\
 | 	__init__.py	\
 | ||||||
| 	date.py		\
 |  | ||||||
| 	env.py		\
 | 	env.py		\
 | ||||||
| 	logger.py	\
 | 	logger.py	\
 | ||||||
|         ltihooks.py	\
 |         ltihooks.py	\
 | ||||||
|  | |||||||
| @ -1,57 +0,0 @@ | |||||||
| """Simple date-representation model""" |  | ||||||
| 
 |  | ||||||
| # Copyright (C) 2006-2007, Red Hat, Inc. |  | ||||||
| # |  | ||||||
| # This library is free software; you can redistribute it and/or |  | ||||||
| # modify it under the terms of the GNU Lesser General Public |  | ||||||
| # License as published by the Free Software Foundation; either |  | ||||||
| # version 2 of the License, or (at your option) any later version. |  | ||||||
| # |  | ||||||
| # This library is distributed in the hope that it will be useful, |  | ||||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |  | ||||||
| # Lesser General Public License for more details. |  | ||||||
| # |  | ||||||
| # You should have received a copy of the GNU Lesser General Public |  | ||||||
| # License along with this library; if not, write to the |  | ||||||
| # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |  | ||||||
| # Boston, MA 02111-1307, USA. |  | ||||||
| 
 |  | ||||||
| import datetime |  | ||||||
| 
 |  | ||||||
| class Date(object): |  | ||||||
|     """Date-object storing a simple time.time() float |  | ||||||
| 
 |  | ||||||
|        Useful to display dates in the UI in an |  | ||||||
|        abbreviated and easy to read format. |  | ||||||
|     """ |  | ||||||
|     def __init__(self, timestamp): |  | ||||||
|         """Initialise via a timestamp (floating point value)""" |  | ||||||
|         self._today = datetime.date.today() |  | ||||||
|         self._timestamp = timestamp |  | ||||||
| 
 |  | ||||||
|     def __str__(self): |  | ||||||
|         """Produce a formatted date representation |  | ||||||
|          |  | ||||||
|         Eventually this should produce a localised version  |  | ||||||
|         of the date.  At the moment it always produces English |  | ||||||
|         dates in long form with Today and Yesterday  |  | ||||||
|         special-cased and dates from this year not presenting |  | ||||||
|         the year in the date. |  | ||||||
|         """ |  | ||||||
|         date = datetime.date.fromtimestamp(self._timestamp) |  | ||||||
| 
 |  | ||||||
|         # FIXME localization |  | ||||||
|         if date == self._today: |  | ||||||
|             result = 'Today' |  | ||||||
|         elif date == self._today - datetime.timedelta(1): |  | ||||||
|             result = 'Yesterday' |  | ||||||
|         elif date.year == self._today.year: |  | ||||||
|             result = date.strftime('%B %d') |  | ||||||
|         else: |  | ||||||
|             result = date.strftime('%B %d, %Y') |  | ||||||
| 
 |  | ||||||
|         time = datetime.datetime.fromtimestamp(self._timestamp) |  | ||||||
|         result = result + ', ' + time.strftime('%I:%M %p') |  | ||||||
| 
 |  | ||||||
|         return result |  | ||||||
| @ -17,6 +17,7 @@ | |||||||
| 
 | 
 | ||||||
| import logging | import logging | ||||||
| import time | import time | ||||||
|  | from gettext import gettext as _ | ||||||
| 
 | 
 | ||||||
| import gtk | import gtk | ||||||
| import hippo | import hippo | ||||||
| @ -31,6 +32,9 @@ from sugar.datastore import datastore | |||||||
| from sugar import activity | from sugar import activity | ||||||
| from sugar.objects import objecttype | from sugar.objects import objecttype | ||||||
| 
 | 
 | ||||||
|  | # TODO: Activities should request the Journal to open objectchooser dialogs. In | ||||||
|  | # that way, we'll be able to reuse most of this code inside the Journal. | ||||||
|  | 
 | ||||||
| class ObjectChooser(gtk.Dialog): | class ObjectChooser(gtk.Dialog): | ||||||
|     def __init__(self, title=None, parent=None, flags=0): |     def __init__(self, title=None, parent=None, flags=0): | ||||||
|         gtk.Dialog.__init__(self, title, parent, flags, (gtk.STOCK_CANCEL, |         gtk.Dialog.__init__(self, title, parent, flags, (gtk.STOCK_CANCEL, | ||||||
| @ -156,8 +160,7 @@ class CollapsedEntry(CanvasRoundBox): | |||||||
| 
 | 
 | ||||||
|     def _format_date(self): |     def _format_date(self): | ||||||
|         """ Convert from a string in iso format to a more human-like format. """ |         """ Convert from a string in iso format to a more human-like format. """ | ||||||
|         ti = time.strptime(self.jobject.metadata['mtime'], "%Y-%m-%dT%H:%M:%S")         |         return _get_elapsed_string(self.jobject.metadata['mtime']) | ||||||
|         return str(Date(time.mktime(ti))) |  | ||||||
| 
 | 
 | ||||||
|     def _format_title(self): |     def _format_title(self): | ||||||
|         return '"%s"' % self.jobject.metadata['title'] |         return '"%s"' % self.jobject.metadata['title'] | ||||||
| @ -169,3 +172,39 @@ class CollapsedEntry(CanvasRoundBox): | |||||||
|         else: |         else: | ||||||
|             self.props.border_color = style.COLOR_BLACK.get_int() |             self.props.border_color = style.COLOR_BLACK.get_int() | ||||||
|             self.props.background_color = style.COLOR_PANEL_GREY.get_int() |             self.props.background_color = style.COLOR_PANEL_GREY.get_int() | ||||||
|  | 
 | ||||||
|  | def _get_elapsed_string(date_string, max_levels=2): | ||||||
|  |     ti = time.strptime(date_string, "%Y-%m-%dT%H:%M:%S") | ||||||
|  | 
 | ||||||
|  |     units = [[_('%d year'),   _('%d years'),   356 * 24 * 60 * 60], | ||||||
|  |              [_('%d month'),  _('%d months'),  30 * 24 * 60 * 60], | ||||||
|  |              [_('%d week'),   _('%d weeks'),   7 * 24 * 60 * 60], | ||||||
|  |              [_('%d day'),    _('%d days'),    24 * 60 * 60], | ||||||
|  |              [_('%d hour'),   _('%d hours'),   60 * 60], | ||||||
|  |              [_('%d minute'), _('%d minutes'), 60], | ||||||
|  |              [_('%d second'), _('%d seconds'), 1]] | ||||||
|  |     levels = 0 | ||||||
|  |     result = '' | ||||||
|  |     elapsed_seconds = int(time.time() - time.mktime(ti)) | ||||||
|  |     for name_singular, name_plural, factor in units: | ||||||
|  |         elapsed_units = elapsed_seconds / factor | ||||||
|  |         if elapsed_units > 0: | ||||||
|  | 
 | ||||||
|  |             if levels > 0: | ||||||
|  |                 if max_levels - levels == 1: | ||||||
|  |                     result += _(' and ') | ||||||
|  |                 else: | ||||||
|  |                     result += _(', ') | ||||||
|  |                  | ||||||
|  |             if elapsed_units == 1: | ||||||
|  |                 result += name_singular % elapsed_units | ||||||
|  |             else: | ||||||
|  |                 result += name_plural % elapsed_units | ||||||
|  |             elapsed_seconds -= elapsed_units * factor | ||||||
|  |             levels += 1 | ||||||
|  |              | ||||||
|  |             if levels == max_levels: | ||||||
|  |                 break | ||||||
|  | 
 | ||||||
|  |     return result | ||||||
|  | 
 | ||||||
|  | |||||||
| @ -17,14 +17,12 @@ | |||||||
| 
 | 
 | ||||||
| import unittest | import unittest | ||||||
| 
 | 
 | ||||||
| import test_date |  | ||||||
| import test_mime | import test_mime | ||||||
| 
 | 
 | ||||||
| runner = unittest.TextTestRunner() | runner = unittest.TextTestRunner() | ||||||
| loader = unittest.TestLoader() | loader = unittest.TestLoader() | ||||||
| 
 | 
 | ||||||
| suite = unittest.TestSuite() | suite = unittest.TestSuite() | ||||||
| suite.addTest(loader.loadTestsFromModule(test_date)) |  | ||||||
| suite.addTest(loader.loadTestsFromModule(test_mime)) | suite.addTest(loader.loadTestsFromModule(test_mime)) | ||||||
| 
 | 
 | ||||||
| runner.run(suite) | runner.run(suite) | ||||||
|  | |||||||
| @ -1,30 +0,0 @@ | |||||||
| # Copyright (C) 2007, Red Hat, Inc. |  | ||||||
| # |  | ||||||
| # This library is free software; you can redistribute it and/or |  | ||||||
| # modify it under the terms of the GNU Lesser General Public |  | ||||||
| # License as published by the Free Software Foundation; either |  | ||||||
| # version 2 of the License, or (at your option) any later version. |  | ||||||
| # |  | ||||||
| # This library is distributed in the hope that it will be useful, |  | ||||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |  | ||||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU |  | ||||||
| # Lesser General Public License for more details. |  | ||||||
| # |  | ||||||
| # You should have received a copy of the GNU Lesser General Public |  | ||||||
| # License along with this library; if not, write to the |  | ||||||
| # Free Software Foundation, Inc., 59 Temple Place - Suite 330, |  | ||||||
| # Boston, MA 02111-1307, USA. |  | ||||||
| 
 |  | ||||||
| import datetime |  | ||||||
| import unittest |  | ||||||
| 
 |  | ||||||
| from sugar.date import Date |  | ||||||
| 
 |  | ||||||
| class TestDate(unittest.TestCase): |  | ||||||
|     def test_today(self): |  | ||||||
|         date = Date(datetime.date(2000, 1, 1)) |  | ||||||
|         date._today = datetime.date(2000, 1, 1) |  | ||||||
|         self.assertEqual(str(date), 'Today') |  | ||||||
| 
 |  | ||||||
| if __name__ == "__main__": |  | ||||||
|     unittest.main() |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tomeu Vizoso
						Tomeu Vizoso