96 lines
3.2 KiB
Dart
96 lines
3.2 KiB
Dart
import '../model/api_response.dart';
|
||
import '../model/app_uri_status.dart';
|
||
|
||
class MyUtils {
|
||
static ApiResponse formatResponse(
|
||
ApiResponse res,
|
||
String successMsg,
|
||
String errorMsg,
|
||
) {
|
||
if (res.code == HttpStatusCodes.ok) {
|
||
// 成功但 msg 为空时填默认成功提示
|
||
if (res.msg == null || res.msg!.isEmpty) {
|
||
res.msg = successMsg;
|
||
}
|
||
} else {
|
||
// 失败且 msg 为空时填默认失败提示
|
||
if (res.msg == null || res.msg!.isEmpty) {
|
||
res.msg = errorMsg;
|
||
}
|
||
}
|
||
return res;
|
||
}
|
||
|
||
// 获取最近24小时的开始时间的毫秒数
|
||
static int getStartOfLast24HoursMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime startOfLast24Hours = now.subtract(Duration(hours: 24));
|
||
return startOfLast24Hours.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取当前时间的毫秒数作为最近24小时的结束时间
|
||
static int getEndOfLast24HoursMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
return now.millisecondsSinceEpoch;
|
||
}
|
||
|
||
static int getStartRangeFromNDaysAgoToNextDay(int n) {
|
||
DateTime now = DateTime.now();
|
||
DateTime start = DateTime(now.year, now.month, now.day - n - 1, 18, 0, 0);
|
||
DateTime end = start.add(Duration(hours: 24));
|
||
return start.millisecondsSinceEpoch;
|
||
}
|
||
|
||
static int getEndRangeFromNDaysAgoToNextDay(int n) {
|
||
DateTime now = DateTime.now();
|
||
DateTime start = DateTime(now.year, now.month, now.day - n - 1, 18, 0, 0);
|
||
DateTime end = start.add(Duration(hours: 24));
|
||
return end.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取当天前一天的下午18:00的时间戳
|
||
static int getYesterday18Milliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime yesterday18 = DateTime(now.year, now.month, now.day - 1, 18, 0, 0);
|
||
return yesterday18.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取当天17:00的时间戳
|
||
static int getToday17Milliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime today17 = DateTime(now.year, now.month, now.day, 17, 0, 0);
|
||
return today17.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取前一天的开始时间戳(前一天的00:00:00)
|
||
static int getStartOfYesterdayMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime startOfYesterday =
|
||
DateTime(now.year, now.month, now.day - 1, 0, 0, 0);
|
||
return startOfYesterday.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取前一天的结束时间戳(前一天的23:59:59)
|
||
static int getEndOfYesterdayMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime endOfYesterday =
|
||
DateTime(now.year, now.month, now.day - 1, 23, 59, 59);
|
||
return endOfYesterday.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取前一天的开始时间戳(前一天的00:00:00)
|
||
static int getStartOfCurrentMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime startOfYesterday = DateTime(now.year, now.month, now.day, 0, 0, 0);
|
||
return startOfYesterday.millisecondsSinceEpoch;
|
||
}
|
||
|
||
// 获取前一天的结束时间戳(前一天的23:59:59)
|
||
static int getEndOfCurrentMilliseconds() {
|
||
DateTime now = DateTime.now();
|
||
DateTime endOfYesterday =
|
||
DateTime(now.year, now.month, now.day, 23, 59, 59);
|
||
return endOfYesterday.millisecondsSinceEpoch;
|
||
}
|
||
}
|