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.
 
 
 
 
 
 

38 lines
1.5 KiB

import 'package:eaimar/data/utils/recording_time.dart';
import 'package:flutter_test/flutter_test.dart';
/// 「从设备同步进来的录音显示什么时间」的口径。
///
/// 用例里的 2018-08-10 不是编的:那是 2026-09-10 真机那张 TF 卡上一批文件的
/// 真实 FAT 时间戳(设备 RTC 还没对时就录的)。
void main() {
final now = DateTime(2026, 9, 10, 23, 43);
test('设备时间合理时就用它', () {
final t = DateTime(2026, 8, 15, 14, 33, 4);
expect(resolveRecordingCreationTime(t, now: now), t.millisecondsSinceEpoch);
});
test('设备没给时间就用当前时刻', () {
expect(resolveRecordingCreationTime(null, now: now),
now.millisecondsSinceEpoch);
});
test('⚠️ RTC 没对时的垃圾时间戳(2018)要丢掉,否则记录沉到列表最底下', () {
expect(resolveRecordingCreationTime(DateTime(2018, 8, 10), now: now),
now.millisecondsSinceEpoch);
});
test('FAT 的 1980 纪元同样丢掉', () {
expect(resolveRecordingCreationTime(DateTime(1980, 1, 1), now: now),
now.millisecondsSinceEpoch);
});
test('未来时间也丢掉(设备时钟跑飞),但留一天容差给时区', () {
expect(resolveRecordingCreationTime(DateTime(2030, 1, 1), now: now),
now.millisecondsSinceEpoch);
final justAhead = now.add(const Duration(hours: 8));
expect(resolveRecordingCreationTime(justAhead, now: now),
justAhead.millisecondsSinceEpoch);
});
}