Mercurial > hg
comparison mercurial/utils/dateutil.py @ 46419:6894c9ef4dcd
errors: use InputError for incorrectly formatted dates
Differential Revision: https://phab.mercurial-scm.org/D9913
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 29 Jan 2021 16:26:53 -0800 |
parents | 89a2afe31e82 |
children | 15c2f9220ae8 |
comparison
equal
deleted
inserted
replaced
46418:dc00324e80f4 | 46419:6894c9ef4dcd |
---|---|
66 offset) tuple based off the local timezone.""" | 66 offset) tuple based off the local timezone.""" |
67 if timestamp is None: | 67 if timestamp is None: |
68 timestamp = time.time() | 68 timestamp = time.time() |
69 if timestamp < 0: | 69 if timestamp < 0: |
70 hint = _(b"check your clock") | 70 hint = _(b"check your clock") |
71 raise error.Abort(_(b"negative timestamp: %d") % timestamp, hint=hint) | 71 raise error.InputError( |
72 _(b"negative timestamp: %d") % timestamp, hint=hint | |
73 ) | |
72 delta = datetime.datetime.utcfromtimestamp( | 74 delta = datetime.datetime.utcfromtimestamp( |
73 timestamp | 75 timestamp |
74 ) - datetime.datetime.fromtimestamp(timestamp) | 76 ) - datetime.datetime.fromtimestamp(timestamp) |
75 tz = delta.days * 86400 + delta.seconds | 77 tz = delta.days * 86400 + delta.seconds |
76 return timestamp, tz | 78 return timestamp, tz |
326 return parsedate(date, extendeddateformats, d)[0] | 328 return parsedate(date, extendeddateformats, d)[0] |
327 | 329 |
328 date = date.strip() | 330 date = date.strip() |
329 | 331 |
330 if not date: | 332 if not date: |
331 raise error.Abort(_(b"dates cannot consist entirely of whitespace")) | 333 raise error.InputError( |
334 _(b"dates cannot consist entirely of whitespace") | |
335 ) | |
332 elif date[0:1] == b"<": | 336 elif date[0:1] == b"<": |
333 if not date[1:]: | 337 if not date[1:]: |
334 raise error.Abort(_(b"invalid day spec, use '<DATE'")) | 338 raise error.InputError(_(b"invalid day spec, use '<DATE'")) |
335 when = upper(date[1:]) | 339 when = upper(date[1:]) |
336 return lambda x: x <= when | 340 return lambda x: x <= when |
337 elif date[0:1] == b">": | 341 elif date[0:1] == b">": |
338 if not date[1:]: | 342 if not date[1:]: |
339 raise error.Abort(_(b"invalid day spec, use '>DATE'")) | 343 raise error.InputError(_(b"invalid day spec, use '>DATE'")) |
340 when = lower(date[1:]) | 344 when = lower(date[1:]) |
341 return lambda x: x >= when | 345 return lambda x: x >= when |
342 elif date[0:1] == b"-": | 346 elif date[0:1] == b"-": |
343 try: | 347 try: |
344 days = int(date[1:]) | 348 days = int(date[1:]) |
345 except ValueError: | 349 except ValueError: |
346 raise error.Abort(_(b"invalid day spec: %s") % date[1:]) | 350 raise error.InputError(_(b"invalid day spec: %s") % date[1:]) |
347 if days < 0: | 351 if days < 0: |
348 raise error.Abort( | 352 raise error.InputError( |
349 _(b"%s must be nonnegative (see 'hg help dates')") % date[1:] | 353 _(b"%s must be nonnegative (see 'hg help dates')") % date[1:] |
350 ) | 354 ) |
351 when = makedate()[0] - days * 3600 * 24 | 355 when = makedate()[0] - days * 3600 * 24 |
352 return lambda x: x >= when | 356 return lambda x: x >= when |
353 elif b" to " in date: | 357 elif b" to " in date: |