stick-the-quick/util/TimeIntervalFormatting.gd

45 lines
1.0 KiB
GDScript3
Raw Permalink Normal View History

class_name TimeIntervalFormatting
func _init() -> void:
push_error("Not instantiable")
free()
static func format_systime_interval(seconds: int) -> String:
var neg := seconds < 0
seconds = abs(seconds)
if seconds < 60:
return "%s%d seconds" % [
'minus ' if neg else '',
seconds
]
elif seconds < 3600:
return "%s%d minutes %d seconds" % [
'minus ' if neg else '',
int(seconds/60.0), seconds%60
]
elif seconds < 86400:
return "%s%d hours %02d minutes" % [
'minus ' if neg else '',
int(seconds/3600.0),
int(seconds/60.0)%60
]
else:
return "%s%d days" % [
'minus ' if neg else '',
int(seconds/86400.0)
]
static func format_realtime_interval(seconds: float) -> String:
var negative := false
if seconds < 0.0:
negative = true
seconds = -seconds
var ithirds: int = int(seconds*60.0)%60
var iseconds: int = int(seconds)%60
var iminutes: int = int(seconds/60.0)%60
var ihours: int = int(seconds/3600.0)
return "%s%d:%02d:%02d:%02d" % [
"-" if negative else "",
ihours, iminutes, iseconds, ithirds
]