Frequency.Static constructor Null safety
static occureance frequency constructor
Implementation
Frequency.Static(
String pName, String pPeriod, List<String> pListOfTimesAtPeriod) {
this.name = pName;
this.isOnce = false;
this.isDynamic = false;
this.isText = false;
this.timesPerDay = 0;
this.timesPerWeek = 0;
this.timesPerMonth = 0;
this.timesPerYear = 0;
pPeriod == "Day" ? this.hoursAtDay = pListOfTimesAtPeriod : [];
pPeriod == "Week" ? this.daysAtWeek = pListOfTimesAtPeriod : [];
pPeriod == "Month" ? this.daysAtMonth = pListOfTimesAtPeriod : [];
pPeriod == "Year" ? this.daysAtYear = pListOfTimesAtPeriod : [];
if (pPeriod == "Day") {
//list of hours in pattern ["08:00:00","10:00:00",..]
DateTime nw = DateTime.now();
this.hoursAtDay!.sort((a, b) => DateTime(
nw.year,
nw.month,
nw.day,
int.parse(a.split(":")[0]),
int.parse(a.split(":")[1]),
int.parse(a.split(":")[2]))
.compareTo(DateTime(
nw.year,
nw.month,
nw.day,
int.parse(a.split(":")[0]),
int.parse(a.split(":")[1]),
int.parse(a.split(":")[2]))));
}
if (pPeriod == "Week") {
//list of weekdays ["Monday","Tuesday",..]
this
.daysAtWeek!
.sort((a, b) => weekDays.indexOf(a).compareTo(weekDays.indexOf(b)));
}
if (pPeriod == "Month") {
//list of month days by index [1,2,9]
this.daysAtMonth!.sort((a, b) => a.compareTo(b));
}
if (pPeriod == "Year") {
//list of time stamps across the year with datetime format as Y-m-d H:m:s Z 2022-02-22 09:00:00 +0400
this
.daysAtYear!
.sort((a, b) => DateTime.parse(a).compareTo(DateTime.parse(b)));
}
}