Skip to content

Commit

Permalink
Add DateDiagnosticsProperty
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Jan 24, 2023
1 parent b35b240 commit 469a0de
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/src/utils.dart
@@ -1,4 +1,5 @@
import 'package:dart_date/dart_date.dart' show Interval;
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart' hide Interval;

import 'week.dart';
Expand Down Expand Up @@ -162,6 +163,31 @@ extension DateTimeTimetable on DateTime {
}
}

class DateDiagnosticsProperty extends DiagnosticsProperty<DateTime> {
/// Create a diagnostics property for [Color].
///
/// The [showName], [style], and [level] arguments must not be null.
DateDiagnosticsProperty(
String super.name,
super.value, {
super.showName,
super.defaultValue,
super.style,
super.level,
}) : assert(value.isValidTimetableDate);

@override
String valueToString({TextTreeConfiguration? parentConfiguration}) {
final value = this.value;
if (value == null) return value.toString();

final year = value.year.toString().padLeft(4, '0');
final month = value.month.toString().padLeft(2, '0');
final day = value.day.toString().padLeft(2, '0');
return '$year-$month-$day';
}
}

extension InternalDateTimeTimetable on DateTime {
static DateTime create({
required int year,
Expand Down

0 comments on commit 469a0de

Please sign in to comment.