Migrate to ThreeTenABP (#77)

This commit is contained in:
Rafał Borcz 2018-04-05 21:56:08 +02:00 committed by Mikołaj Pich
parent 5c9f10fa50
commit c72e7748e2
4 changed files with 22 additions and 19 deletions

View File

@ -80,9 +80,9 @@ dependencies {
implementation "org.greenrobot:greendao:$greenDao" implementation "org.greenrobot:greendao:$greenDao"
implementation "com.github.yuweiguocn:GreenDaoUpgradeHelper:$greenDaoHelper" implementation "com.github.yuweiguocn:GreenDaoUpgradeHelper:$greenDaoHelper"
implementation "com.jakewharton:butterknife:$butterknife" implementation "com.jakewharton:butterknife:$butterknife"
implementation "joda-time:joda-time:$jodaTime"
implementation "com.google.dagger:dagger-android-support:$dagger2" implementation "com.google.dagger:dagger-android-support:$dagger2"
implementation "com.aurelhubert:ahbottomnavigation:$ahbottom" implementation "com.aurelhubert:ahbottomnavigation:$ahbottom"
implementation "com.jakewharton.threetenabp:threetenabp:$threeTenABP"
implementation("com.crashlytics.sdk.android:crashlytics:$crashlyticsSdk@aar") { implementation("com.crashlytics.sdk.android:crashlytics:$crashlyticsSdk@aar") {
transitive = true transitive = true

View File

@ -4,6 +4,7 @@ import android.app.Application;
import com.crashlytics.android.Crashlytics; import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.core.CrashlyticsCore; import com.crashlytics.android.core.CrashlyticsCore;
import com.jakewharton.threetenabp.AndroidThreeTen;
import org.greenrobot.greendao.query.QueryBuilder; import org.greenrobot.greendao.query.QueryBuilder;
@ -28,6 +29,8 @@ public class WulkanowyApp extends Application {
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
AndroidThreeTen.init(this);
applicationComponent = DaggerApplicationComponent applicationComponent = DaggerApplicationComponent
.builder() .builder()
.applicationModule(new ApplicationModule(this)) .applicationModule(new ApplicationModule(this))

View File

@ -1,8 +1,8 @@
package io.github.wulkanowy.utils; package io.github.wulkanowy.utils;
import org.joda.time.DateTime; import org.threeten.bp.DayOfWeek;
import org.joda.time.DateTimeConstants; import org.threeten.bp.LocalDate;
import org.joda.time.LocalDate; import org.threeten.bp.format.DateTimeFormatter;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -13,14 +13,14 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.TimeZone; import java.util.TimeZone;
import static io.github.wulkanowy.utils.AppConstant.DATE_PATTERN;
public final class TimeUtils { public final class TimeUtils {
private static final long TICKS_AT_EPOCH = 621355968000000000L; private static final long TICKS_AT_EPOCH = 621355968000000000L;
private static final long TICKS_PER_MILLISECOND = 10000; private static final long TICKS_PER_MILLISECOND = 10000;
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(AppConstant.DATE_PATTERN);
private TimeUtils() { private TimeUtils() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
@ -33,7 +33,7 @@ public final class TimeUtils {
} }
public static long getNetTicks(String dateString) throws ParseException { public static long getNetTicks(String dateString) throws ParseException {
return getNetTicks(dateString, DATE_PATTERN); return getNetTicks(dateString, AppConstant.DATE_PATTERN);
} }
public static long getNetTicks(String dateString, String dateFormat) throws ParseException { public static long getNetTicks(String dateString, String dateFormat) throws ParseException {
@ -49,12 +49,12 @@ public final class TimeUtils {
} }
public static List<String> getMondaysFromCurrentSchoolYear() { public static List<String> getMondaysFromCurrentSchoolYear() {
LocalDate startDate = new LocalDate(getCurrentSchoolYear(), 9, 1); LocalDate startDate = LocalDate.of(getCurrentSchoolYear(), 9, 1);
LocalDate endDate = new LocalDate(getCurrentSchoolYear() + 1, 8, 31); LocalDate endDate = LocalDate.of(getCurrentSchoolYear() + 1, 8, 31);
List<String> dateList = new ArrayList<>(); List<String> dateList = new ArrayList<>();
LocalDate thisMonday = startDate.withDayOfWeek(DateTimeConstants.MONDAY); LocalDate thisMonday = startDate.with(DayOfWeek.MONDAY);
if (startDate.isAfter(thisMonday)) { if (startDate.isAfter(thisMonday)) {
startDate = thisMonday.plusWeeks(1); startDate = thisMonday.plusWeeks(1);
@ -63,27 +63,27 @@ public final class TimeUtils {
} }
while (startDate.isBefore(endDate)) { while (startDate.isBefore(endDate)) {
dateList.add(startDate.toString(DATE_PATTERN)); dateList.add(startDate.format(formatter));
startDate = startDate.plusWeeks(1); startDate = startDate.plusWeeks(1);
} }
return dateList; return dateList;
} }
public static int getCurrentSchoolYear() { public static int getCurrentSchoolYear() {
DateTime dateTime = new DateTime(); LocalDate localDate = LocalDate.now();
return dateTime.getMonthOfYear() <= 8 ? dateTime.getYear() - 1 : dateTime.getYear(); return localDate.getMonthValue() <= 8 ? localDate.getYear() - 1 : localDate.getYear();
} }
public static String getDateOfCurrentMonday(boolean normalize) { public static String getDateOfCurrentMonday(boolean normalize) {
DateTime currentDate = new DateTime(); LocalDate currentDate = LocalDate.now();
if (currentDate.getDayOfWeek() == DateTimeConstants.SATURDAY && normalize) { if (currentDate.getDayOfWeek() == DayOfWeek.SATURDAY && normalize) {
currentDate = currentDate.plusDays(2); currentDate = currentDate.plusDays(2);
} else if (currentDate.getDayOfWeek() == DateTimeConstants.SUNDAY && normalize) { } else if (currentDate.getDayOfWeek() == DayOfWeek.SUNDAY && normalize) {
currentDate = currentDate.plusDays(1); currentDate = currentDate.plusDays(1);
} else { } else {
currentDate = currentDate.withDayOfWeek(DateTimeConstants.MONDAY); currentDate = currentDate.with(DayOfWeek.MONDAY);
} }
return currentDate.toString(DATE_PATTERN); return currentDate.format(formatter);
} }
} }

View File

@ -36,7 +36,7 @@ ext {
greenDao = "3.2.2" greenDao = "3.2.2"
greenDaoHelper = "v2.0.2" greenDaoHelper = "v2.0.2"
butterknife = "8.8.1" butterknife = "8.8.1"
jodaTime = "2.9.9" threeTenABP = "1.0.5"
dagger2 = "2.15" dagger2 = "2.15"
ahbottom = "2.1.0" ahbottom = "2.1.0"
jsoup = "1.10.3" jsoup = "1.10.3"