From d6384b2014c5877cb1cc7e24b1ab2c8562c5f126 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 26 Apr 2020 13:41:32 +0200 Subject: powerctl: T2010: report reboot time in current timezone Do not inform the user when the reboot will happen in UTC, use the local timezone instead. --- src/op_mode/powerctrl.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/op_mode/powerctrl.py b/src/op_mode/powerctrl.py index a70418801..d33f8633d 100755 --- a/src/op_mode/powerctrl.py +++ b/src/op_mode/powerctrl.py @@ -20,11 +20,16 @@ import re from argparse import ArgumentParser from datetime import datetime, timedelta, time as type_time, date as type_date from sys import exit +from time import time from vyos.util import ask_yes_no, cmd, call, run, STDOUT systemd_sched_file = "/run/systemd/shutdown/scheduled" +def utc2local(datetime): + now = time() + offs = datetime.fromtimestamp(now) - datetime.utcfromtimestamp(now) + return datetime + offs def parse_time(s): try: @@ -66,11 +71,12 @@ def get_shutdown_status(): def check_shutdown(): output = get_shutdown_status() + dt = datetime.strptime(output['DATETIME'], '%Y-%m-%d %H:%M:%S') if output and 'MODE' in output: if output['MODE'] == 'reboot': - print("Reboot is scheduled", output['DATETIME']) + print("Reboot is scheduled", utc2local(dt)) elif output['MODE'] == 'poweroff': - print("Poweroff is scheduled", output['DATETIME']) + print("Poweroff is scheduled", utc2local(dt)) else: print("Reboot or poweroff is not scheduled") -- cgit v1.2.3