-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity_creator.dart
47 lines (42 loc) · 1.21 KB
/
entity_creator.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'package:open_work_flutter/data/models/calculation_type.dart';
import 'package:open_work_flutter/data/models/work_day.dart';
import 'package:open_work_flutter/data/models/work_month.dart';
import 'package:open_work_flutter/data/models/work_type.dart';
class EntityCreator {
static WorkType workType({
String? id,
required String name,
required CalculationType calculation,
required double price,
}) =>
WorkType(
name: name,
calculation: calculation,
price: price,
);
static WorkMonth workMonth({
String? id,
required int year,
required int month,
required List<WorkType> types,
}) {
return WorkMonth(
date: DateTime(year, month),
types: types,
days: emptyDays(year: year, month: month),
);
}
static List<WorkDay> emptyDays({required int year, required int month}) {
int days = dayCount(year: year, month: month);
return List.generate(
days,
growable: false,
(index) => WorkDay(
date: DateTime(year, month, index + 1),
works: List.empty(growable: true),
),
);
}
static int dayCount({required int year, required int month}) =>
DateTime(year, month + 1, 0).day;
}