Fix: Passt an, dass bei monatlichen Transaktionen der Tag entsprechend hergenommen wird
This commit is contained in:
@@ -16,4 +16,32 @@ class DateUtils {
|
||||
final DateTime monthDate,
|
||||
final int monthsToAdd,
|
||||
) => DateTime(monthDate.year, monthDate.month + monthsToAdd);
|
||||
|
||||
/// Returns the number of days in a month, according to the proleptic
|
||||
/// Gregorian calendar.
|
||||
///
|
||||
/// This applies the leap year logic introduced by the Gregorian reforms of
|
||||
/// 1582. It will not give valid results for dates prior to that time.
|
||||
static int getDaysInMonth(final int year, final int month) {
|
||||
if (month == DateTime.february) {
|
||||
final bool isLeapYear =
|
||||
(year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0);
|
||||
return isLeapYear ? 29 : 28;
|
||||
}
|
||||
const List<int> daysInMonth = <int>[
|
||||
31,
|
||||
-1,
|
||||
31,
|
||||
30,
|
||||
31,
|
||||
30,
|
||||
31,
|
||||
31,
|
||||
30,
|
||||
31,
|
||||
30,
|
||||
31,
|
||||
];
|
||||
return daysInMonth[month - 1];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,15 +67,51 @@ class GenerateTransactionsTask extends Task {
|
||||
case TimeFrameEnum.weekly:
|
||||
newTransactionDate = lastTransactionDate.add(const Duration(days: 7));
|
||||
case TimeFrameEnum.monthly:
|
||||
newTransactionDate = DateUtils.addMonthsToMonthDate(
|
||||
final DateTime monthDate = DateUtils.addMonthsToMonthDate(
|
||||
lastTransactionDate,
|
||||
1,
|
||||
);
|
||||
|
||||
final int day =
|
||||
recurringTransaction.startDate!.day <
|
||||
DateUtils.getDaysInMonth(
|
||||
monthDate.year,
|
||||
monthDate.day,
|
||||
)
|
||||
? recurringTransaction.startDate!.day
|
||||
: DateUtils.getDaysInMonth(
|
||||
monthDate.year,
|
||||
monthDate.month,
|
||||
);
|
||||
|
||||
newTransactionDate = DateTime(
|
||||
monthDate.year,
|
||||
monthDate.month,
|
||||
day,
|
||||
);
|
||||
case TimeFrameEnum.yearly:
|
||||
newTransactionDate = DateUtils.addMonthsToMonthDate(
|
||||
final DateTime monthDate = DateUtils.addMonthsToMonthDate(
|
||||
lastTransactionDate,
|
||||
12,
|
||||
);
|
||||
|
||||
final int day =
|
||||
recurringTransaction.startDate!.day <
|
||||
DateUtils.getDaysInMonth(
|
||||
monthDate.year,
|
||||
monthDate.day,
|
||||
)
|
||||
? recurringTransaction.startDate!.day
|
||||
: DateUtils.getDaysInMonth(
|
||||
monthDate.year,
|
||||
monthDate.month,
|
||||
);
|
||||
|
||||
newTransactionDate = DateTime(
|
||||
monthDate.year,
|
||||
monthDate.month,
|
||||
day,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
newTransactionDate = recurringTransaction.startDate!;
|
||||
|
||||
Reference in New Issue
Block a user