mac
2024-04-28 a034e242fe844a1ca45d2a28710cb7face1f8fe6
app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
@@ -4,6 +4,7 @@
import android.text.TextUtils;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.enums.TimeType;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.home.HomePageFragment;
import com.hdl.sdk.link.core.utils.LanguageUtils;
@@ -113,14 +114,22 @@
     * @param dayMonthYearToAdd 天数(日,月,年)
     * @return 日历
     */
    public static String addDayMonthYearToDate(Calendar date, int dayMonthYearToAdd, String dateFormat, HomePageFragment.TimeType timeType) {
    public static String addDayMonthYearToDate(Calendar date, int dayMonthYearToAdd, String dateFormat, String timeType) {
        Calendar newDate = (Calendar) date.clone();
        if (timeType == HomePageFragment.TimeType.day) {
            newDate.add(Calendar.DAY_OF_MONTH, dayMonthYearToAdd);
        } else if (timeType == HomePageFragment.TimeType.month) {
            newDate.add(Calendar.MONTH, dayMonthYearToAdd);
        } else if (timeType == HomePageFragment.TimeType.year || timeType == HomePageFragment.TimeType.lifecycle) {
            newDate.add(Calendar.YEAR, dayMonthYearToAdd);
        switch (timeType) {
            case TimeType.day: {
                newDate.add(Calendar.DAY_OF_MONTH, dayMonthYearToAdd);
            }
            break;
            case TimeType.month: {
                newDate.add(Calendar.MONTH, dayMonthYearToAdd);
            }
            break;
            case TimeType.year:
            case TimeType.all: {
                newDate.add(Calendar.YEAR, dayMonthYearToAdd);
            }
            break;
        }
        return calendarToString(newDate, dateFormat);
    }
@@ -132,14 +141,22 @@
     * @param dayMonthYearToSubtract 天数
     * @return 日历
     */
    public static String subtractDayMonthYearFromDate(Calendar date, int dayMonthYearToSubtract, String dateFormat, HomePageFragment.TimeType timeType) {
    public static String subtractDayMonthYearFromDate(Calendar date, int dayMonthYearToSubtract, String dateFormat, String timeType) {
        Calendar newDate = (Calendar) date.clone();
        if (timeType == HomePageFragment.TimeType.day) {
            newDate.add(Calendar.DAY_OF_MONTH, -dayMonthYearToSubtract);
        } else if (timeType == HomePageFragment.TimeType.month) {
            newDate.add(Calendar.MONTH, -dayMonthYearToSubtract);
        } else if (timeType == HomePageFragment.TimeType.year) {
            newDate.add(Calendar.YEAR, -dayMonthYearToSubtract);
        switch (timeType) {
            case TimeType.day: {
                newDate.add(Calendar.DAY_OF_MONTH, -dayMonthYearToSubtract);
            }
            break;
            case TimeType.month: {
                newDate.add(Calendar.MONTH, -dayMonthYearToSubtract);
            }
            break;
            case TimeType.year:
            case TimeType.all: {
                newDate.add(Calendar.YEAR, -dayMonthYearToSubtract);
            }
            break;
        }
        return calendarToString(newDate, dateFormat);
    }