| 729 | |
| 730 | |
| 731 | bool PriceService::timeIsInPeriod(tmElements_t tm, PriceConfig pc) { |
| 732 | uint8_t day = 0x01 << ((tm.Wday+5)%7); |
| 733 | uint32_t hrs = 0x01 << tm.Hour; |
| 734 | |
| 735 | if((pc.days & day) != day) return false; |
| 736 | if((pc.hours & hrs) != hrs) return false; |
| 737 | |
| 738 | tmElements_t tms; |
| 739 | tms.Year = tm.Year; |
| 740 | tms.Month = pc.start_month == 0 || pc.start_month > 12 ? 1 : pc.start_month; |
| 741 | tms.Day = pc.start_dayofmonth == 0 || pc.start_dayofmonth > 31 ? 1 : pc.start_dayofmonth; |
| 742 | tms.Hour = 0; |
| 743 | tms.Minute = 0; |
| 744 | tms.Second = 0; |
| 745 | |
| 746 | tmElements_t tme; |
| 747 | tme.Year = tm.Year; |
| 748 | tme.Month = pc.end_month == 0 || pc.end_month > 12 ? 12 : pc.end_month; |
| 749 | tme.Day = pc.end_dayofmonth == 0 || pc.end_dayofmonth > 31 ? 31 : pc.end_dayofmonth; |
| 750 | tme.Hour = 23; |
| 751 | tme.Minute = 59; |
| 752 | tme.Second = 59; |
| 753 | if(makeTime(tms) > makeTime(tme)) { |
| 754 | if(makeTime(tm) <= makeTime(tme)) { |
| 755 | tms.Year--; |
| 756 | } else { |
| 757 | tme.Year++; |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | return makeTime(tms) <= makeTime(tm) && makeTime(tme) >= makeTime(tm); |
| 762 | } |
| 763 | |
| 764 | uint8_t PriceService::getCurrentPricePointIndex() { |
| 765 | time_t ts = time(nullptr); |
nothing calls this directly
no outgoing calls
no test coverage detected