FIX IssueComments moddel (#425)
Reformat Code FIX IssueComments moddel reformate Code TimeHelper.formatTime dont crash on null date object Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://gitea.com/gitnex/GitNex/pulls/425 Reviewed-by: M M Arif <mmarif@swatian.com>
This commit is contained in:
@@ -16,77 +16,82 @@ import java.util.Locale;
|
||||
|
||||
public class TimeHelper {
|
||||
|
||||
public static String customDateFormatForToast(String customDate) {
|
||||
public static String customDateFormatForToast(String customDate) {
|
||||
|
||||
String[] parts = customDate.split("\\+");
|
||||
String part1 = parts[0] + "Z";
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
|
||||
Date createdTime = null;
|
||||
try {
|
||||
createdTime = formatter.parse(part1);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String[] parts = customDate.split("\\+");
|
||||
String part1 = parts[0] + "Z";
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
|
||||
Date createdTime = null;
|
||||
try {
|
||||
createdTime = formatter.parse(part1);
|
||||
}
|
||||
catch(ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(createdTime);
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(createdTime);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatTime(Date date, Locale locale, String timeFormat, Context context) {
|
||||
public static String formatTime(Date date, Locale locale, String timeFormat, Context context) {
|
||||
|
||||
switch (timeFormat) {
|
||||
if(date == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
|
||||
return prettyTime.format(date);
|
||||
}
|
||||
switch(timeFormat) {
|
||||
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||
return formatter.format(date);
|
||||
}
|
||||
case "pretty": {
|
||||
PrettyTime prettyTime = new PrettyTime(Locale.getDefault());
|
||||
return prettyTime.format(date);
|
||||
}
|
||||
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||
return formatter.format(date);
|
||||
}
|
||||
case "normal": {
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
}
|
||||
case "normal1": {
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale);
|
||||
return formatter.format(date);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public static String customDateFormatForToastDateFormat(Date customDate) {
|
||||
return "";
|
||||
}
|
||||
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(customDate);
|
||||
public static String customDateFormatForToastDateFormat(Date customDate) {
|
||||
|
||||
}
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(customDate);
|
||||
|
||||
public static boolean timeBetweenHours(int fromHour, int toHour) {
|
||||
}
|
||||
|
||||
Calendar cal = Calendar.getInstance();
|
||||
public static boolean timeBetweenHours(int fromHour, int toHour) {
|
||||
|
||||
Calendar from = Calendar.getInstance();
|
||||
from.set(Calendar.HOUR_OF_DAY, fromHour);
|
||||
from.set(Calendar.MINUTE, 0);
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
Calendar to = Calendar.getInstance();
|
||||
to.set(Calendar.HOUR_OF_DAY, toHour);
|
||||
to.set(Calendar.MINUTE, 0);
|
||||
Calendar from = Calendar.getInstance();
|
||||
from.set(Calendar.HOUR_OF_DAY, fromHour);
|
||||
from.set(Calendar.MINUTE, 0);
|
||||
|
||||
if(to.before(from)) {
|
||||
if (cal.after(to)) {
|
||||
to.add(Calendar.DATE, 1);
|
||||
}
|
||||
else {
|
||||
from.add(Calendar.DATE, -1);
|
||||
}
|
||||
}
|
||||
Calendar to = Calendar.getInstance();
|
||||
to.set(Calendar.HOUR_OF_DAY, toHour);
|
||||
to.set(Calendar.MINUTE, 0);
|
||||
|
||||
return cal.after(from) && cal.before(to);
|
||||
if(to.before(from)) {
|
||||
if(cal.after(to)) {
|
||||
to.add(Calendar.DATE, 1);
|
||||
}
|
||||
else {
|
||||
from.add(Calendar.DATE, -1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return cal.after(from) && cal.before(to);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user