Skip to content

Commit

Permalink
Convert Disaster Recovery Objectives units
Browse files Browse the repository at this point in the history
  • Loading branch information
ab-smith committed Dec 10, 2024
1 parent 8bee503 commit f5b8ffa
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,12 +1581,29 @@ def get_security_objectives_display(self) -> list[dict[str, str]]:
]

def get_disaster_recovery_objectives_display(self) -> list[dict[str, str]]:
def format_seconds(seconds: int) -> str:
hours, remainder = divmod(seconds, 3600)
minutes, secs = divmod(remainder, 60)

parts = []
if hours > 0:
parts.append(f"{hours:02d}h")
if minutes > 0:
parts.append(f"{minutes:02d}m")

if secs > 0 or (
not parts
): # Always show seconds if no other parts, or if > 0
parts.append(f"{secs:02d}s")

return "".join(parts)

"""
Gets the disaster recovery objectives of a given asset as strings.
"""
disaster_recovery_objectives = self.get_disaster_recovery_objectives()
return [
{"str": f"{key}: {content.get('value', 0)}"}
{"str": f"{key}: {format_seconds(content.get('value', 0))}"}
for key, content in disaster_recovery_objectives.get(
"objectives", {}
).items()
Expand Down

0 comments on commit f5b8ffa

Please sign in to comment.