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

zomertijd
Spring: shift to daylight saving time.
wintertijd
Autumn: shift to standard time.

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

Assignment

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.

Preparation

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)

Example

>>> 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'

Epilogue

“Don’t forget to put all your clocks forward tonight,” said Piglet.
“How much?” asked Pooh.
“About five inches, I think,” said Piglet, confidently.

Winnie-the-Pooh
Winnie-the-Pooh en Piglet.