/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/timestamp.py

  • Committer: John Arbash Meinel
  • Date: 2007-03-20 00:49:11 UTC
  • mto: This revision was merged to the branch mainline in revision 2366.
  • Revision ID: john@arbash-meinel.com-20070320004911-0qajqnddr3rf9r2e
Simplify the test even further....
Basically, if you have a file deleted as removed, and then you unversion its directory
it deletes all records in the dirblock, not realizing that some of them might
already be marked as removed.

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
19
19
 
20
 
from bzrlib import osutils
21
 
 
22
20
 
23
21
def format_highres_date(t, offset=0):
24
22
    """Format a date, such that it includes higher precision in the
47
45
    >>> format_highres_date(1152428738.867522, 19800)
48
46
    'Sun 2006-07-09 12:35:38.867522001 +0530'
49
47
    """
50
 
    if not isinstance(t, float):
51
 
        raise ValueError(t)
 
48
    assert isinstance(t, float)
52
49
 
53
50
    # This has to be formatted for "original" date, so that the
54
51
    # revision XML entry will be reproduced faithfully.
56
53
        offset = 0
57
54
    tt = time.gmtime(t + offset)
58
55
 
59
 
    return (osutils.weekdays[tt[6]] +
60
 
            time.strftime(" %Y-%m-%d %H:%M:%S", tt)
 
56
    return (time.strftime("%a %Y-%m-%d %H:%M:%S", tt)
61
57
            # Get the high-res seconds, but ignore the 0
62
58
            + ('%.9f' % (t - int(t)))[1:]
63
59
            + ' %+03d%02d' % (offset / 3600, (offset / 60) % 60))
101
97
    ...      break
102
98
 
103
99
    """
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
100
    # Up until the first period is a datestamp that is generated
110
101
    # as normal from time.strftime, so use time.strptime to
111
102
    # parse it
113
104
    if dot_loc == -1:
114
105
        raise ValueError(
115
106
            '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")
 
107
    base_time = time.strptime(date[:dot_loc], "%a %Y-%m-%d %H:%M:%S")
117
108
    fract_seconds, offset = date[dot_loc:].split()
118
109
    fract_seconds = float(fract_seconds)
119
110
 
136
127
 
137
128
    Inverse of parse_patch_date.
138
129
    """
139
 
    if offset % 60 != 0:
140
 
        raise ValueError(
141
 
        "can't represent timezone %s offset by fractional minutes" % offset)
142
 
    # so that we don't need to do calculations on pre-epoch times,
143
 
    # which doesn't work with win32 python gmtime, we always
144
 
    # give the epoch in utc
145
 
    if secs == 0:
146
 
        offset = 0
147
 
    if secs + offset < 0:
148
 
        from warnings import warn
149
 
        warn("gmtime of negative time (%s, %s) may not work on Windows" %
150
 
                (secs, offset))
151
 
    return osutils.format_date(secs, offset=offset,
152
 
            date_fmt='%Y-%m-%d %H:%M:%S')
 
130
    assert offset % 36 == 0
 
131
    tm = time.gmtime(secs+offset)
 
132
    time_str = time.strftime('%Y-%m-%d %H:%M:%S', tm)
 
133
    return '%s %+05d' % (time_str, offset/36)
153
134
 
154
135
 
155
136
def parse_patch_date(date_str):
158
139
    Inverse of format_patch_date.
159
140
    """
160
141
    secs_str = date_str[:-6]
161
 
    offset_str = date_str[-5:]
162
 
    if len(offset_str) != 5:
163
 
        raise ValueError(
164
 
            "invalid timezone %r" % offset_str)
165
 
    offset_hours, offset_mins = offset_str[:3], offset_str[3:]
166
 
    offset = int(offset_hours) * 3600 + int(offset_mins) * 60
 
142
    offset_str = date_str[-6:]
 
143
    offset = int(offset_str) * 36
167
144
    tm_time = time.strptime(secs_str, '%Y-%m-%d %H:%M:%S')
168
145
    # adjust seconds according to offset before converting to POSIX
169
146
    # timestamp, to avoid edge problems