@@ -40,6 +40,8 @@ class CommonUtils {
4040
4141 static final double DAYS_LIMIT = 30 * HOURS_LIMIT ;
4242
43+ static Locale curLocale;
44+
4345 static String getDateStr (DateTime date) {
4446 if (date == null || date.toString () == null ) {
4547 return "" ;
@@ -58,19 +60,38 @@ class CommonUtils {
5860
5961 ///日期格式转换
6062 static String getNewsTimeStr (DateTime date) {
61- int subTime =
62- DateTime .now ().millisecondsSinceEpoch - date.millisecondsSinceEpoch;
63-
64- if (subTime < MILLIS_LIMIT ) {
65- return "刚刚" ;
66- } else if (subTime < SECONDS_LIMIT ) {
67- return (subTime / MILLIS_LIMIT ).round ().toString () + " 秒前" ;
68- } else if (subTime < MINUTES_LIMIT ) {
69- return (subTime / SECONDS_LIMIT ).round ().toString () + " 分钟前" ;
70- } else if (subTime < HOURS_LIMIT ) {
71- return (subTime / MINUTES_LIMIT ).round ().toString () + " 小时前" ;
72- } else if (subTime < DAYS_LIMIT ) {
73- return (subTime / HOURS_LIMIT ).round ().toString () + " 天前" ;
63+ var cur = DateTime .now ();
64+ Duration subTime;
65+ if (date.timeZoneOffset != cur.timeZoneOffset) {
66+ subTime = DateTime .now ().difference (date.subtract (cur.timeZoneOffset));
67+ } else {
68+ subTime = DateTime .now ().difference (date);
69+ }
70+
71+ if (subTime.inMilliseconds < MILLIS_LIMIT ) {
72+ return (curLocale != null )
73+ ? (curLocale.languageCode != "zh" ) ? "right now" : "刚刚"
74+ : "刚刚" ;
75+ } else if (subTime.inMilliseconds < SECONDS_LIMIT ) {
76+ return (subTime.inMilliseconds / MILLIS_LIMIT ).round ().toString () +
77+ ((curLocale != null )
78+ ? (curLocale.languageCode != "zh" ) ? " seconds ago" : " 秒前"
79+ : " 秒前" );
80+ } else if (subTime.inMilliseconds < MINUTES_LIMIT ) {
81+ return (subTime.inMilliseconds / SECONDS_LIMIT ).round ().toString () +
82+ ((curLocale != null )
83+ ? (curLocale.languageCode != "zh" ) ? " min ago" : " 分钟前"
84+ : " 分钟前" );
85+ } else if (subTime.inMilliseconds < HOURS_LIMIT ) {
86+ return (subTime.inMilliseconds / MINUTES_LIMIT ).round ().toString () +
87+ ((curLocale != null )
88+ ? (curLocale.languageCode != "zh" ) ? " hours ago" : " 小时前"
89+ : " 小时前" );
90+ } else if (subTime.inMilliseconds < DAYS_LIMIT ) {
91+ return (subTime.inMilliseconds / HOURS_LIMIT ).round ().toString () +
92+ ((curLocale != null )
93+ ? (curLocale.languageCode != "zh" ) ? " days ago" : " 天前"
94+ : " 天前" );
7495 } else {
7596 return getDateStr (date);
7697 }
@@ -148,7 +169,6 @@ class CommonUtils {
148169 return ThemeData (primarySwatch: color, platform: TargetPlatform .android);
149170 }
150171
151-
152172 static showLanguageDialog (BuildContext context, Store store) {
153173 List <String > list = [
154174 CommonUtils .getLocale (context).home_language_default,
@@ -174,6 +194,7 @@ class CommonUtils {
174194 locale = Locale ('en' , 'US' );
175195 break ;
176196 }
197+ curLocale = locale;
177198 store.dispatch (RefreshLocaleAction (locale));
178199 }
179200
0 commit comments