Last active
September 29, 2016 07:24
-
-
Save benadaba/1de58607f10563d3466fd4f980291945 to your computer and use it in GitHub Desktop.
Financial Year Dates Incrementor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Created on Wed Sep 28 22:17:41 2016 | |
@author: adaba | |
""" | |
import datetime | |
from calendar import monthrange | |
from dateutil.parser import parse | |
import calendar | |
incrementList = [] | |
''' | |
@tyYR = this YEARS year | |
@tyMth = this YEAR's month | |
@tyDay = this YEAR's day | |
@lyYR = last YEARS year | |
@lyMth = last YEAR's month | |
@lyDay = last YEAR's day | |
@week = overall incrementing week | |
@weekty = yearly weeks from 1 to 52 | |
@numTimesToLoop = number of times to loop through the item. | |
''' | |
def dateincrement(tyYR, tyMth, tyDay, lyYR, lyMth, lyDay, week, weekty, numTimesToLoop): | |
date = datetime.datetime(tyYR,tyMth,tyDay) | |
dateLy= datetime.datetime(lyYR,lyMth,lyDay) | |
finYear = str(date.year) + ' - ' + str(date.year + 1) | |
for i in range(numTimesToLoop): | |
# print(i) | |
if(date.weekday()==0): | |
#start a new week and weekty | |
week = week + 1 | |
weekty = weekty + 1 | |
if(weekty == 53): | |
weekty = 1 | |
# date += datetime.timedelta(days=1) | |
# dateLy += datetime.timedelta(days=1) | |
if(date.month == 1): | |
finMonth = '10. January' | |
if(date.month == 2): | |
finMonth = '11. February' | |
if(date.month == 3): | |
finMonth = '12. March' | |
if(date.month == 4): | |
finMonth = '01. April' | |
#change change to new finacial year | |
finYear = str(date.year) + ' - ' + str(date.year + 1) | |
if(date.month == 5): | |
finMonth = '02. May' | |
if(date.month == 6): | |
finMonth = '03. June' | |
if(date.month == 7): | |
finMonth = '04. July' | |
if(date.month == 8): | |
finMonth = '05. August' | |
if(date.month == 9): | |
finMonth = '06. September' | |
if(date.month == 10): | |
finMonth = '07. October' | |
if(date.month == 11): | |
finMonth = '08. November' | |
if(date.month == 12): | |
finMonth = '09. December' | |
dateline = "('"+ date.strftime('%Y%m%d') +"' " +', ' + "'"+ dateLy.strftime('%Y%m%d')+"' " + \ | |
', ' +" '"+ calendar.day_name[date.weekday()] +"' "+ ', ' + " '"+ calendar.day_abbr[date.weekday()] + \ | |
"' " + ', ' +str(week) + ', ' + str(weekty) + ', ' +" '"+ finMonth + "' "+ ', ' +\ | |
" '"+ finYear + "') " | |
incrementList.append(dateline) | |
date += datetime.timedelta(days=1) | |
dateLy += datetime.timedelta(days=1) | |
# print(date,' ', dateLy, ' ', week, ' ', weekty, ' ', date.weekday() ) | |
''' | |
@tyYR = this YEARS year | |
@tyMth = this YEAR's month | |
@tyDay = this YEAR's day | |
@lyYR = last YEARS year | |
@lyMth = last YEAR's month | |
@lyDay = last YEAR's day | |
@week = overall incrementing week | |
@weekty = yearly weeks from 1 to 52 | |
@numTimesToLoop = number of times to loop through the item. | |
''' | |
#dateincrement(tyYR, tyMth, tyDay, lyYR, lyMth, lyDay, week, weekty, numTimesToLoop) | |
dateincrement(2013, 3, 31, 2012, 3, 26, 1, 0,1460) | |
import pandas as pd | |
from pandas import DataFrame | |
df = pd.DataFrame(incrementList) | |
df.to_csv('dates.csv', index=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment