Frontend first draft
This commit is contained in:
27
frontend/pshared/lib/models/settings/time_validity.dart
Normal file
27
frontend/pshared/lib/models/settings/time_validity.dart
Normal file
@@ -0,0 +1,27 @@
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'time_validity.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class TimeValidity {
|
||||
final DateTime? start;
|
||||
final DateTime? expiry;
|
||||
|
||||
const TimeValidity({this.start, this.expiry});
|
||||
|
||||
bool get isExpired => expiry?.isBefore(DateTime.now()) ?? false;
|
||||
bool get isNotStarted => start?.isAfter(DateTime.now()) ?? false;
|
||||
bool get isActive => (!isNotStarted) && (!isExpired);
|
||||
|
||||
TimeValidity copyWith({
|
||||
DateTime? Function()? start,
|
||||
DateTime? Function()? expiry,
|
||||
}) => TimeValidity(
|
||||
start: start == null ? this.start : start(),
|
||||
expiry: expiry == null ? this.expiry : expiry(),
|
||||
);
|
||||
|
||||
factory TimeValidity.fromJson(Map<String, dynamic> json) => _$TimeValidityFromJson(json);
|
||||
Map<String, dynamic> toJson() => _$TimeValidityToJson(this);
|
||||
}
|
||||
Reference in New Issue
Block a user