3
3
import android .content .Context ;
4
4
import android .support .test .InstrumentationRegistry ;
5
5
import android .support .test .runner .AndroidJUnit4 ;
6
- import android .util .Log ;
7
-
8
- import com .rae .core .utils .RaeDateUtil ;
9
6
10
7
import org .junit .Test ;
11
8
import org .junit .runner .RunWith ;
12
9
13
- import java .util .Calendar ;
14
- import java .util .Date ;
15
- import java .util .regex .Matcher ;
16
- import java .util .regex .Pattern ;
17
-
18
10
import static org .junit .Assert .assertEquals ;
19
11
20
12
/**
@@ -32,58 +24,58 @@ public void useAppContext() throws Exception {
32
24
assertEquals ("com.rae.cnblogs" , appContext .getPackageName ());
33
25
}
34
26
35
- @ Test
36
- public void testDate () {
37
- Log .d ("rae" , "测试今天:" + getDate ("2016-12-06 00:00:00" ));
38
- Log .d ("rae" , "测试昨天:" + getDate ("2016-12-05 23:30" ));
39
- Log .d ("rae" , "测试前天:" + getDate ("2016-12-04 12:30" ));
40
- Log .d ("rae" , "测试其他时间:" + getDate ("2016-11-02 12:30" ));
41
- }
42
-
43
-
44
- private String getDate (String text ) {
45
-
46
- String regx = "\\ d{4}-\\ d{2}-\\ d{2} \\ d{2}:\\ d{2}" ;
47
- Matcher matcher = Pattern .compile (regx ).matcher (text );
48
- if (!matcher .find ()) {
49
- return text ;
50
- }
51
-
52
- text = matcher .group ();
53
- String time = text .split (" " )[1 ];
54
-
55
- // 时间间隔
56
- long span = (System .currentTimeMillis () - parseDate (text ).getTime ()) / 1000 ;
57
-
58
- // 今天过去的时间
59
- Calendar calendar = Calendar .getInstance ();
60
- calendar .set (Calendar .HOUR , 0 );
61
- calendar .set (Calendar .MINUTE , 0 );
62
- calendar .set (Calendar .SECOND , 0 );
63
- calendar .set (Calendar .MILLISECOND , 0 );
64
-
65
- long today = (System .currentTimeMillis () - calendar .getTimeInMillis ()) / 1000 ;
66
- if (span < today ) {
67
- text = "今天 " + time ;
68
- } else if (span < today + 86400 ) {
69
- text = "昨天 " + time ;
70
- } else if (span < today + 2 * 86400 ) {
71
- text = "前天 " + time ;
72
- }
73
-
74
-
75
- return text ;
76
- }
77
-
78
- private Date parseDate (String text ) {
79
- Date target ;
80
- try {
81
- target = RaeDateUtil .parse (text , "yyyy-MM-dd HH:mm" );
82
- } catch (Exception e ) {
83
- Log .e ("rae" , "解析出错!" , e );
84
- target = new Date ();
85
- }
86
- return target ;
87
- }
27
+ // @Test
28
+ // public void testDate() {
29
+ // Log.d("rae", "测试今天:" + getDate("2016-12-06 00:00:00"));
30
+ // Log.d("rae", "测试昨天:" + getDate("2016-12-05 23:30"));
31
+ // Log.d("rae", "测试前天:" + getDate("2016-12-04 12:30"));
32
+ // Log.d("rae", "测试其他时间:" + getDate("2016-11-02 12:30"));
33
+ // }
34
+
35
+
36
+ // private String getDate(String text) {
37
+ //
38
+ // String regx = "\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}";
39
+ // Matcher matcher = Pattern.compile(regx).matcher(text);
40
+ // if (!matcher.find()) {
41
+ // return text;
42
+ // }
43
+ //
44
+ // text = matcher.group();
45
+ // String time = text.split(" ")[1];
46
+ //
47
+ // // 时间间隔
48
+ // long span = (System.currentTimeMillis() - parseDate(text).getTime()) / 1000;
49
+ //
50
+ // // 今天过去的时间
51
+ // Calendar calendar = Calendar.getInstance();
52
+ // calendar.set(Calendar.HOUR, 0);
53
+ // calendar.set(Calendar.MINUTE, 0);
54
+ // calendar.set(Calendar.SECOND, 0);
55
+ // calendar.set(Calendar.MILLISECOND, 0);
56
+ //
57
+ // long today = (System.currentTimeMillis() - calendar.getTimeInMillis()) / 1000;
58
+ // if (span < today) {
59
+ // text = "今天 " + time;
60
+ // } else if (span < today + 86400) {
61
+ // text = "昨天 " + time;
62
+ // } else if (span < today + 2 * 86400) {
63
+ // text = "前天 " + time;
64
+ // }
65
+ //
66
+ //
67
+ // return text;
68
+ // }
69
+
70
+ // private Date parseDate(String text) {
71
+ // Date target;
72
+ // try {
73
+ // target = RaeDateUtil.parse(text, "yyyy-MM-dd HH:mm");
74
+ // } catch (Exception e) {
75
+ // Log.e("rae", "解析出错!", e);
76
+ // target = new Date();
77
+ // }
78
+ // return target;
79
+ // }
88
80
89
81
}
0 commit comments