* fix(mobile): clamp out of range datetimes so timeline queries cannot crash * replace the per column converters with a clamping custom type * heal each table in one statement, rename the clamp type, read dates as stored * one medium test for the clamp, drop the dart side bounds, private clamp type
51 lines
1.9 KiB
Dart
51 lines
1.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:immich_mobile/utils/datetime_helpers.dart';
|
|
|
|
void main() {
|
|
group('tryFromSecondsSinceEpoch', () {
|
|
test('returns null for null input', () {
|
|
final result = tryFromSecondsSinceEpoch(null);
|
|
expect(result, isNull);
|
|
});
|
|
|
|
test('returns null for value above maximum allowed range', () {
|
|
const seconds = 8640000000000000 ~/ 1000 + 1; // One second after max allowed
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result, isNull);
|
|
});
|
|
|
|
test('returns correct DateTime for minimum allowed value', () {
|
|
const seconds = -62135596800000 ~/ 1000; // Minimum allowed timestamp
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result, DateTime.fromMillisecondsSinceEpoch(-62135596800000));
|
|
});
|
|
|
|
test('returns correct DateTime for maximum allowed value', () {
|
|
const seconds = 8640000000000000 ~/ 1000; // Maximum allowed timestamp
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result, DateTime.fromMillisecondsSinceEpoch(8640000000000000));
|
|
});
|
|
|
|
test('returns correct DateTime for negative timestamp', () {
|
|
const seconds = -1577836800; // Dec 31, 1919 (pre-epoch)
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result, DateTime.fromMillisecondsSinceEpoch(-1577836800 * 1000));
|
|
});
|
|
|
|
test('returns correct DateTime for zero timestamp', () {
|
|
const seconds = 0; // Jan 1, 1970 (epoch)
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result, DateTime.fromMillisecondsSinceEpoch(0));
|
|
});
|
|
|
|
test('returns correct DateTime for recent timestamp', () {
|
|
final now = DateTime.now();
|
|
final seconds = now.millisecondsSinceEpoch ~/ 1000;
|
|
final result = tryFromSecondsSinceEpoch(seconds);
|
|
expect(result?.year, now.year);
|
|
expect(result?.month, now.month);
|
|
expect(result?.day, now.day);
|
|
});
|
|
});
|
|
}
|