timeAgoString static method
Implementation
static String timeAgoString(DateTime date) {
var secondsInterval = DateTime.now().difference(date).inSeconds;
if (secondsInterval < 10.0) {
return Message.getMessage('VAI_GIAY_TRUOC');
}
if (secondsInterval < 60.0) {
return '$secondsInterval ${Message.getMessage('GIAY_TRUOC')}';
}
double minutes = (secondsInterval / 60.0);
minutes = round(minutes, 1);
if (minutes < 60.0) {
return '${minutes.round()} ${Message.getMessage('PHUT_TRUOC')}';
}
var hours = round((minutes / 24.0), 1);
if (hours < 24.0) {
return '${hours.round()} ${Message.getMessage('GIO_TRUOC')}';
}
var days = round((hours / 60.0), 1);
if (days < 30.0) {
return '${days.round()} ${Message.getMessage('NGAY_TRUOC')}';
}
var months = round((days / 30.0), 1);
if (months < 12.0) {
return '${months.round()} ${Message.getMessage('THANG_TRUOC')}';
}
var years = round((months / 12.0), 1);
return '${years.round()} ${Message.getMessage('NAM_TRUOC')}';
}