Daylight saving time (DST or summertime) is the arrangement by which clocks are advanced by one hour in spring and moved back in autumn to make the most of seasonal daylight
In the summer the sun rises so early that it is already light while most people are still sleeping. By shifting the clock, the sun seems to rise and to set later. This is why in the morning it is dark for longer, and in the evening it is light for longer. The period of daylight is thus more consistent with the period when most people are awake. The idea behind DST is that there could be cut back on (electric) lighting. However, the energy-saving effect of DST is controversial. Approximately 70 countries are currently changing the time on their clocks twice a year. In the European Union, the DST runs from the last Sunday in March until the last Sunday in October. The dates of the next few years the DST in the European Union begins and ends, are shown in the table below.
year | begin date | end date |
---|---|---|
2013 | 31 March | 27 October |
2014 | 30 March | 26 October |
2015 | 29 March | 25 October |
2016 | 27 March | 30 October |
2017 | 26 March | 29 October |
Write a function summertime to which a year must be passed as an argument. The function must return a date object (datetime module from the Python Standard Library), which represents the date on which the European Union enters the daylight saving time (last Sunday of March) in the specified year.
Write a function wintertime to which a year must be passed as an argument. The function must return a date object (datetime module from the Python Standard Library), which represents the date on which the European Union enters the standard time (last Sunday of October) in the specified year.
Write a function clock to which a string argument must be passed, which sets a date in the format day/month/year. The function must return a string that indicates whether the clock on the specified date is in summer time or winter time. The function must return a custom string on the dates on which will be switched between summer time and winter time. The possible definitions that the function must return can be found in the example below.
You can assume with every function that all years are between 1600 and 2400. In this task, it is important that you try to reuse code as much as possible and you should, where possible, thus avoid repeating a similar code.
For this assignment you have to use the data types date and timedelta, which are defined in the module datetime of the Python Standard Library1. The following interactive Pythonsession demonstrates all methods of the required data types:
>>> from datetime import date, timedelta
>>> today = date.today()
>>> today
datetime.date(2013, 6, 27)
>>> today.weekday()
3
>>> tomorrow = today + timedelta(1)
>>> tomorrow.weekday()
4
>>> tomorrow
datetime.date(2013, 6, 28)
>>> summertime(2013)
datetime.date(2013, 3, 31)
>>> summertime(2014)
datetime.date(2014, 3, 30)
>>> summertime(2015)
datetime.date(2015, 3, 29)
>>> wintertime(2013)
datetime.date(2013, 10, 27)
>>> wintertime(2014)
datetime.date(2014, 10, 26)
>>> wintertime(2015)
datetime.date(2015, 10, 25)
>>> clock('27/06/2013')
'summertime'
>>> clock('27/11/2013')
'wintertime'
>>> clock('31/03/2013')
'switch from wintertime to summertime'
>>> clock('27/10/2013')
'switch from summertime to wintertime'
“Don’t forget to put all your clocks forward tonight,” said Piglet.
“How much?” asked Pooh.
“About five inches, I think,” said Piglet, confidently.