2023-03-03 21:12:54 +00:00
|
|
|
## Describes a row in a timesheet
|
|
|
|
## Has a beginning and an end
|
|
|
|
class_name TimeEntry
|
|
|
|
|
|
|
|
var name := ""
|
|
|
|
var closed := false
|
|
|
|
var start_time := TimeStamp.new()
|
|
|
|
var end_time := TimeStamp.new()
|
|
|
|
var previous_total := 0
|
|
|
|
|
|
|
|
|
|
|
|
func start_recording() -> TimeEntry:
|
|
|
|
start_time = start_time.from_current_time()
|
|
|
|
end_time = end_time.from_current_time()
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
|
|
func update() -> void:
|
|
|
|
end_time = end_time.from_current_time()
|
|
|
|
|
|
|
|
|
|
|
|
func get_elapsed_seconds() -> int:
|
|
|
|
var elapsed := end_time.get_difference(start_time)
|
|
|
|
return elapsed
|
|
|
|
|
|
|
|
|
|
|
|
func get_total_elapsed_seconds() -> int:
|
|
|
|
var elapsed := get_elapsed_seconds() + previous_total
|
|
|
|
return elapsed
|
|
|
|
|
|
|
|
|
|
|
|
func get_period() -> String:
|
|
|
|
var time_in_secs := get_elapsed_seconds()
|
2023-03-09 20:26:57 +00:00
|
|
|
return time_to_period(time_in_secs)
|
2023-03-03 21:12:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
func get_total_period() -> String:
|
|
|
|
var time_in_secs := get_total_elapsed_seconds()
|
2023-03-09 20:26:57 +00:00
|
|
|
return time_to_period(time_in_secs)
|
2023-03-03 21:12:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
static func time_to_period(time_in_secs: int) -> String:
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:integer_division
|
2023-03-03 21:12:54 +00:00
|
|
|
var seconds := time_in_secs%60
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:integer_division
|
2023-03-03 21:12:54 +00:00
|
|
|
var minutes := (time_in_secs/60)%60
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:integer_division
|
2023-03-03 21:12:54 +00:00
|
|
|
var hours := (time_in_secs/60)/60
|
|
|
|
return "%02d:%02d:%02d" % [hours, minutes, seconds]
|
|
|
|
|
2023-03-09 20:26:57 +00:00
|
|
|
func to_csv_line() -> PoolStringArray:
|
|
|
|
return PoolStringArray([
|
2023-03-03 21:12:54 +00:00
|
|
|
name,
|
|
|
|
start_time,
|
|
|
|
end_time,
|
|
|
|
str(get_elapsed_seconds()) if closed else tr(Consts.ONGOING)
|
|
|
|
])
|
|
|
|
|
2023-03-09 20:26:57 +00:00
|
|
|
static func is_csv_line_valid(line: PoolStringArray) -> bool:
|
2023-03-03 21:12:54 +00:00
|
|
|
return line.size() > 3
|
|
|
|
|
|
|
|
|
2023-03-09 20:26:57 +00:00
|
|
|
func from_csv_line(line: PoolStringArray) -> TimeEntry:
|
2023-03-03 21:12:54 +00:00
|
|
|
name = line[0]
|
|
|
|
|
|
|
|
var start_time_string = line[1]
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:return_value_discarded
|
2023-03-03 21:12:54 +00:00
|
|
|
start_time.from_string(start_time_string)
|
|
|
|
|
2023-03-09 20:26:57 +00:00
|
|
|
var elapsed_seconds = int(line[3]) if line[3].is_valid_integer() else 0
|
2023-03-03 21:12:54 +00:00
|
|
|
closed = elapsed_seconds > 0
|
|
|
|
|
|
|
|
if closed == true:
|
|
|
|
var end_time_string = line[2]
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:return_value_discarded
|
2023-03-03 21:12:54 +00:00
|
|
|
end_time.from_string(end_time_string)
|
|
|
|
else:
|
2023-03-09 20:26:57 +00:00
|
|
|
# warning-ignore:return_value_discarded
|
2023-03-03 21:12:54 +00:00
|
|
|
end_time.from_current_time()
|
|
|
|
return self
|
|
|
|
|
2023-03-04 14:07:03 +00:00
|
|
|
func _to_string() -> String:
|
2023-03-09 20:11:34 +00:00
|
|
|
return "%s\t%s\t%s"%[name, Consts.ONGOING if closed == false else "", start_time]
|