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

  1. String convertToAgo(String input, { bool short = false }) {
  2. DateTime time = DateTime.parse(input);
  3. Duration diff = DateTime.now().difference(time);
  4. if(diff.inDays >= 1){
  5. return '${diff.inDays} day${diff.inDays == 1 ? "" : "s"} ${short ? '': 'ago'}';
  6. }
  7. if(diff.inHours >= 1){
  8. return '${diff.inHours} hour${diff.inHours == 1 ? "" : "s"} ${short ? '' : 'ago'}';
  9. }
  10. if(diff.inMinutes >= 1){
  11. return '${diff.inMinutes} ${short ? 'min' : 'minute'}${diff.inMinutes == 1 ? "" : "s"} ${short ? '' : 'ago'}';
  12. }
  13. if (diff.inSeconds >= 1){
  14. return '${diff.inSeconds} ${short ? '' : 'second'}${diff.inSeconds == 1 ? "" : "s"} ${short ? '' : 'ago'}';
  15. }
  16. return 'just now';
  17. }