mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-11-27 21:34:54 +00:00
schedule for one gang and two gang and three gange
This commit is contained in:
@ -1,21 +1,69 @@
|
||||
class FunctionModel {
|
||||
final String code;
|
||||
final bool value;
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
FunctionModel({
|
||||
class ScheduleModel {
|
||||
String category;
|
||||
bool enable;
|
||||
ScheduleFunctionData function;
|
||||
String time;
|
||||
String scheduleId;
|
||||
String timezoneId;
|
||||
List<String> days;
|
||||
|
||||
ScheduleModel({
|
||||
required this.category,
|
||||
required this.enable,
|
||||
required this.function,
|
||||
required this.time,
|
||||
required this.scheduleId,
|
||||
required this.timezoneId,
|
||||
required this.days,
|
||||
});
|
||||
|
||||
// Factory method to create an instance from JSON
|
||||
factory ScheduleModel.fromJson(Map<String, dynamic> json) {
|
||||
return ScheduleModel(
|
||||
category: json['category'],
|
||||
enable: json['enable'],
|
||||
function: ScheduleFunctionData.fromJson(json['function']),
|
||||
time:getTimeIn12HourFormat( json['time']),
|
||||
scheduleId: json['scheduleId'],
|
||||
timezoneId: json['timezoneId'],
|
||||
days: List<String>.from(json['days']),
|
||||
);
|
||||
}
|
||||
|
||||
// Method to convert an instance into JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'category': category,
|
||||
'enable': enable,
|
||||
'function': function.toJson(),
|
||||
'time': time,
|
||||
'scheduleId': scheduleId,
|
||||
'timezoneId': timezoneId,
|
||||
'days': days,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduleFunctionData {
|
||||
String code;
|
||||
bool value;
|
||||
|
||||
ScheduleFunctionData({
|
||||
required this.code,
|
||||
required this.value,
|
||||
});
|
||||
|
||||
// Convert a JSON object to a FunctionModel instance
|
||||
factory FunctionModel.fromJson(Map<String, dynamic> json) {
|
||||
return FunctionModel(
|
||||
// Factory method to create an instance from JSON
|
||||
factory ScheduleFunctionData.fromJson(Map<String, dynamic> json) {
|
||||
return ScheduleFunctionData(
|
||||
code: json['code'],
|
||||
value: json['value'],
|
||||
);
|
||||
}
|
||||
|
||||
// Convert a FunctionModel instance to a JSON object
|
||||
// Method to convert an instance into JSON
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'code': code,
|
||||
@ -24,51 +72,12 @@ class FunctionModel {
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduleModel {
|
||||
final String id;
|
||||
final String category;
|
||||
final bool enable;
|
||||
final FunctionModel function;
|
||||
final String time;
|
||||
final String timerId;
|
||||
final String timezoneId;
|
||||
final List<String> days;
|
||||
String getTimeIn12HourFormat(time) {
|
||||
// Parse the time string (in HH:mm format)
|
||||
final DateFormat inputFormat = DateFormat("HH:mm");
|
||||
final DateFormat outputFormat = DateFormat("h:mm a"); // 12-hour format with AM/PM
|
||||
|
||||
ScheduleModel({
|
||||
required this.id,
|
||||
required this.category,
|
||||
required this.enable,
|
||||
required this.function,
|
||||
required this.time,
|
||||
required this.timerId,
|
||||
required this.timezoneId,
|
||||
required this.days,
|
||||
});
|
||||
|
||||
// Convert a JSON object to a Schedule instance
|
||||
factory ScheduleModel.fromJson(Map<String, dynamic> json) {
|
||||
return ScheduleModel(
|
||||
id: json['id'],
|
||||
category: json['category'],
|
||||
enable: json['enable'],
|
||||
function: FunctionModel.fromJson(json['function']),
|
||||
time: json['time'],
|
||||
timerId: json['timerId'],
|
||||
timezoneId: json['timezoneId'],
|
||||
days: List<String>.from(json['days']),
|
||||
);
|
||||
}
|
||||
|
||||
// Convert a Schedule instance to a JSON object
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'category': category,
|
||||
'enable': enable,
|
||||
'function': function.toJson(),
|
||||
'time': time,
|
||||
'timerId': timerId,
|
||||
'timezoneId': timezoneId,
|
||||
'days': days,
|
||||
};
|
||||
}
|
||||
}
|
||||
// Convert the time string
|
||||
DateTime parsedTime = inputFormat.parse(time);
|
||||
return outputFormat.format(parsedTime);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user