-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathUtils.java
41 lines (33 loc) · 1.21 KB
/
Utils.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.brunoaybar.unofficialupc.utils;
import com.brunoaybar.unofficialupc.data.models.errors.NoInternetException;
import com.brunoaybar.unofficialupc.data.source.remote.responses.ServiceException;
import java.util.Calendar;
import java.util.Date;
/**
* Created by brunoaybar on 16/10/2016.
*/
public class Utils {
public static boolean isEmpty(String text){
return text==null || text.length()<1;
}
public static boolean sameDay(Date date1, Date date2){
Calendar cal1 = Calendar.getInstance();
Calendar cal2 = Calendar.getInstance();
cal1.setTime(date1);
cal2.setTime(date2);
return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
}
public static Throwable getError(String defaultMessage){
return getError(null,defaultMessage);
}
public static Throwable getError(Throwable source, String defaultMessage){
if(source instanceof NoInternetException){
return source;
} else if(source instanceof ServiceException){
return source;
} else{
return new Throwable(defaultMessage);
}
}
}