-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
71 lines (61 loc) · 1.94 KB
/
index.js
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { prices, tempzone } from './information.json'
/* month */
export const monthEntry = () => prices.month_entry
export const monthSundry = () => prices.month_sundry
export const monthSpecialTime = () => prices.month_special_time
export const monthCare = (age, day, time) =>
prices.month_init[age] +
prices.month_charge * day +
prices.month_charge * time
/* temp */
export const nappy = () => prices.nappy
export const milk = () => prices.milk
export const food = () => prices.food
export const tempAllday = age => prices.temp_allday[age]
export class TempCare {
constructor(from, to) {
this.morning = substractOrZero({
from: from,
to: toOrLimit(to, tempzone.day_start)
})
this.day = substractOrZero({
from: fromOrStart(from, tempzone.day_start),
to: toOrLimit(to, tempzone.evening_start)
})
this.evening = substractOrZero({
from: fromOrStart(from, tempzone.evening_start),
to: toOrLimit(to, tempzone.night_start)
})
this.night = substractOrZero({
from: fromOrStart(from, tempzone.night_start),
to: toOrLimit(to, tempzone.limit)
})
}
price(age) {
return (
prices.temp_morning * this.morning +
prices.temp_day[age] * this.day +
prices.temp_evening * this.evening +
prices.temp_night * this.night
)
}
priceByTime(age) {
return {
morning: prices.temp_morning * this.morning,
day: prices.temp_day[age] * this.day,
evening: prices.temp_evening * this.evening,
night: prices.temp_night * this.night
}
}
timeByTime() {
return {
morning: this.morning,
day: this.day,
evening: this.evening,
night: this.night
}
}
}
const substractOrZero = ({ from, to }) => (to - from > 0 ? to - from : 0)
const fromOrStart = (from, start) => (from > start ? from : start)
const toOrLimit = (to, limit) => (to < limit ? to : limit)