Changeset 3879
- Timestamp:
- 01/17/08 13:05:11 (7 months ago)
- Files:
-
- branches/paul/dabo/__init__.py (modified) (2 diffs)
- branches/paul/dabo/lib/dates.py (modified) (4 diffs)
- branches/paul/dabo/settings.py (modified) (1 diff)
- branches/paul/dabo/ui/uiwx/dGrid.py (modified) (2 diffs)
- branches/paul/dabo/ui/uiwx/dTextBoxMixin.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/paul/dabo/__init__.py
r3810 r3879 103 103 import os 104 104 import sys 105 import locale 105 106 try: 106 107 import pysqlite2 … … 151 152 from settings import * 152 153 154 if settings.loadUserLocale: 155 locale.setlocale(locale.LC_ALL, '') 156 153 157 from __version__ import version 154 158 import dColors branches/paul/dabo/lib/dates.py
r3877 r3879 7 7 import re 8 8 import time 9 import dabo 9 10 10 11 _dregex = {} … … 29 30 exp = "^%(month)s%(day)s$" 30 31 else: 31 return None 32 conv = {"%d": "%(day)s", 33 "%m": "%(month)s", 34 "%y": "%(shortyear)s", 35 "%Y": "%(year)s"} 36 if "%d" in format and "%m" in format and ("%y" in format or "%Y" in format): 37 for k in conv.keys(): 38 format = format.replace(k, conv[k]) 39 format.replace(".", "\.") 40 exp = "^%s$" % format 41 else: 42 return None 43 32 44 return re.compile(exp % elements) 33 45 … … 75 87 76 88 89 def getStringFromDate(dateVal): 90 """Given a datetime.date, convert to string in dabo.settings.dateFormat style.""" 91 dateFormat = dabo.settings.dateFormat 92 if dateFormat is None: 93 # Delegate formatting to the time module, which will take the 94 # user's locale into account. 95 dateFormat = "%x" 96 return dateVal.strftime(dateFormat) 97 98 77 99 def getDateFromString(strVal, formats=None): 78 100 """Given a string in a defined format, return a date object or None.""" 79 101 global _dregex 80 102 103 dateFormat = dabo.settings.dateFormat 81 104 ret = None 105 82 106 if formats is None: 83 107 formats = ["ISO8601"] 108 109 if dateFormat is not None: 110 # Take the date format as set in dabo into account, when trying 111 # to make a date out of the string. 112 formats.append(dateFormat) 84 113 85 114 # Try each format in order: … … 113 142 break 114 143 if ret is None: 115 ## Fall back to the current locale setting: 116 try: 117 ret = datetime.date(*time.strptime(strVal, "%x")[:3]) 118 except: 119 ret = None 144 if dateFormat is None: 145 # Fall back to the current locale setting in user's os account: 146 try: 147 ret = datetime.date(*time.strptime(strVal, "%x")[:3]) 148 except: 149 pass 120 150 return ret 121 151 branches/paul/dabo/settings.py
r3877 r3879 112 112 checkForWebUpdates = True 113 113 114 # Date and Time formats. None will use the os user's settings, but 115 # your code can easily override these. Example: 116 # dabo.settings.dateFormat = "%d.%m.%Y" -> "31.12.2008". 117 dateFormat = None 118 dateTimeFormat = None 119 timeFormat = None 120 121 # Do we load the os user's locale settings automatically? 122 # Pythonista note: this executes: 123 # locale.setlocale(locale.LC_ALL, '') 124 loadUserLocale = True 114 125 115 126 ### Settings - end branches/paul/dabo/ui/uiwx/dGrid.py
r3877 r3879 22 22 from dabo.dObject import dObject 23 23 from dabo.ui import makeDynamicProperty 24 import dabo.lib.dates 24 25 25 26 # from dabo.lib.profilehooks import profile … … 349 350 """Get the string value to display in the grid.""" 350 351 if isinstance(val, datetime.date): 351 return time.strftime("%x", (val.year, val.month, val.day, 0, 0, 0, 0, 0, 0))352 return dabo.lib.dates.getStringFromDate(val) 352 353 return val 353 354 branches/paul/dabo/ui/uiwx/dTextBoxMixin.py
r3877 r3879 514 514 strVal = value.isoformat(" ") 515 515 elif isinstance(value, datetime.date): 516 strVal = time.strftime("%x", (value.year, value.month, value.day, 0, 0, 0, 0, 0, 0))516 strVal = dabo.lib.dates.getStringFromDate(value) 517 517 elif isinstance(value, datetime.time): 518 518 # Use the ISO 8601 time string format … … 533 533 datetime.date object, or None. 534 534 """ 535 formats = [ dabo.settings.dateFormat,"ISO8601"]535 formats = ["ISO8601"] 536 536 if not self.StrictDateEntry: 537 537 # Add some less strict date-entry formats:
