|
32 | 32 | */ |
33 | 33 | public final class DateTimeConverterUtil { |
34 | 34 |
|
35 | | - /** |
36 | | - * The date format of the input parameters. |
37 | | - */ |
38 | | - private static final String INPUT_DATE_FORMAT = "yyyy-MM-dd"; |
| 35 | + /** |
| 36 | + * The date format of the input parameters. |
| 37 | + */ |
| 38 | + private static final String INPUT_DATE_FORMAT = "yyyy-MM-dd"; |
39 | 39 |
|
40 | | - /** |
41 | | - * The date format of JIRA. |
42 | | - */ |
43 | | - private static final String JIRA_OUTPUT_DATE_TIME_FORMAT = "yyyy-MM-dd hh:mm:ss.s"; |
| 40 | + /** |
| 41 | + * The date format of JIRA. |
| 42 | + */ |
| 43 | + private static final String JIRA_OUTPUT_DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss.s"; |
44 | 44 |
|
45 | | - /** |
46 | | - * The date format of the output. |
47 | | - */ |
48 | | - private static final String OUTPUT_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; |
| 45 | + /** |
| 46 | + * The date format of the output. |
| 47 | + */ |
| 48 | + private static final String OUTPUT_DATE_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ssZ"; |
49 | 49 |
|
50 | | - /** |
51 | | - * Convert the date to String ({@value #OUTPUT_DATE_TIME_FORMAT}). |
52 | | - * |
53 | | - * @param date |
54 | | - * The Date to convert. |
55 | | - * @return The result time. |
56 | | - */ |
57 | | - private static String dateToString(final Date date) { |
58 | | - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OUTPUT_DATE_TIME_FORMAT); |
59 | | - String dateString = simpleDateFormat.format(date); |
60 | | - return dateString; |
61 | | - } |
| 50 | + /** |
| 51 | + * Convert the date to String ({@value #OUTPUT_DATE_TIME_FORMAT}). |
| 52 | + * |
| 53 | + * @param date |
| 54 | + * The Date to convert. |
| 55 | + * @return The result time. |
| 56 | + */ |
| 57 | + private static String dateToString(final Date date) { |
| 58 | + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(OUTPUT_DATE_TIME_FORMAT); |
| 59 | + String dateString = simpleDateFormat.format(date); |
| 60 | + return dateString; |
| 61 | + } |
62 | 62 |
|
63 | | - /** |
64 | | - * Convert String ({@value #INPUT_DATE_FORMAT}) to Calendar. |
65 | | - * |
66 | | - * @param dateString |
67 | | - * The String date to convert. |
68 | | - * @return The result Date. |
69 | | - * @throws ParseException |
70 | | - * If can't parse the date. |
71 | | - */ |
72 | | - public static Calendar inputStringToCalendar(final String dateString) throws ParseException { |
73 | | - DateFormat dateFormat = new SimpleDateFormat(INPUT_DATE_FORMAT); |
74 | | - Calendar calendar = Calendar.getInstance(); |
75 | | - calendar.setTime(dateFormat.parse(dateString)); |
76 | | - return calendar; |
77 | | - } |
| 63 | + /** |
| 64 | + * Convert String ({@value #INPUT_DATE_FORMAT}) to Calendar. |
| 65 | + * |
| 66 | + * @param dateString |
| 67 | + * The String date to convert. |
| 68 | + * @return The result Date. |
| 69 | + * @throws ParseException |
| 70 | + * If can't parse the date. |
| 71 | + */ |
| 72 | + public static Calendar inputStringToCalendar(final String dateString) throws ParseException { |
| 73 | + DateFormat dateFormat = new SimpleDateFormat(INPUT_DATE_FORMAT); |
| 74 | + Calendar calendar = Calendar.getInstance(); |
| 75 | + calendar.setTime(dateFormat.parse(dateString)); |
| 76 | + return calendar; |
| 77 | + } |
78 | 78 |
|
79 | | - /** |
80 | | - * Set the calendar hour, minute and second value. |
81 | | - * |
82 | | - * @param originalCalendar |
83 | | - * The original calendar. |
84 | | - * @param hourOfDay |
85 | | - * The hour of the day to set. |
86 | | - * @param minute |
87 | | - * The minute to set. |
88 | | - * @param second |
89 | | - * The second to set. |
90 | | - * @return The new calendar object. |
91 | | - */ |
92 | | - public static Calendar setCalendarHourMinSec(final Calendar originalCalendar, final int hourOfDay, |
93 | | - final int minute, final int second) { |
94 | | - Calendar calendar = Calendar.getInstance(); |
95 | | - calendar.set( |
96 | | - originalCalendar.get(Calendar.YEAR), |
97 | | - originalCalendar.get(Calendar.MONTH), |
98 | | - originalCalendar.get(Calendar.DAY_OF_MONTH), |
99 | | - hourOfDay, |
100 | | - minute, |
101 | | - second); |
102 | | - return calendar; |
103 | | - } |
| 79 | + /** |
| 80 | + * Set the calendar hour, minute and second value. |
| 81 | + * |
| 82 | + * @param originalCalendar |
| 83 | + * The original calendar. |
| 84 | + * @param hourOfDay |
| 85 | + * The hour of the day to set. |
| 86 | + * @param minute |
| 87 | + * The minute to set. |
| 88 | + * @param second |
| 89 | + * The second to set. |
| 90 | + * @return The new calendar object. |
| 91 | + */ |
| 92 | + public static Calendar setCalendarHourMinSec(final Calendar originalCalendar, |
| 93 | + final int hourOfDay, |
| 94 | + final int minute, final int second) { |
| 95 | + Calendar calendar = Calendar.getInstance(); |
| 96 | + calendar.set( |
| 97 | + originalCalendar.get(Calendar.YEAR), |
| 98 | + originalCalendar.get(Calendar.MONTH), |
| 99 | + originalCalendar.get(Calendar.DAY_OF_MONTH), |
| 100 | + hourOfDay, |
| 101 | + minute, |
| 102 | + second); |
| 103 | + return calendar; |
| 104 | + } |
104 | 105 |
|
105 | | - /** |
106 | | - * Format a String date to valid ISO-8601 format String date. |
107 | | - * |
108 | | - * @param dateString |
109 | | - * The date. |
110 | | - * @return The formated String date. |
111 | | - * @throws ParseException |
112 | | - * If cannot parse the String to Date. |
113 | | - */ |
114 | | - public static String stringDateToISO8601FormatString(final String dateString) throws ParseException { |
115 | | - DateFormat dateFormat = new SimpleDateFormat(JIRA_OUTPUT_DATE_TIME_FORMAT); |
116 | | - Date date = dateFormat.parse(dateString); |
117 | | - return DateTimeConverterUtil.dateToString(date); |
118 | | - } |
| 106 | + /** |
| 107 | + * Format a String date to valid ISO-8601 format String date. |
| 108 | + * |
| 109 | + * @param dateString |
| 110 | + * The date. |
| 111 | + * @return The formated String date. |
| 112 | + * @throws ParseException |
| 113 | + * If cannot parse the String to Date. |
| 114 | + */ |
| 115 | + public static String stringDateToISO8601FormatString(final String dateString) |
| 116 | + throws ParseException { |
| 117 | + DateFormat dateFormat = new SimpleDateFormat(JIRA_OUTPUT_DATE_TIME_FORMAT); |
| 118 | + Date date = dateFormat.parse(dateString); |
| 119 | + return DateTimeConverterUtil.dateToString(date); |
| 120 | + } |
119 | 121 |
|
120 | | - /** |
121 | | - * Private constructor. |
122 | | - */ |
123 | | - private DateTimeConverterUtil() { |
124 | | - } |
| 122 | + /** |
| 123 | + * Private constructor. |
| 124 | + */ |
| 125 | + private DateTimeConverterUtil() { |
| 126 | + } |
125 | 127 |
|
126 | 128 | } |
0 commit comments