text stringlengths 0 828 |
|---|
@type datetime_string: string |
@return: the guessed time. |
@rtype: L{time.struct_time} |
@raises ValueError: in case it's not possible to guess the time. |
"""""" |
if CFG_HAS_EGENIX_DATETIME: |
try: |
return Parser.DateTimeFromString(datetime_string).timetuple() |
except ValueError: |
pass |
else: |
for format in (None, '%x %X', '%X %x', '%Y-%M-%dT%h:%m:%sZ'): |
try: |
return time.strptime(datetime_string, format) |
except ValueError: |
pass |
raise ValueError(""It is not possible to guess the datetime format of %s"" % |
datetime_string)" |
4388,"def get_time_estimator(total): |
""""""Given a total amount of items to compute, return a function that, |
if called every time an item is computed (or every step items are computed) |
will give a time estimation for how long it will take to compute the whole |
set of itmes. The function will return two values: the first is the number |
of seconds that are still needed to compute the whole set, the second value |
is the time in the future when the operation is expected to end. |
"""""" |
t1 = time.time() |
count = [0] |
def estimate_needed_time(step=1): |
count[0] += step |
t2 = time.time() |
t3 = 1.0 * (t2 - t1) / count[0] * (total - count[0]) |
return t3, t3 + t1 |
return estimate_needed_time" |
4389,"def pretty_date(ugly_time=False, ln=None): |
""""""Get a datetime object or a int() Epoch timestamp and return a pretty |
string like 'an hour ago', 'Yesterday', '3 months ago', 'just now', etc. |
"""""" |
ln = default_ln(ln) |
_ = gettext_set_language(ln) |
now = real_datetime.now() |
if isinstance(ugly_time, six.string_types): |
# try to convert it to epoch timestamp |
date_format = '%Y-%m-%d %H:%M:%S.%f' |
try: |
ugly_time = time.strptime(ugly_time, date_format) |
ugly_time = int(time.mktime(ugly_time)) |
except ValueError: |
# doesn't match format, let's try to guess |
try: |
ugly_time = int(guess_datetime(ugly_time)) |
except ValueError: |
return ugly_time |
ugly_time = int(time.mktime(ugly_time)) |
# Initialize the time period difference |
if isinstance(ugly_time, int): |
diff = now - real_datetime.fromtimestamp(ugly_time) |
elif isinstance(ugly_time, real_datetime): |
diff = now - ugly_time |
elif not ugly_time: |
diff = now - now |
second_diff = diff.seconds |
day_diff = diff.days |
if day_diff < 0: |
return '' |
if day_diff == 0: |
if second_diff < 10: |
return _(""just now"") |
if second_diff < 60: |
return str(second_diff) + _("" seconds ago"") |
if second_diff < 120: |
return _(""a minute ago"") |
if second_diff < 3600: |
return str(second_diff / 60) + _("" minutes ago"") |
if second_diff < 7200: |
return _(""an hour ago"") |
if second_diff < 86400: |
return str(second_diff / 3600) + _("" hours ago"") |
if day_diff == 1: |
return _(""Yesterday"") |
if day_diff < 7: |
return str(day_diff) + _("" days ago"") |
if day_diff < 31: |
if day_diff / 7 == 7: |
return _(""Last week"") |
else: |
return str(day_diff / 7) + _("" weeks ago"") |
if day_diff < 365: |
if day_diff / 30 == 1: |
return _(""Last month"") |
else: |
return str(day_diff / 30) + _("" months ago"") |
if day_diff / 365 == 1: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.