@@ -40,8 +40,6 @@ class CommonUtils {
4040
4141 static final double DAYS_LIMIT = 30 * HOURS_LIMIT ;
4242
43- static Locale curLocale;
44-
4543 static String getDateStr (DateTime date) {
4644 if (date == null || date.toString () == null ) {
4745 return "" ;
@@ -60,38 +58,19 @@ class CommonUtils {
6058
6159 ///日期格式转换
6260 static String getNewsTimeStr (DateTime date) {
63- var cur = DateTime .now ();
64- Duration subTime;
65- if (date.timeZoneOffset != cur.timeZoneOffset) {
66- subTime = cur.difference (date.subtract (cur.timeZoneOffset));
67- } else {
68- subTime = cur.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- : " 天前" );
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 () + " 天前" ;
9574 } else {
9675 return getDateStr (date);
9776 }
@@ -169,6 +148,7 @@ class CommonUtils {
169148 return ThemeData (primarySwatch: color, platform: TargetPlatform .android);
170149 }
171150
151+
172152 static showLanguageDialog (BuildContext context, Store store) {
173153 List <String > list = [
174154 CommonUtils .getLocale (context).home_language_default,
@@ -194,7 +174,6 @@ class CommonUtils {
194174 locale = Locale ('en' , 'US' );
195175 break ;
196176 }
197- curLocale = locale;
198177 store.dispatch (RefreshLocaleAction (locale));
199178 }
200179
0 commit comments