immich/mobile/lib/utils/datetime_helpers.dart
shenlong fea5e6783c
fix: merged timeline orderby localtime (#22371)
* chore: refactor dateFmt to truncateDate

* fix: merged timeline orderby localtime

---------

Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
2025-09-29 09:53:40 -05:00

20 lines
574 B
Dart

const int _maxMillisecondsSinceEpoch = 8640000000000000; // 275760-09-13
const int _minMillisecondsSinceEpoch = -62135596800000; // 0001-01-01
DateTime? tryFromSecondsSinceEpoch(int? secondsSinceEpoch, {bool isUtc = false}) {
if (secondsSinceEpoch == null) {
return null;
}
final milliSeconds = secondsSinceEpoch * 1000;
if (milliSeconds < _minMillisecondsSinceEpoch || milliSeconds > _maxMillisecondsSinceEpoch) {
return null;
}
try {
return DateTime.fromMillisecondsSinceEpoch(milliSeconds, isUtc: isUtc);
} catch (e) {
return null;
}
}