You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.7 KiB
59 lines
1.7 KiB
import 'package:equatable/equatable.dart';
|
|
|
|
// 计时器实体类
|
|
class TimerEntry extends Equatable {
|
|
final int id;
|
|
final String? description;
|
|
final int? projectID;
|
|
final DateTime startTime;
|
|
final DateTime? endTime;
|
|
final String? notes;
|
|
|
|
// 构造函数
|
|
const TimerEntry(
|
|
{required this.id,
|
|
required this.description,
|
|
required this.projectID,
|
|
required this.startTime,
|
|
required this.endTime,
|
|
this.notes = ""});
|
|
|
|
// 返回属性列表,用于比较两个对象是否相等
|
|
@override
|
|
List<Object?> get props =>
|
|
[id, description, projectID, startTime, endTime, notes];
|
|
@override
|
|
bool get stringify => true;
|
|
|
|
// 克隆方法
|
|
TimerEntry.clone(TimerEntry timer,
|
|
{String? description,
|
|
int? projectID,
|
|
DateTime? startTime,
|
|
DateTime? endTime,
|
|
String? notes})
|
|
: this(
|
|
id: timer.id,
|
|
description: description ?? timer.description,
|
|
projectID: projectID ?? timer.projectID,
|
|
startTime: startTime ?? timer.startTime,
|
|
endTime: endTime ?? timer.endTime,
|
|
notes: notes ?? timer.notes,
|
|
);
|
|
|
|
// 格式化时间
|
|
static String formatDuration(Duration d) {
|
|
if (d.inHours > 0) {
|
|
return "${d.inHours}:${(d.inMinutes - (d.inHours * 60)).toString().padLeft(2, "0")}:${(d.inSeconds - (d.inMinutes * 60)).toString().padLeft(2, "0")}";
|
|
} else {
|
|
return "${d.inMinutes.toString().padLeft(2, "0")}:${(d.inSeconds - (d.inMinutes * 60)).toString().padLeft(2, "0")}";
|
|
}
|
|
}
|
|
|
|
// 格式化时间
|
|
String formatTime() {
|
|
Duration d = (endTime ?? DateTime.now()).difference(startTime);
|
|
return formatDuration(d);
|
|
}
|
|
}
|