473,594 Members | 2,655 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Daylight saving time question

Hi,

is it possible to get the two annual daylight saving times
(day, month and time) from Python by giving location
in some country/location string ("Europe/Finland" for example).

I need to ask country in program and calculate daylight
saving times for the next few years onwards somehow like this:

for y in range(2007, 2017):
(m1,d1,t1,m2,d2 ,t2) = daylight_change _epochs("Finlan d")

-pekka-
Mar 20 '07 #1
2 1865
On Mar 20, 2:53 pm, Mr Pekka Niiranen <pekka.niira... @pp5.inet.fi>
wrote:
Hi,

is it possible to get the two annual daylight saving times
(day, month and time) from Python by giving location
in some country/location string ("Europe/Finland" for example).

I need to ask country in program and calculate daylight
saving times for the next few years onwards somehow like this:

for y in range(2007, 2017):
(m1,d1,t1,m2,d2 ,t2) = daylight_change _epochs("Finlan d")

-pekka-
I recommend you read this article about using the dateutil module:

http://labix.org/python-dateutil

I can't remember, but I think this one might have a slightly more
restrictive license than other modules. Be sure to check that as well.
The "tzoffset type" is probably what you need

Mike

Mar 20 '07 #2
On Mar 20, 12:53 pm, Mr Pekka Niiranen <pekka.niira... @pp5.inet.fi>
wrote:
Hi,

is it possible to get the two annual daylight saving times
(day, month and time) from Python by giving location
in some country/location string ("Europe/Finland" for example).

I need to ask country in program and calculate daylight
saving times for the next few years onwards somehow like this:

for y in range(2007, 2017):
(m1,d1,t1,m2,d2 ,t2) = daylight_change _epochs("Finlan d")

-pekka-


A generator defined via recursion:

import dateutil.rrule, dateutil.tz
import datetime

mytz = dateutil.tz.tzf ile("/usr/share/zoneinfo/Europe/Helsinki")

start = datetime.dateti me(2007,1,1,0,0 ,0,tzinfo=mytz)
end = datetime.dateti me(2017,1,1,0,0 ,0,tzinfo=mytz)

successively_fi ner = {
dateutil.rrule. WEEKLY: dateutil.rrule. DAILY,
dateutil.rrule. DAILY: dateutil.rrule. HOURLY,
dateutil.rrule. HOURLY: dateutil.rrule. MINUTELY,
dateutil.rrule. MINUTELY: dateutil.rrule. SECONDLY
}

# find week, then day, then hour, etc. that spans a change in DST

def sieve (start, end, freq):
dstflag = start.timetuple ()[-1]
iter = dateutil.rrule. rrule(freq,dtst art=start,until =end)
tprior = start
for t in iter:
if t.timetuple()[-1] != dstflag:
dstflag = t.timetuple()[-1]
if freq == dateutil.rrule. SECONDLY:
yield tprior, t
else:
yield sieve(tprior, t,
successively_fi ner[freq]).next()
tprior = t
raise StopIteration

for before, after in sieve(start, end, dateutil.rrule. WEEKLY):
print "%s =%s" % (
before.strftime ("%Y-%m-%d %H:%M:%S (%a) %Z"),
after.strftime( "%Y-%m-%d %H:%M:%S (%a) %Z"))
I get:

2007-03-25 02:59:59 (Sun) EET =2007-03-25 03:00:00 (Sun) EEST
2007-10-28 02:59:59 (Sun) EEST =2007-10-28 03:00:00 (Sun) EET
2008-03-30 02:59:59 (Sun) EET =2008-03-30 03:00:00 (Sun) EEST
2008-10-26 02:59:59 (Sun) EEST =2008-10-26 03:00:00 (Sun) EET
2009-03-29 02:59:59 (Sun) EET =2009-03-29 03:00:00 (Sun) EEST
2009-10-25 02:59:59 (Sun) EEST =2009-10-25 03:00:00 (Sun) EET
2010-03-28 02:59:59 (Sun) EET =2010-03-28 03:00:00 (Sun) EEST
2010-10-31 02:59:59 (Sun) EEST =2010-10-31 03:00:00 (Sun) EET
2011-03-27 02:59:59 (Sun) EET =2011-03-27 03:00:00 (Sun) EEST
2011-10-30 02:59:59 (Sun) EEST =2011-10-30 03:00:00 (Sun) EET
2012-03-25 02:59:59 (Sun) EET =2012-03-25 03:00:00 (Sun) EEST
2012-10-28 02:59:59 (Sun) EEST =2012-10-28 03:00:00 (Sun) EET
2013-03-31 02:59:59 (Sun) EET =2013-03-31 03:00:00 (Sun) EEST
2013-10-27 02:59:59 (Sun) EEST =2013-10-27 03:00:00 (Sun) EET
2014-03-30 02:59:59 (Sun) EET =2014-03-30 03:00:00 (Sun) EEST
2014-10-26 02:59:59 (Sun) EEST =2014-10-26 03:00:00 (Sun) EET
2015-03-29 02:59:59 (Sun) EET =2015-03-29 03:00:00 (Sun) EEST
2015-10-25 02:59:59 (Sun) EEST =2015-10-25 03:00:00 (Sun) EET
2016-03-27 02:59:59 (Sun) EET =2016-03-27 03:00:00 (Sun) EEST
2016-10-30 02:59:59 (Sun) EEST =2016-10-30 03:00:00 (Sun) EET

--
Hope this helps,
Steven

Mar 21 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
5522
by: Amitabh Deepak | last post by:
Is there any way to check whether daylight saving is enabled on a linux machine?
1
30136
by: Drew | last post by:
Is there a way to check if it is daylight savings or not via c#? I have heard you can use System.Globalization? Thanks - Drew
7
4074
by: Brett Edman | last post by:
I created a UTC clock using this: UTCTime = MyTime.ToUniversalTime() Now that we've turned the clocks ahead 1 hour for daylight savings time, the clock is reporting the wrong UTC time. It is reporting UTC + 1 hour. Is this a bug or is there a way I can querey for daylight time and make the adjustment in my application? Thanks.
1
3209
by: maflatoun | last post by:
Hi everyone, I have 3 different time zones that I'm working with. Basically converting from UTC to those 3 time zones. Eastern Daylight Time (GMT -04:00, New York) Central Daylight Time (GMT -05:00, Chicago) Pacific Daylight Time (GMT -07:00, San Francisco) Using C# I know how to detect if Daylight saving time is applied or not
27
6822
by: RobG | last post by:
I was investigating a function to determine whether daylight saving was being observed on a particular date (given the platform's regional settings) and came across a suggestion at merlyn.com to test the time zone offset on a variety of dates to see if it changes. Based on that, I developed the following checkDST() function which, as far as I can tell, should be sufficient. It checks either the date passed to it or the current date with...
0
7941
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8368
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8000
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6652
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5738
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5404
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3895
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2383
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1205
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.