toLiveTime method
Implementation
String toLiveTime([DateFormats format = DateFormats.dateDMY]) {
final time = DateTime.fromMillisecondsSinceEpoch(_v);
final int currentMS = DateTime.now().microsecondsSinceEpoch;
final int tempMS = currentMS - _v;
final double secondCount = tempMS / TimeConstrains.secondMS.value;
final double minuteCount = tempMS / TimeConstrains.minuteMS.value;
final double hourCount = tempMS / TimeConstrains.hourMS.value;
if (tempMS < TimeConstrains.secondMS.value) {
return "Now";
} else if (tempMS < TimeConstrains.minuteMS.value) {
return "$secondCount second ago";
} else if (tempMS < TimeConstrains.hourMS.value) {
return "$minuteCount minute ago";
} else if (tempMS < TimeConstrains.dayMS.value) {
return "$hourCount hour ago";
} else {
return time.toDate(format);
}
}