You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.3 KiB
Dart

class MonthStart {
final DateTime month; // YYYY-MM-01
final int startMinutes; // starthours (in Minuten)
final int startVacationUnits; // startvacation (z.B. Tage)
final int overtimeMinutes; // overtime (Minuten)
final int correctionMinutes; // correction (Minuten)
const MonthStart({
required this.month,
required this.startMinutes,
required this.startVacationUnits,
required this.overtimeMinutes,
required this.correctionMinutes,
});
/// Basis für kumulierte Differenz
int get carryBaseMinutes => startMinutes + overtimeMinutes + correctionMinutes;
static MonthStart fromJson(Map<String, dynamic> json) {
final bookings = (json['bookings'] as List?) ?? const [];
final row = bookings.isNotEmpty ? (bookings.first as Map<String, dynamic>) : const <String, dynamic>{};
final dateStr = (json['date'] as String?) ?? '1970-01-01';
final dt = DateTime.tryParse(dateStr) ?? DateTime(1970, 1, 1);
int _toInt(dynamic v) => v is num ? v.toInt() : int.tryParse('$v') ?? 0;
return MonthStart(
month: DateTime(dt.year, dt.month, 1),
startMinutes: _toInt(row['starthours']),
startVacationUnits: _toInt(row['startvacation']),
overtimeMinutes: _toInt(row['overtime']),
correctionMinutes: _toInt(row['correction']),
);
}
}