Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter/Dart DateTime max min value

I want to know the DateTime min and max value for comparison.

DateTimes can represent time values that are at a distance of at most 100,000,000 days from epoch (1970-01-01 UTC): -271821-04-20 to 275760-09-13.

I see no min/max define in DateTime, is there any way to programmatically get the min/max values?

DateTime min;  // -271821-04-20  
DateTime max;  // 275760-09-13
like image 730
Tommy Chang Avatar asked Oct 24 '25 21:10

Tommy Chang


1 Answers

It doesn't seem like this is something that is available at the moment. You could make a feature request and see what happens, but the only thing right now is to just make getters for the max and min values. Unfortunately, we can't make static extension methods either, so you'll just have to use a static class or globals:

class DateTimeMaxMin {
  static const _numDays = 100000000;
  
  static DateTime get min => DateTime.fromMicrosecondsSinceEpoch(0).subtract(Duration(days: _numDays));
  static DateTime get max => DateTime.fromMicrosecondsSinceEpoch(0).add(Duration(days: _numDays));
}
like image 103
Christopher Moore Avatar answered Oct 26 '25 10:10

Christopher Moore