package main import ( "time" ) const dailySupplyCharge = 105.750 / 100 var ( solarFeedInTariff = fixedTariff(8.471 / 100) tariff93 = &onOffPeakTariff{ onPeak: 32.137 / 100, offPeak: 14.963 / 100, isPeak: (&weekdayHours{ zone: time.FixedZone("UTC+10", +10*60*60), on: [24]bool{ 7: true, 8: true, 9: true, 16: true, 17: true, 18: true, 19: true, 20: true, }, }).isPeak, } ) type tariff interface { pricePerKWh(time.Time) float64 } type fixedTariff float64 func (f fixedTariff) pricePerKWh(time.Time) float64 { return float64(f) } type onOffPeakTariff struct { onPeak, offPeak float64 isPeak func(time.Time) bool } func (o *onOffPeakTariff) pricePerKWh(t time.Time) float64 { if o.isPeak(t) { return o.onPeak } return o.offPeak } type weekdayHours struct { zone *time.Location on [24]bool } func (w *weekdayHours) isPeak(t time.Time) bool { t = t.In(w.zone) switch t.Weekday() { case time.Saturday, time.Sunday: return false default: return w.on[t.Hour()] } }