Changeset 7:7f7b4ef7c0c1 in stamper
- Timestamp:
- Jul 8, 2014, 10:38:01 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
stamper/stamper.py
r0 r7 1 1 2 2 import json 3 import re 3 4 from datetime import datetime, timedelta 4 5 from os.path import expanduser, exists 6 5 7 6 8 STAMPS_FILE = expanduser('~/.workstamps.json') … … 49 51 return worktime.seconds 50 52 53 def validate_filter(self, stamp_filter): 54 """ 55 Validate a given filter. Filters can have the following notation: 56 57 - %Y-%m-%d--%Y-%m-%d: Times recorded between two dates 58 59 - -%Y-%m-%d: Times recorded before a given date 60 61 - +%Y-%m-%d: Times recorded after a given date 62 63 - N...N[d|w|m|y]: Times recorded N...N days/weeks/months/years ago 64 """ 65 # First try the date filters, one by one 66 matches = ['%Y-%m-%d', '-%Y-%m-%d', '+%Y-%m-%d'] 67 for match in matches: 68 try: 69 if '--' in stamp_filter: 70 filter_from, filter_to = stamp_filter.split('--') 71 filter_from = datetime.strptime(stamp_filter, match) 72 filter_to = datetime.strptime(stamp_filter, match) 73 else: 74 valid_filter = datetime.strptime(stamp_filter, match) 75 except ValueError: 76 pass 77 else: 78 return stamp_filter 79 80 valid_filter = re.search(r'(\d+[dwmyDWMY]{1})', stamp_filter) 81 if valid_filter: 82 return stamp_filter 83 84 # Not a valid filter 85 return None 86 51 87 def customers(self): 52 88 customers = []
Note:
See TracChangeset
for help on using the changeset viewer.