diff options
author | 2015-09-22 00:33:01 +0200 | |
---|---|---|
committer | 2015-09-22 00:33:01 +0200 | |
commit | 5748b8ed8222dac07e9d40ce582ca7f8ae591cb8 (patch) | |
tree | 8223a71fce727e19cea680013e81e2ba9a363579 /module/plugins | |
parent | Spare improvements and fixes (2) (diff) | |
download | pyload-5748b8ed8222dac07e9d40ce582ca7f8ae591cb8.tar.xz |
Auto-detect seconds_to_midnight
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/internal/Plugin.py | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/module/plugins/internal/Plugin.py b/module/plugins/internal/Plugin.py index e9964b11d..b651079c2 100644 --- a/module/plugins/internal/Plugin.py +++ b/module/plugins/internal/Plugin.py @@ -89,22 +89,15 @@ def which(program): return exe_file -def seconds_to_midnight(gmt=0): - now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt) - - if now.hour == 0 and now.minute < 10: - midnight = now +def seconds_to_midnight(gmt=None): + if gmt is None: + now = datetime.datetime.today() else: - midnight = now + datetime.timedelta(days=1) - - td = midnight.replace(hour=0, minute=10, second=0, microsecond=0) - now + now = datetime.datetime.utcnow() + datetime.timedelta(hours=gmt) - if hasattr(td, 'total_seconds'): - res = td.total_seconds() - else: #@NOTE: work-around for python 2.5 and 2.6 missing datetime.timedelta.total_seconds - res = (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 + midnight = now.replace(hour=0, minute=10, second=0, microsecond=0) + datetime.timedelta(days=1) - return int(res) + return (midnight - now).seconds def replace_patterns(string, ruleslist): |