~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/timestamp.py

  • Committer: Martin Pool
  • Date: 2008-05-08 04:12:06 UTC
  • mto: This revision was merged to the branch mainline in revision 3415.
  • Revision ID: mbp@sourcefrog.net-20080508041206-tkrr8ucmcyrlzkum
Some review cleanups for assertion removal

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
import calendar
18
18
import time
56
56
        offset = 0
57
57
    tt = time.gmtime(t + offset)
58
58
 
59
 
    return (osutils.weekdays[tt[6]] +
60
 
            time.strftime(" %Y-%m-%d %H:%M:%S", tt)
 
59
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
61
60
            # Get the high-res seconds, but ignore the 0
62
61
            + ('%.9f' % (t - int(t)))[1:]
63
62
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
101
100
    ...      break
102
101
 
103
102
    """
104
 
    # Weekday parsing is locale sensitive, so drop the weekday
105
 
    space_loc = date.find(' ')
106
 
    if space_loc == -1 or date[:space_loc] not in osutils.weekdays:
107
 
        raise ValueError(
108
 
            'Date string does not contain a day of week: %r' % date)
109
103
    # Up until the first period is a datestamp that is generated
110
104
    # as normal from time.strftime, so use time.strptime to
111
105
    # parse it
113
107
    if dot_loc == -1:
114
108
        raise ValueError(
115
109
            'Date string does not contain high-precision seconds: %r' % date)
116
 
    base_time = time.strptime(date[space_loc:dot_loc], " %Y-%m-%d %H:%M:%S")
 
110
    base_time = time.strptime(date[:dot_loc], "%a %Y-%m-%d %H:%M:%S")
117
111
    fract_seconds, offset = date[dot_loc:].split()
118
112
    fract_seconds = float(fract_seconds)
119
113
 
139
133
    if offset % 60 != 0:
140
134
        raise ValueError(
141
135
        "can't represent timezone %s offset by fractional minutes" % offset)
142
 
    # so that we don't need to do calculations on pre-epoch times,
 
136
    # so that we don't need to do calculations on pre-epoch times, 
143
137
    # which doesn't work with win32 python gmtime, we always
144
138
    # give the epoch in utc
145
139
    if secs == 0: