mirror of
https://github.com/pd4d10/git-touch.git
synced 2026-05-02 04:17:39 -05:00
feat: style of home and notification screen
This commit is contained in:
25
lib/utils/timeago.dart
Normal file
25
lib/utils/timeago.dart
Normal file
@@ -0,0 +1,25 @@
|
||||
import 'dart:core';
|
||||
|
||||
class TimeAgo {
|
||||
static String _ceil(double n) => n.ceil().toString();
|
||||
|
||||
static String _pluralize(double time, String unit) {
|
||||
if (time == 1) {
|
||||
return '${_ceil(time)} $unit ago';
|
||||
}
|
||||
return '${_ceil(time)} ${unit}s ago';
|
||||
}
|
||||
|
||||
static String format(DateTime time) {
|
||||
double diff =
|
||||
(DateTime.now().millisecondsSinceEpoch - time.millisecondsSinceEpoch) /
|
||||
1000;
|
||||
if (diff < 3600) {
|
||||
return _pluralize(diff / 60, 'minute');
|
||||
} else if (diff < 86400) {
|
||||
return _pluralize(diff / 3600, 'hour');
|
||||
} else {
|
||||
return _pluralize(diff / 86400, 'day');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user