mirror of
https://github.com/immich-app/immich.git
synced 2025-10-29 01:32:34 -04:00
* chore: refactor dateFmt to truncateDate * fix: merged timeline orderby localtime --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
20 lines
574 B
Dart
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;
|
|
}
|
|
}
|