Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
696 B

String convertToAgo(String input, { bool short = false }) {
DateTime time = DateTime.parse(input);
Duration diff = DateTime.now().difference(time);
if(diff.inDays >= 1){
return '${diff.inDays} day${diff.inDays == 1 ? "" : "s"} ${short ? '': 'ago'}';
}
if(diff.inHours >= 1){
return '${diff.inHours} hour${diff.inHours == 1 ? "" : "s"} ${short ? '' : 'ago'}';
}
if(diff.inMinutes >= 1){
return '${diff.inMinutes} ${short ? 'min' : 'minute'}${diff.inMinutes == 1 ? "" : "s"} ${short ? '' : 'ago'}';
}
if (diff.inSeconds >= 1){
return '${diff.inSeconds} ${short ? '' : 'second'}${diff.inSeconds == 1 ? "" : "s"} ${short ? '' : 'ago'}';
}
return 'just now';
}