Skip to content
Snippets Groups Projects
Commit 5b04c5b1 authored by poka's avatar poka
Browse files

refacto: getDateDelimiter() logic

parent 21a56bbc
Branches
Tags
No related merge requests found
Pipeline #19327 waiting for manual action
...@@ -254,58 +254,50 @@ Future<QueryResult> _execQuery( ...@@ -254,58 +254,50 @@ Future<QueryResult> _execQuery(
} }
Map computeHistoryView(repository, String address) { Map computeHistoryView(repository, String address) {
bool isTody = false;
bool isYesterday = false;
bool isThisWeek = false;
bool isMigrationTime = false;
bool isChangeOwnerkeyTime = false;
String? dateDelimiter;
DateTime now = DateTime.now();
final bool isUdUnit = configBox.get('isUdUnit') ?? false; final bool isUdUnit = configBox.get('isUdUnit') ?? false;
late double amount; late double amount;
late String finalAmount; late String finalAmount;
DateTime date = repository[0]; final DateTime date = repository[0];
String dateForm;
bool isDelimiter = true; final dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, {
1,
if ({4, 10, 11, 12}.contains(date.month)) { 2,
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}"; 7,
} else if ({1, 2, 7, 9}.contains(date.month)) { 9
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}"; }.contains(date.month) ? 4 : 3)}";
} else {
dateForm = "${date.day} ${monthsInYear[date.month]}"; DateTime normalizeDate(DateTime inputDate) {
return DateTime(inputDate.year, inputDate.month, inputDate.day);
} }
final transactionDate = DateTime(date.year, date.month, date.day); String getDateDelimiter() {
final todayDate = DateTime(now.year, now.month, now.day); DateTime now = DateTime.now();
final yesterdayDate = DateTime(now.year, now.month, now.day - 1); final transactionDate = normalizeDate(date.toLocal());
final todayDate = normalizeDate(now);
if (transactionDate == todayDate && !isTody) { final yesterdayDate = normalizeDate(now.subtract(const Duration(days: 1)));
dateDelimiter = "today".tr(); final isSameWeek = weekNumber(transactionDate) == weekNumber(now) &&
isTody = true; transactionDate.year == now.year;
} else if (transactionDate == yesterdayDate && !isYesterday) { final isTodayOrYesterday =
dateDelimiter = "yesterday".tr(); transactionDate == todayDate || transactionDate == yesterdayDate;
isYesterday = true;
} else if (weekNumber(date) == weekNumber(now) && if (transactionDate == todayDate) {
date.year == now.year && return "today".tr();
transactionDate != yesterdayDate && } else if (transactionDate == yesterdayDate) {
transactionDate != todayDate && return "yesterday".tr();
!isThisWeek) { } else if (isSameWeek && !isTodayOrYesterday) {
dateDelimiter = "thisWeek".tr(); return "thisWeek".tr();
isThisWeek = true; } else if (!isSameWeek && !isTodayOrYesterday) {
} else if (dateDelimiter != "${monthsInYear[date.month]} ${date.year}" && if (transactionDate.year == now.year) {
transactionDate != todayDate && return monthsInYear[transactionDate.month]!;
transactionDate != yesterdayDate &&
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
if (date.year == now.year) {
dateDelimiter = monthsInYear[date.month];
} else { } else {
dateDelimiter = "${monthsInYear[date.month]} ${date.year}"; return "${monthsInYear[transactionDate.month]} ${transactionDate.year}";
} }
} else { } else {
isDelimiter = false; return '';
} }
}
final dateDelimiter = getDateDelimiter();
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1; amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
...@@ -316,30 +308,20 @@ Map computeHistoryView(repository, String address) { ...@@ -316,30 +308,20 @@ Map computeHistoryView(repository, String address) {
finalAmount = '$amount $currencyName'; finalAmount = '$amount $currencyName';
} }
if (startBlockchainInitialized && date.compareTo(startBlockchainTime) < 0) { bool isMigrationTime =
isMigrationTime = true; startBlockchainInitialized && date.compareTo(startBlockchainTime) < 0;
} else {
isMigrationTime = false;
}
//TODO: Migration date and transaction migration doesn't match, add this event to v2s indexer. //TODO: Migration date and transaction migration doesn't match, add this event to v2s indexer.
// log.d('debug date transaction: $date'); // log.d('debug date transaction: $date');
// log.d('debug date identity migration: ${sub.oldOwnerKeys[address]?[1]}'); // log.d('debug date identity migration: ${sub.oldOwnerKeys[address]?[1]}');
// if (date.compareTo(sub.oldOwnerKeys[address]?[1] ?? DateTime(2000)) < 0) { // isChangeOwnerkeyTime = date.compareTo(sub.oldOwnerKeys[address]?[1] ?? DateTime(2000)) < 0;
// log.d('taaaaaaaaa: GOOOO');
// isChangeOwnerkeyTime = true;
// } else {
// isChangeOwnerkeyTime = false;
// }
return { return {
'finalAmount': finalAmount, 'finalAmount': finalAmount,
'isMigrationTime': isMigrationTime, 'isMigrationTime': isMigrationTime,
'dateDelimiter': dateDelimiter ?? '', 'dateDelimiter': dateDelimiter,
'isDelimiter': isDelimiter,
'dateForm': dateForm, 'dateForm': dateForm,
'isChangeOwnerkeyTime': isChangeOwnerkeyTime
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment