1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 10:48:50 +01:00

refactor: use timeago package

This commit is contained in:
Rongjian Zhang 2019-08-31 20:44:59 +08:00
parent a7155d4def
commit 2cc7493a24
4 changed files with 4 additions and 34 deletions

View File

@ -1,31 +0,0 @@
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 formatFromString(String str) {
return format(DateTime.parse(str));
}
static String format(DateTime time) {
double diff =
(DateTime.now().millisecondsSinceEpoch - time.millisecondsSinceEpoch) /
1000;
if (diff < 0) {
return 'in the future';
} else if (diff < 3600) {
return _pluralize(diff / 60, 'minute');
} else if (diff < 86400) {
return _pluralize(diff / 3600, 'hour');
} else {
return _pluralize(diff / 86400, 'day');
}
}
}

View File

@ -4,7 +4,6 @@ import 'package:flutter/gestures.dart';
import '../providers/settings.dart';
import '../screens/repo.dart';
export 'package:flutter_vector_icons/flutter_vector_icons.dart';
export 'timeago.dart';
class StorageKeys {
static const account = 'account';

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:primer/primer.dart';
import '../utils/utils.dart';
import 'avatar.dart';
@ -53,7 +54,7 @@ class CommentItem extends StatelessWidget {
UserName(payload['author']['login']),
Padding(padding: EdgeInsets.only(bottom: 2)),
Text(
TimeAgo.formatFromString(payload['createdAt']),
timeago.format(DateTime.parse(payload['createdAt'])),
style: TextStyle(color: Colors.black54, fontSize: 13),
),
],

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:primer/primer.dart';
import 'package:url_launcher/url_launcher.dart';
import '../utils/utils.dart';
@ -36,7 +37,7 @@ class NotificationPayload {
}
title = input['subject']['title'];
updateAt = TimeAgo.formatFromString(input['updated_at']);
updateAt = timeago.format(DateTime.parse(input['updated_at']));
unread = input['unread'];
}
}