import pandas as pd
import numpy as np
from datetime import datetime

"""
Explanation: Date Arithmetic
documentation: http://pandas.pydata.org/pandas-docs/stable/timeseries.html#timeseries-offsets
| Type      |   | Description                                                       |
|-----------|---|-------------------------------------------------------------------|
| date      |   | Store calendar date (year, month, day) using a Gregorian Calendar |
| datetime  |   | Store both date and time                                          |
| timedelta |   | Difference between two datetime values                            |
common date arithmetic operations

calculate differences between date
generate sequences of dates and time spans
convert time series to a particular frequency

Date, time, functions
documentation: http://pandas.pydata.org/pandas-docs/stable/api.html#top-level-dealing-with-datetimelike
| to_datetime(args, kwargs)                      | Convert argument to datetime.                                               |   |
|---------------------------------------------------|-----------------------------------------------------------------------------|---|
| to_timedelta(args, **kwargs)                     | Convert argument to timedelta                                               |   |
| date_range([start, end, periods, freq, tz, ...])  | Return a fixed frequency datetime index, with day (calendar) as the default |   |
| bdate_range([start, end, periods, freq, tz, ...]) | Return a fixed frequency datetime index, with business day as the default   |   |
| period_range([start, end, periods, freq, name])   | Return a fixed frequency datetime index, with day (calendar) as the default |   |
| timedelta_range([start, end, periods, freq, ...]) | Return a fixed frequency timedelta index, with day as the default           |   |
| infer_freq(index[, warn])                         | Infer the most likely frequency given the input index.                      |   |
End of explanation
"""


now = datetime.now()
now

now.year, now.month, now.day

"""
Explanation: now()
End of explanation
"""


delta = now - datetime(2001, 1, 1)
delta

delta.days

"""
Explanation: delta
source: http://pandas.pydata.org/pandas-docs/stable/timedeltas.html
End of explanation
"""


pd.Timedelta('4 days 7 hours')

"""
Explanation: Parsing Timedelta
from string
End of explanation
"""


# note: these MUST be specified as keyword arguments
pd.Timedelta(days=1, seconds=1)

"""
Explanation: named keyword arguments
End of explanation
"""


pd.Timedelta(1, unit='d')

"""
Explanation: integers with a unit
End of explanation
"""


us_memorial_day = datetime(2016, 5, 30)
print(us_memorial_day)
us_labor_day = datetime(2016, 9, 5)
print(us_labor_day)
us_summer_time = us_labor_day - us_memorial_day
print(us_summer_time)
type(us_summer_time)

us_summer_time_range = pd.date_range(us_memorial_day, periods=us_summer_time.days, freq='D')

"""
Explanation: create a range of dates from Timedelta
End of explanation
"""


us_summer_time_time_series = pd.Series(np.random.randn(us_summer_time.days), index=us_summer_time_range)
us_summer_time_time_series.tail()

"""
Explanation: summer_time time series with random data
End of explanation
"""


