Skip to content

Commit

Permalink
No longer store _pm and _pmhour
Browse files Browse the repository at this point in the history
  • Loading branch information
hannosch committed May 8, 2011
1 parent adc0e75 commit a737cb8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
7 changes: 4 additions & 3 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Changelog
3.0 (unreleased)
----------------

- Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon` and `_pmon` in
memory for every instance but look them up dynamically based on `_dayoffset`
and `_month`. This saves another 150 bytes of memory per DateTime instance.
- Avoid storing `_aday`, `_fday`, `_pday`, `_amon`, `_fmon`, `_pmon`, `_pmhour`
and `_pm` in memory for every instance but look them up dynamically based on
`_dayoffset`, `_month` and `_hour`. This saves another 150 bytes of memory
per DateTime instance.

- Moved various internal parsing related class variables to module constants.

Expand Down
22 changes: 14 additions & 8 deletions src/DateTime/DateTime.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,6 @@ class DateTime(object):
__slots__ = (
'_timezone_naive',
'_tz',
'_pm',
'_pmhour',
'_dayoffset',
'_year',
'_month',
Expand Down Expand Up @@ -825,12 +823,6 @@ def _parse_args(self, *args, **kw):
tz = self._calcTimezoneName(x, ms)
s,d,t,microsecs = _calcIndependentSecondEtc(tz, x, ms)

if hr>12:
self._pmhour=hr-12
self._pm='pm'
else:
self._pmhour=hr or 12
self._pm= (hr==12) and 'pm' or 'am'
self._dayoffset = int((_julianday(yr,mo,dy) + 2L) % 7)
# Round to nearest microsecond in platform-independent way. You
# cannot rely on C sprintf (Python '%') formatting to round
Expand Down Expand Up @@ -1426,6 +1418,13 @@ def dow_1(self):
"""Return the integer day of the week, where sunday is 1."""
return self._dayoffset+1

@property
def _pmhour(self):
hr = self._hour
if hr > 12:
return hr - 12
return hr or 12

def h_12(self):
"""Return the 12-hour clock representation of the hour."""
return self._pmhour
Expand All @@ -1434,6 +1433,13 @@ def h_24(self):
"""Return the 24-hour clock representation of the hour."""
return self._hour

@property
def _pm(self):
hr = self._hour
if hr >= 12:
return 'pm'
return 'am'

def ampm(self):
"""Return the appropriate time modifier (am or pm)."""
return self._pm
Expand Down

0 comments on commit a737cb8

Please sign in to comment.