Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Negligible spacing cleanup in utils/dateparse.py

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17219 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 637a70fa7bad163de70bf4493b1ea73dd2147240 1 parent 286c5c8
Adrian Holovaty authored December 17, 2011

Showing 1 changed file with 19 additions and 27 deletions. Show diff stats Hide diff stats

  1. 46  django/utils/dateparse.py
46  django/utils/dateparse.py
... ...
@@ -1,58 +1,51 @@
1 1
 """Functions to parse datetime objects."""
2 2
 
3 3
 # We're using regular expressions rather than time.strptime because:
4  
-# - they provide both validation and parsing,
5  
-# - they're more flexible for datetimes,
6  
-# - the date/datetime/time constructors produce friendlier error messages.
7  
-
  4
+# - They provide both validation and parsing.
  5
+# - They're more flexible for datetimes.
  6
+# - The date/datetime/time constructors produce friendlier error messages.
8 7
 
9 8
 import datetime
10 9
 import re
11  
-
12 10
 from django.utils.timezone import utc
13 11
 from django.utils.tzinfo import FixedOffset
14 12
 
15  
-
16 13
 date_re = re.compile(
17  
-        r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$'
  14
+    r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})$'
18 15
 )
19 16
 
20  
-
21 17
 datetime_re = re.compile(
22  
-        r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})'
23  
-        r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
24  
-        r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
25  
-        r'(?P<tzinfo>Z|[+-]\d{1,2}:\d{1,2})?$'
  18
+    r'(?P<year>\d{4})-(?P<month>\d{1,2})-(?P<day>\d{1,2})'
  19
+    r'[T ](?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
  20
+    r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
  21
+    r'(?P<tzinfo>Z|[+-]\d{1,2}:\d{1,2})?$'
26 22
 )
27 23
 
28  
-
29 24
 time_re = re.compile(
30  
-        r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
31  
-        r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
  25
+    r'(?P<hour>\d{1,2}):(?P<minute>\d{1,2})'
  26
+    r'(?::(?P<second>\d{1,2})(?:\.(?P<microsecond>\d{1,6})\d{0,6})?)?'
32 27
 )
33 28
 
34  
-
35 29
 def parse_date(value):
36  
-    """Parse a string and return a datetime.date.
  30
+    """Parses a string and return a datetime.date.
37 31
 
38  
-    Raise ValueError if the input is well formatted but not a valid date.
39  
-    Return None if the input isn't well formatted.
  32
+    Raises ValueError if the input is well formatted but not a valid date.
  33
+    Returns None if the input isn't well formatted.
40 34
     """
41 35
     match = date_re.match(value)
42 36
     if match:
43 37
         kw = dict((k, int(v)) for k, v in match.groupdict().iteritems())
44 38
         return datetime.date(**kw)
45 39
 
46  
-
47 40
 def parse_time(value):
48  
-    """Parse a string and return a datetime.time.
  41
+    """Parses a string and return a datetime.time.
49 42
 
50 43
     This function doesn't support time zone offsets.
51 44
 
52 45
     Sub-microsecond precision is accepted, but ignored.
53 46
 
54  
-    Raise ValueError if the input is well formatted but not a valid time.
55  
-    Return None if the input isn't well formatted, in particular if it
  47
+    Raises ValueError if the input is well formatted but not a valid time.
  48
+    Returns None if the input isn't well formatted, in particular if it
56 49
     contains an offset.
57 50
     """
58 51
     match = time_re.match(value)
@@ -63,17 +56,16 @@ def parse_time(value):
63 56
         kw = dict((k, int(v)) for k, v in kw.iteritems() if v is not None)
64 57
         return datetime.time(**kw)
65 58
 
66  
-
67 59
 def parse_datetime(value):
68  
-    """Parse a string and return a datetime.datetime.
  60
+    """Parses a string and return a datetime.datetime.
69 61
 
70 62
     This function supports time zone offsets. When the input contains one,
71 63
     the output uses an instance of FixedOffset as tzinfo.
72 64
 
73 65
     Sub-microsecond precision is accepted, but ignored.
74 66
 
75  
-    Raise ValueError if the input is well formatted but not a valid datetime.
76  
-    Return None if the input isn't well formatted.
  67
+    Raises ValueError if the input is well formatted but not a valid datetime.
  68
+    Returns None if the input isn't well formatted.
77 69
     """
78 70
     match = datetime_re.match(value)
79 71
     if match:

0 notes on commit 637a70f

Please sign in to comment.
Something went wrong with that request. Please try again.