|
@@ -1,9 +1,11 @@
|
|
package com.tencent.qcloud.tuikit.timcommon.util;
|
|
package com.tencent.qcloud.tuikit.timcommon.util;
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
+
|
|
import com.tencent.qcloud.tuicore.TUIConfig;
|
|
import com.tencent.qcloud.tuicore.TUIConfig;
|
|
import com.tencent.qcloud.tuicore.TUIThemeManager;
|
|
import com.tencent.qcloud.tuicore.TUIThemeManager;
|
|
import com.tencent.qcloud.tuikit.timcommon.R;
|
|
import com.tencent.qcloud.tuikit.timcommon.R;
|
|
|
|
+
|
|
import java.text.ParseException;
|
|
import java.text.ParseException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
@@ -40,35 +42,35 @@ public class DateTimeUtil {
|
|
locale = TUIThemeManager.getInstance().getLocale(context);
|
|
locale = TUIThemeManager.getInstance().getLocale(context);
|
|
}
|
|
}
|
|
String timeText;
|
|
String timeText;
|
|
- Calendar calendar = Calendar.getInstance();
|
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
- calendar = Calendar.getInstance();
|
|
|
|
- calendar.set(Calendar.DAY_OF_WEEK, 1);
|
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
- calendar = Calendar.getInstance();
|
|
|
|
- calendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
- calendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
- calendar.set(Calendar.MINUTE, 0);
|
|
|
|
- calendar.set(Calendar.SECOND, 0);
|
|
|
|
- calendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
- long yearStartTimeInMillis = calendar.getTimeInMillis();
|
|
|
|
- long dayStartTimeInMillis = calendar.getTimeInMillis();
|
|
|
|
- long weekStartTimeInMillis = calendar.getTimeInMillis();
|
|
|
|
|
|
+ Calendar dayStartCalendar = Calendar.getInstance();
|
|
|
|
+ dayStartCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
+ dayStartCalendar.set(Calendar.MINUTE, 0);
|
|
|
|
+ dayStartCalendar.set(Calendar.SECOND, 0);
|
|
|
|
+ dayStartCalendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
+ Calendar weekStartCalendar = Calendar.getInstance();
|
|
|
|
+ weekStartCalendar.set(Calendar.DAY_OF_WEEK, 1);
|
|
|
|
+ weekStartCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
+ weekStartCalendar.set(Calendar.MINUTE, 0);
|
|
|
|
+ weekStartCalendar.set(Calendar.SECOND, 0);
|
|
|
|
+ weekStartCalendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
+ Calendar yearStartCalendar = Calendar.getInstance();
|
|
|
|
+ yearStartCalendar.set(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
+ yearStartCalendar.set(Calendar.HOUR_OF_DAY, 0);
|
|
|
|
+ yearStartCalendar.set(Calendar.MINUTE, 0);
|
|
|
|
+ yearStartCalendar.set(Calendar.SECOND, 0);
|
|
|
|
+ yearStartCalendar.set(Calendar.MILLISECOND, 0);
|
|
|
|
+ long dayStartTimeInMillis = dayStartCalendar.getTimeInMillis();
|
|
|
|
+ long weekStartTimeInMillis = weekStartCalendar.getTimeInMillis();
|
|
|
|
+ long yearStartTimeInMillis = yearStartCalendar.getTimeInMillis();
|
|
long outTimeMillis = date.getTime();
|
|
long outTimeMillis = date.getTime();
|
|
if (outTimeMillis < yearStartTimeInMillis) {
|
|
if (outTimeMillis < yearStartTimeInMillis) {
|
|
- timeText = String.format(locale, "%tD", date);
|
|
|
|
|
|
+ timeText = String.format(Locale.US, "%tD", date);
|
|
} else if (outTimeMillis < weekStartTimeInMillis) {
|
|
} else if (outTimeMillis < weekStartTimeInMillis) {
|
|
- timeText = String.format(locale, "%1$tm/%1$td", date);
|
|
|
|
|
|
+ timeText = String.format(Locale.US, "%1$tm/%1$td", date);
|
|
} else if (outTimeMillis < dayStartTimeInMillis) {
|
|
} else if (outTimeMillis < dayStartTimeInMillis) {
|
|
timeText = String.format(locale, "%tA", date);
|
|
timeText = String.format(locale, "%tA", date);
|
|
} else {
|
|
} else {
|
|
- timeText = String.format(locale, "%tR", date);
|
|
|
|
|
|
+ timeText = String.format(Locale.US, "%tR", date);
|
|
}
|
|
}
|
|
return timeText;
|
|
return timeText;
|
|
}
|
|
}
|
|
@@ -82,14 +84,7 @@ public class DateTimeUtil {
|
|
if (date == null) {
|
|
if (date == null) {
|
|
return "";
|
|
return "";
|
|
}
|
|
}
|
|
- Context context = TUIConfig.getAppContext();
|
|
|
|
- Locale locale;
|
|
|
|
- if (context == null) {
|
|
|
|
- locale = Locale.getDefault();
|
|
|
|
- } else {
|
|
|
|
- locale = TUIThemeManager.getInstance().getLocale(context);
|
|
|
|
- }
|
|
|
|
- return String.format(locale, "%tR", date);
|
|
|
|
|
|
+ return String.format(Locale.US, "%tR", date);
|
|
}
|
|
}
|
|
|
|
|
|
public static String formatSeconds(long seconds) {
|
|
public static String formatSeconds(long seconds) {
|
|
@@ -136,7 +131,7 @@ public class DateTimeUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static long getStringToDate(String dateString, String pattern) {
|
|
public static long getStringToDate(String dateString, String pattern) {
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
|
|
|
|
|
|
+ SimpleDateFormat dateFormat = new SimpleDateFormat(pattern, Locale.US);
|
|
Date date = new Date();
|
|
Date date = new Date();
|
|
try {
|
|
try {
|
|
date = dateFormat.parse(dateString);
|
|
date = dateFormat.parse(dateString);
|
|
@@ -148,7 +143,7 @@ public class DateTimeUtil {
|
|
}
|
|
}
|
|
|
|
|
|
public static String getTimeStringFromDate(Date date, String pattern) {
|
|
public static String getTimeStringFromDate(Date date, String pattern) {
|
|
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
|
|
|
|
|
|
+ SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, Locale.US);
|
|
return simpleDateFormat.format(date);
|
|
return simpleDateFormat.format(date);
|
|
}
|
|
}
|
|
}
|
|
}
|