In [13]:
import pandas

import datetime
import time

import mx.DateTime

import numpy as np

import pytz

import dateutil

In [14]:
# constructing

# time type
time.gmtime(0) # time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)
time.struct_time((2000,1,13,0,0,0,0,0,0))
time.strptime('2000-01-13', '%Y-%m-%d')

# Default type
datetime.datetime.fromtimestamp(0) # 1970-01-01
datetime.datetime.fromordinal(1) # 0001-01-01
datetime.datetime(2000,1,13)
datetime.datetime.strptime('2000-01-13', '%Y-%m-%d')

# egenix 
mx.DateTime.DateTimeFromTicks(0) # 1970-01-01
mx.DateTime.DateTimeFromAbsDays(0) # 0001-01-01
mx.DateTime.DateTimeFrom('2000-01-13')
mx.DateTime.DateTime(2000,1,13)

# numpy
np.datetime64(0,'s') # 1970-01-01 
np.datetime64('2000-01-13')


Out[14]:
numpy.datetime64('2000-01-13')

In [15]:
sys.getsizeof(time.strptime('2000-01-13', '%Y-%m-%d')) # 96
sys.getsizeof(datetime.datetime.strptime('2000-01-13', '%Y-%m-%d')) # 48
sys.getsizeof(mx.DateTime.DateTimeFrom('2000-01-13')) # 72
sys.getsizeof(np.datetime64('2000-01-13')) # 40


Out[15]:
32

In [16]:
# Difficult dates

# Year 0 does not exist:
# Year zero does not exist in the Anno Domini system usually used to number years in the Gregorian calendar
# and in its predecessor, the Julian calendar. In this system, the year 1 BC is followed by AD 1. However, 
# there is a year zero in astronomical year numbering (where it coincides with the Julian year 1 BC) and 
# in ISO 8601:2004 (where it coincides with the Gregorian year 1 BC) as well as in all Buddhist and Hindu 
# calendars.


# Since negative years and the year 0 don't fit well with the Gregorian or Julian calendars, the normal 
# ranges of dates start with year 1. The ISO C standard allows tm_year to assume values corresponding to 
# years before year 1, but the use of such years provided unspecified results.)

#time.strptime('0000-01-01', '%Y-%m-%d')
#datetime.datetime.strptime('0000-01-01', '%Y-%m-%d')
mx.DateTime.DateTimeFrom('0000-01-01')
#np.datetime64('0000-01-01')


Out[16]:
<mx.DateTime.DateTime object for '0000-01-01 00:00:00.00' at 3e9cc90>

In [17]:
time.struct_time((-1,1,1,0,0,0,0,0,0))
# datetime.datetime(-1,1,1) # nope
mx.DateTime.DateTime(-1,1,1)
# np.datetime64('-0001-01-01') # nope


Out[17]:
<mx.DateTime.DateTime object for '-0001-01-01 00:00:00.00' at 3e9ca50>

In [18]:
#time.strptime('20000-01-01', '%Y-%m-%d')
#datetime.datetime.strptime('20000-01-01', '%Y-%m-%d')
#mx.DateTime.DateTimeFrom('20000-01-01')
#np.datetime64('20000-01-01')

In [19]:
time.struct_time((20000,1,1,0,0,0,0,0,0))
# datetime.datetime(20000,1,1) # nope
mx.DateTime.DateTime(20000,1,1)
# np.array('200000-01-01', 'M8[D]') # nope


Out[19]:
<mx.DateTime.DateTime object for '20000-01-01 00:00:00.00' at 3e9cae0>

In [20]:
utc = pytz.timezone('UTC')
gmt = pytz.timezone('GMT')
ams = pytz.timezone('Europe/Amsterdam')

In [21]:
rows = []
for date, transinfo in zip(ams._utc_transition_times, ams._transition_info):
    dateutc = date.replace(tzinfo=utc)
    row = {'utc': dateutc,
           'ams': dateutc.astimezone(ams),
           'diff': dateutc.astimezone(ams).replace(tzinfo=utc) - dateutc,
           'name': transinfo[2]}
           
    rows.append(row)

In [22]:
df = pandas.DataFrame.from_records(rows)
df['diff_minutes'] = df['diff'].apply(lambda x:60.0*x/(3600.0*1.0e9))
df = df.ix[1:]

In [37]:
fig, ax = plt.subplots(figsize=(20,5))
ax.plot_date(matplotlib.dates.date2num(df['utc']), df['diff_minutes'], drawstyle='steps', linestyle='-', marker='', color='#009999', linewidth=3)
ax.set_xlim(matplotlib.dates.date2num(datetime.datetime(1900,1,1)), matplotlib.dates.date2num(datetime.datetime(2015,1,1)))
ax.set_xlabel('date')
ax.set_ylabel('minutes to UTC')
ax.set_title('Europe/Amsterdam')
arrowprops=dict(facecolor='black', shrink=0.1)

for name in set(df.name):
    row = df[df.name == name].irow(0)
    x = matplotlib.dates.date2num(row['ams'])
    y = row['diff_minutes']
    ax.annotate(name, xy=(x,y), xytext=(x+3000, y+10 if row['diff_minutes'] > 30 else y-10), arrowprops=arrowprops)