From b9cc7390e8e8ce64c41c26fb369c98ce669d660c Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 07 五月 2025 15:02:30 +0800
Subject: [PATCH] Merge branch '1.2.0'

---
 app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java |  142 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 119 insertions(+), 23 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java b/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
index 899010f..0091ead 100644
--- a/app/src/main/java/com/hdl/photovoltaic/utils/TimeUtils.java
+++ b/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;
@@ -23,8 +24,52 @@
     public static final String zhDateYearFormat = "yyyy";
 
     public static final String enDateYearMonthDayFormat = "dd/MM/yyyy";
-    public static final String enDateYearMonthFormat = "/MM/yyyy";
+    public static final String enDateYearMonthFormat = "MM/yyyy";
     public static final String enDateYearFormat = "yyyy";
+
+    /**
+     * 鑾峰彇褰撳墠绯荤粺鏃ユ湡鏃堕棿鎴�
+     *
+     * @return 鏃堕棿鎴�
+     */
+    public static long getCurrentTimestamp() {
+        return new Date().getTime();
+    }
+
+    /**
+     * 鑾峰彇鏃ユ湡鏍煎紡 (2024/2/09,yyyy/DD/dd)
+     *
+     * @return 鏃ユ湡鏍煎紡 (2024/2/09,yyyy/DD/dd)
+     */
+    public static String getTimeDateFormat(String timeType) {
+        String timeDateFormat = TimeUtils.zhDateYearMonthDayFormat;
+        switch (timeType) {
+            case TimeType.day: {
+                timeDateFormat = TimeUtils.zhDateYearMonthDayFormat;
+                if (!UserConfigManage.getInstance().isZh()) {
+                    timeDateFormat = TimeUtils.enDateYearMonthDayFormat;
+                }
+            }
+            break;
+            case TimeType.month: {
+                timeDateFormat = TimeUtils.zhDateYearMonthFormat;
+                if (!UserConfigManage.getInstance().isZh()) {
+                    timeDateFormat = TimeUtils.enDateYearMonthFormat;
+                }
+            }
+            break;
+            case TimeType.year:
+            case TimeType.all: {
+                timeDateFormat = TimeUtils.zhDateYearFormat;
+                if (!UserConfigManage.getInstance().isZh()) {
+                    timeDateFormat = TimeUtils.enDateYearFormat;
+                }
+            }
+            break;
+
+        }
+        return timeDateFormat;
+    }
 
     /**
      * 鑾峰彇鍒嗛挓
@@ -34,7 +79,7 @@
      */
     public static String getMinuteTime(long timestamp) {
         try {
-            SimpleDateFormat dateFormat = new SimpleDateFormat("mm", Locale.ENGLISH);
+            SimpleDateFormat dateFormat = new SimpleDateFormat("mm", getLocale());
             Date date = new Date(timestamp);
             return dateFormat.format(date);
         } catch (Exception e) {
@@ -52,7 +97,37 @@
      */
     public static String getDateTimestamp(long timestamp, String date_format) {
         try {
-            SimpleDateFormat dateFormat = new SimpleDateFormat(date_format, Locale.ENGLISH);
+            SimpleDateFormat dateFormat = new SimpleDateFormat(date_format, getLocale());
+            Date date = new Date(timestamp);
+            return dateFormat.format(date);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return "";
+    }
+
+    /**
+     * 鏃堕棿鎴宠浆鏃堕棿(鏍煎紡:yyyy-MM-dd HH:mm:ss)
+     *
+     * @param timestamp        鏃堕棿鎴�
+     * @param isDisplaySeconds 鏄惁鏄剧ず绉掞紝true鏄剧ず
+     * @return -
+     */
+    public static String getTimeFromTimestamp(long timestamp, boolean isDisplaySeconds) {
+        try {
+            String pattern = "yyyy-MM-dd HH:mm:ss";
+            if (isDisplaySeconds) {
+                pattern = "yyyy-MM-dd HH:mm:ss";
+                if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) {
+                    pattern = "dd-MM-yyyy HH:mm:ss";
+                }
+            } else {
+                pattern = "yyyy-MM-dd HH:mm";
+                if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) {
+                    pattern = "dd-MM-yyyy HH:mm";
+                }
+            }
+            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
             Date date = new Date(timestamp);
             return dateFormat.format(date);
         } catch (Exception e) {
@@ -65,7 +140,7 @@
      * 鏃堕棿鎴宠浆鏃堕棿(鏍煎紡:yyyy-MM-dd HH:mm:ss)
      *
      * @param timestamp 鏃堕棿鎴�
-     * @return -
+     *                  卢     * @return -
      */
     public static String getTimeFromTimestamp(long timestamp) {
         try {
@@ -73,7 +148,7 @@
             if (UserConfigManage.getInstance().getCurrentAppLanguage().equals(LocalManageUtil.en)) {
                 pattern = "dd-MM-yyyy HH:mm";
             }
-            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.ENGLISH);
+            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, getLocale());
             Date date = new Date(timestamp);
             return dateFormat.format(date);
         } catch (Exception e) {
@@ -81,6 +156,7 @@
         }
         return "";
     }
+
 
     /**
      * 鏃堕棿鎴宠浆鏃堕棿(鏍煎紡:yyyy-MM-dd HH:mm:ss)
@@ -113,14 +189,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 +216,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);
     }
@@ -167,7 +259,7 @@
      * @return Calendar瀵硅薄
      */
     public static Calendar stringToCalendar(String dateString, String dateFormat) {
-        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
         Calendar calendar = Calendar.getInstance();
         try {
             Date date = sdf.parse(dateString);
@@ -186,7 +278,7 @@
      * @return Calendar瀵硅薄
      */
     public static String calendarToString(Calendar calendar, String dateFormat) {
-        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
         return sdf.format(calendar.getTime());
     }
 
@@ -197,7 +289,7 @@
      * @return Calendar瀵硅薄
      */
     public static String dateToString(Date date, String dateFormat) {
-        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, Locale.ENGLISH);
+        SimpleDateFormat sdf = new SimpleDateFormat(dateFormat, getLocale());
         return sdf.format(date.getTime());
     }
 
@@ -210,7 +302,7 @@
      */
     public static long stringDateToTimestamp(String dateString, String dateFormat) {
         try {
-            SimpleDateFormat slf = new SimpleDateFormat(dateFormat, Locale.getDefault());
+            SimpleDateFormat slf = new SimpleDateFormat(dateFormat, getLocale());
             Date date = slf.parse(dateString);
             if (date == null) {
                 return 0;
@@ -221,4 +313,8 @@
         return 0;
     }
 
+    private static Locale getLocale() {
+        return Locale.ENGLISH;
+    }
+
 }

--
Gitblit v1.8.0