20
2
This is my first code golf so please let me know if it's too broad or if I'm missing any information for a good puzzle!
Challenge
In Ontario and possibly other areas of the world, electricity is billed using Time-Of-Use (TOU) pricing, which varies the cost per kilowatt-hour according to when you use power.
Given a date and time, I want to know whether I'm in an on-peak (red), mid-peak (yellow), or off-peak (green) time period.
Input
Assume that input is provided in an acceptable timezone-less ISO 8601 date-time format with the minimum precision of hours: YYYY-MM-DDThh[:mm[:ss]]
(the T is literal).
Examples
- 2014-09-01T14
- 2014-09-01T17:30
- 2014-09-01T17:30:02
Output
The output should be a string On
, Mid
, or Off
.
Rules
- Shortest code wins
- For the purposes of this challenge, ignore statutory holidays
- Assume the information found in this post. The actual rules of time-of-use pricing might change in the future by the Ontario Ministry of Energy.
Information
Summer weekdays (May 1st to October 31st)
- Off-peak: 19h00 - 07h00
- Mid-peak: 07h00 - 11h00 and 17h00 - 19h00
- On-peak: 11h00 - 17h00
Winter weekdays (November 1st to April 30th)
- Off-peak: 19h00 - 07h00
- Mid-peak: 11h00 - 17h00
- On-peak: 07h00 - 11h00 and 17h00 - 19h00
Weekends
- Off-peak: All day
Are you sure the winter weekdays don't have mid-peak / on-peak swapped? – John Dvorak – 2014-08-26T08:52:54.180
3@JanDvorak, in winter people use lights and heating in the morning and evening; in summer they use air-con at midday. – Peter Taylor – 2014-08-26T08:53:41.877
4
This is borderline-duplicate of http://codegolf.stackexchange.com/q/7008/194 (parse a datetime and do a simple calculation based on whether it's a working day or not). I think the season dependency is just different enough, but others may disagree.
– Peter Taylor – 2014-08-26T08:55:16.213@PeterTaylor the rules seem much simpler here than in the linked question. This doesn't have to handle leap years, for example. – John Dvorak – 2014-08-26T09:00:33.983
@JanDvorak you do need to consider leap years to correctly calculate the weekends in February and March. However it does seem simpler in its rules and output, and more rigid in its datetime format, so I don't think it's a duplicate. – Level River St – 2014-08-26T12:02:15.380
3Should the general date format be
YYYY-MM-DDThh[:mm[:ss]]
since seconds can only be applied if minutes are applied? – Cruncher – 2014-08-26T14:34:32.573Buy two of these, plug them in, program them, and then move the plug from one to the next twice a year. Problem solved: http://www.amazon.com/GE-Plug-In-Digital-Security-Feature/dp/B007BJUKVM unless you just want off-peak and don't care about mid peak. Then you only need one. If you don't care about weekends you can get a cheaper 24 hour timer.
– Adam Davis – 2014-08-26T18:45:41.443Semi-on topic: I'm happy BC is fighting against those smart meters ;) – Canadian Luke – 2014-08-27T16:18:06.093