Skip to content

Commit

Permalink
Parse system time into datetime object
Browse files Browse the repository at this point in the history
Instead of returning the datetime as a string, parse it and return a
datetime object.

See: #46
  • Loading branch information
robin-nitrokey committed Nov 17, 2023
1 parent 96b86e8 commit ad49579
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 2 additions & 2 deletions nethsm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -993,12 +993,12 @@ def get_config_network(self) -> NetworkConfig:
netmask=response.body.netmask,
)

def get_config_time(self) -> str:
def get_config_time(self) -> datetime:
try:
response = self.get_api().config_time_get()
except Exception as e:
_handle_exception(e, state=State.OPERATIONAL, roles=[Role.ADMINISTRATOR])
return response.body.time
return datetime.fromisoformat(response.body.time)

def get_config_unattended_boot(self) -> str:
try:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_nethsm_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ def get_config_network(nethsm: NetHSM) -> None:


def get_config_time(nethsm: NetHSM) -> None:
dt_nethsm = datetime.datetime.strptime(
nethsm.get_config_time(), "%Y-%m-%dT%H:%M:%SZ"
).replace(tzinfo=datetime.timezone.utc)
dt_nethsm = nethsm.get_config_time()
dt_now = datetime.datetime.now(datetime.timezone.utc)

seconds_diff = (dt_nethsm - dt_now).total_seconds()
Expand Down

0 comments on commit ad49579

Please sign in to comment.