implementata libreria compatibilità LocalDate
This commit is contained in:
parent
8aad7337bf
commit
79ec6430f6
@ -41,6 +41,7 @@ android {
|
|||||||
versionName appVersionName
|
versionName appVersionName
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
signingConfig signingConfigs.release
|
signingConfig signingConfigs.release
|
||||||
|
multiDexEnabled true
|
||||||
|
|
||||||
javaCompileOptions {
|
javaCompileOptions {
|
||||||
annotationProcessorOptions {
|
annotationProcessorOptions {
|
||||||
@ -66,7 +67,7 @@ android {
|
|||||||
compileOptions {
|
compileOptions {
|
||||||
sourceCompatibility JavaVersion.VERSION_11
|
sourceCompatibility JavaVersion.VERSION_11
|
||||||
targetCompatibility JavaVersion.VERSION_11
|
targetCompatibility JavaVersion.VERSION_11
|
||||||
//coreLibraryDesugaringEnabled true
|
coreLibraryDesugaringEnabled true
|
||||||
}
|
}
|
||||||
|
|
||||||
productFlavors {
|
productFlavors {
|
||||||
@ -115,7 +116,7 @@ dependencies {
|
|||||||
implementation 'com.google.android.gms:play-services-basement:18.1.0'
|
implementation 'com.google.android.gms:play-services-basement:18.1.0'
|
||||||
|
|
||||||
|
|
||||||
implementation 'androidx.appcompat:appcompat:1.6.0'
|
implementation 'androidx.appcompat:appcompat:1.6.1'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.8.0'
|
implementation 'com.google.android.material:material:1.8.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
|
||||||
@ -188,7 +189,7 @@ dependencies {
|
|||||||
// RxJava is also required.
|
// RxJava is also required.
|
||||||
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
|
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
|
||||||
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
|
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
|
||||||
|
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.2'
|
||||||
}
|
}
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
package it.integry.integrywmsnative.core.rest;
|
package it.integry.integrywmsnative.core.rest;
|
||||||
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
|
||||||
@ -62,11 +60,14 @@ public class RESTBuilder {
|
|||||||
String endpoint = "http://" + host + ":" + port + "/" + (addEmsApi ? "ems-api/" : "");
|
String endpoint = "http://" + host + ":" + port + "/" + (addEmsApi ? "ems-api/" : "");
|
||||||
|
|
||||||
|
|
||||||
GsonBuilder builder = new GsonBuilder().setDateFormat("dd/MM/yyyy HH:mm:ss").excludeFieldsWithModifiers(Modifier.TRANSIENT);
|
Gson gson = new GsonBuilder()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
.setDateFormat("dd/MM/yyyy HH:mm:ss")
|
||||||
builder.registerTypeAdapter(LocalDate.class, new LocalDateDeserializer()).registerTypeAdapter(LocalDate.class, new LocalDateSerializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer()).registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer());
|
.excludeFieldsWithModifiers(Modifier.TRANSIENT)
|
||||||
}
|
.registerTypeAdapter(LocalDate.class, new LocalDateDeserializer())
|
||||||
Gson gson = builder.create();
|
.registerTypeAdapter(LocalDate.class, new LocalDateSerializer())
|
||||||
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeDeserializer())
|
||||||
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeSerializer())
|
||||||
|
.create();
|
||||||
|
|
||||||
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(endpoint).client(client).build();
|
Retrofit retrofit = new Retrofit.Builder().addConverterFactory(GsonConverterFactory.create(gson)).baseUrl(endpoint).client(client).build();
|
||||||
|
|
||||||
|
|||||||
@ -44,9 +44,9 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Date recognizeDateWithExceptionHandler(String dateString) {
|
public static Date recognizeDateWithExceptionHandler(String dateString) {
|
||||||
try{
|
try {
|
||||||
return UtilityDate.recognizeDate(dateString);
|
return UtilityDate.recognizeDate(dateString);
|
||||||
} catch (ParseException | DateNotRecognizedException | TimeNotRecognizedException pex){
|
} catch (ParseException | DateNotRecognizedException | TimeNotRecognizedException pex) {
|
||||||
UtilityLogger.error(pex);
|
UtilityLogger.error(pex);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -64,9 +64,9 @@ public class UtilityDate {
|
|||||||
char dateSeparator;
|
char dateSeparator;
|
||||||
|
|
||||||
String onlyDateSubstring = dateString.substring(0, 10);
|
String onlyDateSubstring = dateString.substring(0, 10);
|
||||||
if(onlyDateSubstring.contains("/")) dateSeparator = '/';
|
if (onlyDateSubstring.contains("/")) dateSeparator = '/';
|
||||||
else if(onlyDateSubstring.contains("-")) dateSeparator = '-';
|
else if (onlyDateSubstring.contains("-")) dateSeparator = '-';
|
||||||
else if(onlyDateSubstring.contains(".")) dateSeparator = '.';
|
else if (onlyDateSubstring.contains(".")) dateSeparator = '.';
|
||||||
else throw new DateNotRecognizedException(dateString);
|
else throw new DateNotRecognizedException(dateString);
|
||||||
|
|
||||||
String dateFormatString = (dateString.charAt(2) == dateSeparator)
|
String dateFormatString = (dateString.charAt(2) == dateSeparator)
|
||||||
@ -74,13 +74,13 @@ public class UtilityDate {
|
|||||||
: "yyyy" + dateSeparator + "MM" + dateSeparator + "dd";
|
: "yyyy" + dateSeparator + "MM" + dateSeparator + "dd";
|
||||||
|
|
||||||
|
|
||||||
if(dateString.length() > 10){
|
if (dateString.length() > 10) {
|
||||||
|
|
||||||
char timeSeparator;
|
char timeSeparator;
|
||||||
|
|
||||||
String onlyTimeSubstring = dateString.substring(10, 14);
|
String onlyTimeSubstring = dateString.substring(10, 14);
|
||||||
if(onlyTimeSubstring.contains("-")) timeSeparator = '-';
|
if (onlyTimeSubstring.contains("-")) timeSeparator = '-';
|
||||||
else if(onlyTimeSubstring.contains(":")) timeSeparator = ':';
|
else if (onlyTimeSubstring.contains(":")) timeSeparator = ':';
|
||||||
else throw new TimeNotRecognizedException(dateString);
|
else throw new TimeNotRecognizedException(dateString);
|
||||||
|
|
||||||
String timeFormatString = "HH" + timeSeparator + "mm" + timeSeparator + "ss";
|
String timeFormatString = "HH" + timeSeparator + "mm" + timeSeparator + "ss";
|
||||||
@ -99,12 +99,11 @@ public class UtilityDate {
|
|||||||
|
|
||||||
|
|
||||||
public static String formatDate(Date dateToFormat, String format) {
|
public static String formatDate(Date dateToFormat, String format) {
|
||||||
if(dateToFormat != null) {
|
if (dateToFormat != null) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||||
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
//sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
|
||||||
return sdf.format(dateToFormat);
|
return sdf.format(dateToFormat);
|
||||||
}
|
} else return null;
|
||||||
else return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -116,7 +115,7 @@ public class UtilityDate {
|
|||||||
public static Date getDateInstance(boolean removeTime) {
|
public static Date getDateInstance(boolean removeTime) {
|
||||||
var calendar = getCalendarInstance();
|
var calendar = getCalendarInstance();
|
||||||
|
|
||||||
if(removeTime) {
|
if (removeTime) {
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
calendar.set(Calendar.SECOND, 0);
|
calendar.set(Calendar.SECOND, 0);
|
||||||
@ -131,8 +130,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String formatDate(LocalDate dateToFormat, String format) {
|
public static String formatDate(LocalDate dateToFormat, String format) {
|
||||||
if (dateToFormat != null) {
|
if (dateToFormat != null) {
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
|
||||||
@ -185,7 +182,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static LocalDate getNow() {
|
public static LocalDate getNow() {
|
||||||
return Instant.now()
|
return Instant.now()
|
||||||
.atZone(currentZone)
|
.atZone(currentZone)
|
||||||
@ -197,6 +193,7 @@ public class UtilityDate {
|
|||||||
.atZone(currentZone)
|
.atZone(currentZone)
|
||||||
.toLocalDateTime();
|
.toLocalDateTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LocalDate timeToLocalDate(long time, @Nullable String timezone) {
|
public static LocalDate timeToLocalDate(long time, @Nullable String timezone) {
|
||||||
return Instant.ofEpochSecond(time)
|
return Instant.ofEpochSecond(time)
|
||||||
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
||||||
@ -210,7 +207,6 @@ public class UtilityDate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static long localDateTimeToTime(LocalDateTime localDateTime, @Nullable String timezone) {
|
public static long localDateTimeToTime(LocalDateTime localDateTime, @Nullable String timezone) {
|
||||||
return localDateTime
|
return localDateTime
|
||||||
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
.atZone(timezone == null ? currentZone : ZoneId.of(timezone))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user