## 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() return time_to_period(time_in_secs) func get_total_period() -> String: var time_in_secs := get_total_elapsed_seconds() return time_to_period(time_in_secs) static func time_to_period(time_in_secs: int) -> String: # warning-ignore:integer_division var seconds := time_in_secs%60 # warning-ignore:integer_division var minutes := (time_in_secs/60)%60 # warning-ignore:integer_division var hours := (time_in_secs/60)/60 return "%02d:%02d:%02d" % [hours, minutes, seconds] func to_csv_line() -> PoolStringArray: return PoolStringArray([ name, start_time, end_time, str(get_elapsed_seconds()) if closed else tr(Consts.ONGOING) ]) static func is_csv_line_valid(line: PoolStringArray) -> bool: return line.size() > 3 func from_csv_line(line: PoolStringArray) -> TimeEntry: name = line[0] var start_time_string = line[1] # warning-ignore:return_value_discarded start_time.from_string(start_time_string) var elapsed_seconds = int(line[3]) if line[3].is_valid_integer() else 0 closed = elapsed_seconds > 0 if closed == true: var end_time_string = line[2] # warning-ignore:return_value_discarded end_time.from_string(end_time_string) else: # warning-ignore:return_value_discarded end_time.from_current_time() return self func _to_string() -> String: return "%s\t%s\t%s"%[name, Consts.ONGOING if closed == false else "", start_time]