mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
use UTC when calculating epoch timestamp. reset time locale to default after changing
This commit is contained in:
@ -62,8 +62,8 @@ pydocmd simple jc.parsers.systemctl_luf+ > ../docs/parsers/systemctl_luf.md
|
||||
pydocmd simple jc.parsers.timedatectl+ > ../docs/parsers/timedatectl.md
|
||||
pydocmd simple jc.parsers.tracepath+ > ../docs/parsers/tracepath.md
|
||||
pydocmd simple jc.parsers.traceroute+ > ../docs/parsers/traceroute.md
|
||||
pydocmd simple jc.parsers.upower+ > ../docs/parsers/upower.md
|
||||
pydocmd simple jc.parsers.uname+ > ../docs/parsers/uname.md
|
||||
pydocmd simple jc.parsers.upower+ > ../docs/parsers/upower.md
|
||||
pydocmd simple jc.parsers.uptime+ > ../docs/parsers/uptime.md
|
||||
pydocmd simple jc.parsers.w+ > ../docs/parsers/w.md
|
||||
pydocmd simple jc.parsers.wc+ > ../docs/parsers/wc.md
|
||||
|
@ -157,7 +157,7 @@ Returns:
|
||||
"native_path": string,
|
||||
"power_supply": boolean,
|
||||
"updated": string,
|
||||
"updated_epoch": integer, # works best with C locale. null if conversion fails
|
||||
"updated_epoch": integer, # as UTC. Works best with C locale. null if conversion fails
|
||||
"updated_seconds_ago": integer,
|
||||
"has_history": boolean,
|
||||
"has_statistics": boolean,
|
||||
|
@ -127,7 +127,7 @@ Examples:
|
||||
]
|
||||
"""
|
||||
import locale
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
import jc.utils
|
||||
|
||||
|
||||
@ -141,6 +141,7 @@ class info():
|
||||
# compatible options: linux, darwin, cygwin, win32, aix, freebsd
|
||||
compatible = ['linux']
|
||||
magic_commands = ['upower']
|
||||
timezone_support = True
|
||||
|
||||
|
||||
__version__ = info.version
|
||||
@ -165,7 +166,7 @@ def process(proc_data):
|
||||
"native_path": string,
|
||||
"power_supply": boolean,
|
||||
"updated": string,
|
||||
"updated_epoch": integer, # works best with C locale. null if conversion fails
|
||||
"updated_epoch": integer, # as UTC. Works best with C locale. null if conversion fails
|
||||
"updated_seconds_ago": integer,
|
||||
"has_history": boolean,
|
||||
"has_statistics": boolean,
|
||||
@ -226,13 +227,19 @@ def process(proc_data):
|
||||
# try C locale. If that fails, try current locale. If that fails, give up
|
||||
entry['updated_epoch'] = None
|
||||
try:
|
||||
entry['updated_epoch'] = int(datetime.strptime(entry['updated'], '%c').strftime('%s'))
|
||||
locale.setlocale(locale.LC_TIME, None)
|
||||
entry['updated_epoch'] = int(datetime.strptime(entry['updated'], '%c').astimezone(tz=timezone.utc).strftime('%s'))
|
||||
except Exception:
|
||||
try:
|
||||
locale.setlocale(locale.LC_TIME, '')
|
||||
entry['updated_epoch'] = int(datetime.strptime(entry['updated'], '%c').strftime('%s'))
|
||||
entry['updated_epoch'] = int(datetime.strptime(entry['updated'], '%c').astimezone(tz=timezone.utc).strftime('%s'))
|
||||
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
locale.setlocale(locale.LC_TIME, None)
|
||||
finally:
|
||||
locale.setlocale(locale.LC_TIME, None)
|
||||
|
||||
entry['updated_seconds_ago'] = int(updated_list[-3])
|
||||
|
||||
|
Reference in New Issue
Block a user