1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
package org.kuali.student.r2.core.class1.atp.service.impl; |
6 | |
|
7 | |
import java.text.DateFormat; |
8 | |
import java.text.ParseException; |
9 | |
import java.text.SimpleDateFormat; |
10 | |
import java.util.Date; |
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | 0 | public class DateUtil { |
19 | |
|
20 | 0 | private static DateFormat JUST_DATE = new SimpleDateFormat("yyyy-MM-dd"); |
21 | 0 | private static DateFormat END_OF_DAY = new SimpleDateFormat("yyyy-MM-dd kk:mm:ss.S"); |
22 | |
|
23 | |
public static Date startOfDay(Date date) { |
24 | 0 | if (date == null) { |
25 | 0 | return null; |
26 | |
} |
27 | 0 | String dateStr = JUST_DATE.format(date); |
28 | |
try { |
29 | 0 | Date newDate = JUST_DATE.parse(dateStr); |
30 | 0 | return newDate; |
31 | 0 | } catch (ParseException ex) { |
32 | 0 | throw new IllegalArgumentException(dateStr); |
33 | |
} |
34 | |
} |
35 | |
|
36 | |
public static Date endOfDay(Date date) { |
37 | 0 | if (date == null) { |
38 | 0 | return null; |
39 | |
} |
40 | 0 | String dateStr = JUST_DATE.format(date); |
41 | |
try { |
42 | 0 | Date newDate = END_OF_DAY.parse(dateStr + " 23:59:59.9"); |
43 | 0 | return newDate; |
44 | 0 | } catch (ParseException ex) { |
45 | 0 | throw new IllegalArgumentException(dateStr); |
46 | |
} |
47 | |
} |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
public static Date nullIfNotDateRange(boolean isDateRange, Date endDate) { |
55 | 0 | if (endDate == null) { |
56 | 0 | return null; |
57 | |
} |
58 | 0 | if (!isDateRange) { |
59 | 0 | return null; |
60 | |
} |
61 | 0 | return endDate; |
62 | |
} |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
public static Date startOfDayfIsAllDay(boolean isAllDay, Date date) { |
70 | 0 | if (date == null) { |
71 | 0 | return null; |
72 | |
} |
73 | 0 | if (!isAllDay) { |
74 | 0 | return date; |
75 | |
} |
76 | 0 | return DateUtil.startOfDay(date); |
77 | |
} |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public static Date endOfDayIfIsAllDay(boolean isAllDay, Date date) { |
85 | 0 | if (date == null) { |
86 | 0 | return null; |
87 | |
} |
88 | 0 | if (!isAllDay) { |
89 | 0 | return date; |
90 | |
} |
91 | 0 | return DateUtil.endOfDay(date); |
92 | |
} |
93 | |
} |